1.1.1 • Published 2 years ago

xterm-readline v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Xterm.js Readline

node ci

This is an xterm-js addon that provides a readline like capability to xterm-js. It allows the creation of cli or repl like interfaces on top of xterm-js.

Large parts of this source are inspired / derived / ported from the MIT licensed rustyline project.

Features

  • Multi-line prompt and input
  • Extendable syntax highlighting
  • Unicode / multi column-width character support

Example

This is a multi-line example that treats any line ending with '&&' as a continuation.

import "xterm/css/xterm.css";
import { Terminal } from 'xterm';
import { Readline } from "xterm-readline";

const term = new Terminal({
  theme: {
        background: "#191A19",
        foreground: "#F5F2E7",
  },
  cursorBlink: true,
  cursorStyle: "block"
});

const rl = new Readline();

term.loadAddon(rl);
term.open(document.getElementById('terminal'));
term.focus();

rl.setCheckHandler((text) => {
  let trimmedText = text.trimEnd();
  if (trimmedText.endsWith("&&")) {
    return false;
  }
  return true;
});

function readLine() {
  rl.read(">")
    .then(processLine);
}

function processLine(text) {
  rl.println("you entered: " + text);
  setTimeout(readLine);
}

readLine();

Keyboard Shortcuts

KeyAction
HomeMove cursor to the beginning of line
EndMove cursor to end of line
LeftMove cursor one character left
RightMove cursor one character right
UpMove cursor up (multi-line edit)
DownMove cursor down (multi-line edit)
Ctrl-CCancel line in progress (additionally call ctrl-c callback if registered)
Ctrl-D, DelDelete the character under the cursor
EnterApply the line, or begin a new line in multiline mode
Alt/Shift EnterForce add \n to the input
Ctrl-UClear line
Ctrl-KDelete text from cursor to end of line

Real World Uses

License Agreement

If you contribute code to this project, you implicitly allow your code to be distributed under the MIT license.

1.1.1

2 years ago

1.1.0

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago