# prototty-terminal-js

> Harness for prototty wasm applications. Compatible with prototty 0.20

Latest version **0.9.0** (published 2019-01-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install prototty-terminal-js
pnpm add prototty-terminal-js
yarn add prototty-terminal-js
bun add prototty-terminal-js
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.9.0 |
| Published | 2019-01-03 |
| First published | 2017-12-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 14.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 83 |
| Author | Stephen Sherratt |
| Maintainers | stevebob |

## Links

- npm: https://www.npmjs.com/package/prototty-terminal-js
- Repository: https://github.com/stevebob/prototty
- Homepage: https://github.com/stevebob/prototty/tree/master/js-terminal
- Issues: https://github.com/stevebob/prototty/issues
- npm.io page: https://npm.io/package/prototty-terminal-js

## Dependencies (1)

- [localforage](https://npm.io/package/localforage.md) ^1.7.3

## Recent versions

- 0.9.0 (latest) — 2019-01-03
- 0.8.0 — 2018-04-03
- 0.7.2 — 2018-03-20
- 0.7.1 — 2018-01-31
- 0.7.0 — 2018-01-30
- 0.6.2 — 2018-01-28
- 0.6.1 — 2018-01-28
- 0.6.0 — 2018-01-28
- 0.5.2 — 2018-01-21
- 0.5.1 — 2018-01-20
- 0.5.0 — 2018-01-13
- 0.4.1 — 2018-01-11
- 0.4.0 — 2018-01-11
- 0.3.0 — 2018-01-10
- 0.2.0 — 2018-01-04
- … 2 more at https://npm.io/package/prototty-terminal-js/versions

## README

# Prototty JS App Harness

[![Download](https://img.shields.io/npm/v/prototty-terminal-js.svg)](https://www.npmjs.com/package/prototty-terminal-js)

[Prototty](https://github.com/stevebob/prototty/) is a rust library for
rendering to a terminal, designed specifically with game prototyping in mind.
It supports compiling to web assembly. This library
provides an application harness, that takes a compiled web assembly file, and
runs it, passing through keyboard input, and rendering the output to the screen.

## Example

This runs an app in a file called "wasm\_app.wasm", rendering the output into an
element called "protottyTerminal", using a grid of 30x20 cells.

```js
import prototty from 'prototty-terminal-js';

let node = document.getElementById("protottyTerminal");
prototty.loadProtottyApp("wasm_app.wasm", 30, 20, node).then(app => app.start());
```

## Big Example

https://github.com/stevebob/protrotty/examples/tetris

This is an implementation of tetris. There's a unix app that runs in an ansi terminal,
and a wasm app which runs in a browser using this library.

## Interface

The app harness expects the following functions to be exposed by the wasm blob:

```rust
#[no_mangle]
pub extern "C" fn alloc_app(rng_seed: usize, storage_buf: *const u8, storage_len: usize) -> *mut c_void {
    // Called once during initialisation.
    // `seed` is a random integer created using Math.random(), which can be used
    // as a seed for an rng.
    // `storage_buf` and `storage_len` is an address and size suitable for passing to
    // `prototty_wasm::WasmStorage::from_ptr`.
    // Allocate your application's state, and return a raw pointer to it.
}

#[no_mangle]
pub fn tick(app: *mut c_void,
            input_buffer: *const u8,
            num_inputs: usize,
            period_millis: f64) {

    // Called by the app harness once per frame.
    // `app` is a pointer to your application's state, returned by `alloc_app`.
    // `input_buffer` is a buffer containing encoded input values
    // `num_inputs` is the number of keycodes in `which_buffer` and `key_code_buffer`.
    // `period_millis` is the number of milliseconds that have passed since the last call to `tick`.
}
```

---
_Source: https://npm.io/package/prototty-terminal-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
