Skip to content

Commit

Permalink
Complete documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
noelwelsh committed Jan 2, 2025
1 parent 4751e59 commit 8543ea8
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion docs/src/pages/js.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# Javascript Backend

The Javascript backend uses [xterm.js], which allows terminal applications to be embedded in website. It's what is used for all the examples in this documentation.
The Javascript backend uses [xterm.js], which allows terminal applications to be embedded in websites. It's what is used for all the examples in this documentation. Running in the web browser means there are some differences from standard terminal applications, but the majority of the Terminus interface stays the same.


## Running a Terminal

When running a `Terminal` you need to provide the ID of a DOM element where you want the terminal mounted. For example, if you have the following within a web page

```html
<div id="terminal"></div>
```

you would construct a `Terminal` with the following.

```scala
Terminal.run("id"){
// Terminal code here
}
```

There are optional arguments to specify the number of rows and columns the terminal occupies.

```scala
Terminal.run("id", rows = 24, cols = 80){
// Terminal code here
}
```


## User Input

User input is asynchronous in the web browser, so the normal @:api(terminus.Reader) interface doesn't work. Instead, Terminus provides a `readKey` method, which returns a `Future[String]`, where the `String` is the [key from a DOM `KeyboardEvent`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key).

[xterm.js]: https://xtermjs.org

0 comments on commit 8543ea8

Please sign in to comment.