UI Toolkit for node.js console apps
TermUI is a library for Node.js that makes it easier to create rich console interfaces.
out(text)- prints text to the screen from the current cursor position
clear()- clears the screen
pos(x,y)- positions the cursor
home()- sends the cursor to the top left corner
end()- sends the cursor to the bottom right corner
fg(color)- sets the foreground color
bg(color)- sets the background color
hifg(color)- sets the foreground color for 256 color terminals
hibg(color)- sets the background color for 256 color terminals
enableMouse()- enables mouse event handling
disableMouse()- disables mouse event handling
eraseLine()- erases the entire line that the cursor is on
hideCursor()- hides the cursor
showCursor()- shows the cursor
The following will print "Hello, world!" at 10, 20 in the terminal in white text on a red background:
As you can see, pretty much everything is chainable.
C object contains definitions for common colors so that you don't have
to remember the numeric values.
- k: black
- r: red
- g: green
- y: yellow
- b: blue
- m: magenta
- c: cyan
- w: white
- x: the terminal's default color
S object is similar: it contains the text style definitions -- normal,
bold, underline, blink, and inverse.
SYM object contains shortcuts for some handy UTF8 characters: star, check
x, triUp, triDown, triLeft, triRight, fn, arrowUp, arrowDown, arrowLeft, and
resize is fired when the user resizes their terminal. The listener receives
an object with 'w' and 'h' properties set to the new width and height of the
keypress is fired when a key is pressed. This works just like the
mousedown, mouseup, drag, wheel are all the mouse events that are fired. The
receiver is sent an object that contains which button was pressed, which direction
the wheel scrolled, the x/y location, and whether or not shift was pressed.
Buttons are simply clickable rectangular areas that can have a label on them. Here's how to use one...
TermUI = require 'TermUI'TermUIenableMousebutton =bounds:x: 0y: 0w: 30h: 3label: 'I am a banana!'labelAnchor: 5buttonon 'mousedown'->button.bg = TermUICybuttondrawbuttonon 'mouseup'->button.bg = TermUICbbuttondrawbuttondraw