Skip to content

Commit

Permalink
Updating README
Browse files Browse the repository at this point in the history
  • Loading branch information
wavesoft committed Sep 12, 2018
1 parent affed53 commit c02f809
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,43 @@
# term-echo
A local-echo utility for xterm.js

> A fully functional local echo controller for xterm.js
You will be surprised how difficult it is to implement a fully functional local-echo controller for [xterm.js](https://github.com/xtermjs/xterm.js) (or any other terminal emulator). This project takes this burden off your hands.

### Features

The local echo controller tries to replicate most of the bash-like user experience primitives, such as:

1. **Arrow Navigation** - Use `left` and `right` arrows to navigate in your input
2. **Word-Boundary Navigation** - Use `alt+left` and `alt+right` to jump between words
3. **Word-Boundary Deletion** - Use `alt+backspace` to delete a word
4. **Multi-Line Continuation** - Break command to multiple lines if they contain incomplete quotation marks, boolean operators (`&&` or `||`), pipe operator (`|`), or new-line escape sequence (`\`).
5. **Fully-Editable Multi-Line Continuation** - Navigate with your arrows and modify any line in your multi-line command.
5. **Local History** - Just like bash, access the commands you previously typed using the `up` and `down` arrows.
6. **Tab-Completion** - Provides callbacks where you can registry your custom tab-completion methods.

# Installation

```sh
npm install --save wavesoft/local-echo
```

# Usage

```js
import { Terminal } from 'xterm';
import LocalEchoController from 'local-echo';

// Start an xterm.js instance
const term = new Terminal();
term.open(document.getElementById('terminal'));

// Create a local echo controller
const localEcho = new LocalEchoController(term);

// Read a single line from the user
localEcho.read("~$ ")
.then(input => alert(`User entered: ${input}`))
.catch(error => alert(`Error reading: ${error}`));
```

6 changes: 1 addition & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ function countLines(input, maxCols) {
* - An input that ends with "\"
* - An input that has an incomplete boolean shell expression (&& and ||)
* - An incomplete pipe expression (|)
*
*/
function isIncompleteInput(input) {
// Empty input is not incomplete
Expand Down Expand Up @@ -169,9 +168,6 @@ class HistoryController {
* - Alt-backspace for word-boundary deletion
* - Multi-line input for incomplete commands
* - Auto-complete hooks
*
* Caveats / Known bugs:
* - Tab characters are replaced with 4 spaces
*/
class LocalEchoController {
constructor(term, historySize = 10) {
Expand Down Expand Up @@ -587,4 +583,4 @@ class LocalEchoController {
}
}

module.exports = LocalEchoController;
export default LocalEchoController;

0 comments on commit c02f809

Please sign in to comment.