Giter Club home page Giter Club logo

terminal.js's Introduction

terminal.js

Javascript handling for terminal io. Presently implements the DEC/ANSI terminal statemachine described here You'll need to understand the statemachine described there to use this code. As most of this terminal stuff is not exactly mainstream knowledge, you'll probably also want to read the VT100 Userguide available here

Caveat: statemachine works fine, infrastructure is very very dirty and I'm only publishing it here for backup and in case someone is really looking for it and willing to clenan it up for me :)

Using

// provide a callback that handles the SM's actions,
// see below for details.
var callback = {...}

// create a Statemachine
var term_sm = new Statemachine(callback)

// get data from somewhere
while (var bla = readTerminalData()) {
  // call execute
  term_sm.execute(bla)
}

Callback / Actions

The statemachine is provided a callback by the user. This callback gets executed whenever an action occurs within the statemachine. Each call passes in an object:

{ 
  "what"       : // the action, see below,
  which        : // the current character,
  intermediate : // collected intermediate chars,
  params       : // the collected params
}

Actions

The "what" field of the object passed to the callback describes what action is currently being executed. Available actions are:

|print | |
|execute | | 
|esc | | 
|csi | |
|dcs_hook| |
|dcs_put| |
|dcs_unhook| |
|ocs_start||
|ocs_put| | 
|ocs_end| |

These are still fairly lowlevel and require an in depth understanding of temrinal arcana. A.k.a. this is most likely not what you'll want to implement.

vtcallback.js provides a default callback that interprets the esc, csi, etc. actions to some degree and forwards them to a terminal implementation, described below.

Have a look at test.js to get an idea of how to set things up.

Terminal Interface

A terminal will be connected to the the callbacks an supported the following interface:

| print          | print a character to the current current cursor position |
| newline        | newline                                                  |
| carriagereturn | carriagereturn                                           |
| cursorMode     | cursorMode,  "Application" or "Cursor"                   |
| vt52           | vt52                                                     |
| setColumns     | setColumns,  132 or 80                                   |
| setScrolling   | setScrolling, "Smooth" or "Jump"                         |
| setScreenMode  | setScreenMode, "Reverse" or "Normal"                     |
| setOriginMode  | setOriginMode,  "Relative" or "Absolute"                 |
| wraparound     | wraparound                                               |
| autorepeat     | autorepeat, bool                                         |
| setLFMode      | setLFMode, "NL" or "LF"                                  |
| keypadMode     | keypadMode, "Application" or "Numeric"                   |
| setTopAndBottomMargin | This sequence sets the top and bottom margins to define the scrolling region. s. DECSTBM |
| setSGR         |setSGR, Select Graphic Rendition, see SGR for params      |
| setCursor      |setCursor                                                 |
| erase          |clear screen, see ED for params                           |
| eraseLine      |eraseLine, clear line, see EL for params                  |
| cursorForward  |move cursor forward                                       |
| cursorBack     |move cursor backward                                      |
| cursorDown     |move cursor down                                          |
| cursorUp       |move cursor up                                            |
| clearTab       |clear tab, see TABC for params                            |
| setLED         |set LEDs, see LEDS for params                             |

vtcallbacks.js provides a default terminal implementation that does nothing but print everything provided to print to stdout and renders control codes.

TODO

more or less everything. Please be aware that this code is very likely to change or possibly be abandoned :)

Any help would be greatly appreciated.

The module infrastructure is more or less node-centric (ok, common.js) at this point, though no node.js Buffers are used, so it should be useable in a browser with minimal effort.

Concerning the statemachine itself, the implementation is quite complete. Most likely, some work will need to go into multibyte characters as the sm doesn't really take utf8 into account.

LICENSE

MIT License (c) Tim Becker 2011

vim: set tw=72:

terminal.js's People

Contributors

a2800276 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.