• Stars
    star
    385
  • Rank 111,464 (Top 3 %)
  • Language
    C++
  • License
    MIT License
  • Created over 14 years ago
  • Updated about 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An ncurses binding for node.js

THIS MODULE IS NO LONGER BEING MAINTAINED. If you would like to become a maintainer, please submit an issue.

You may want to look at blessed as a better alternative to this module.

Description

node-ncurses is an ncurses binding for node.js.

Note: Mac OSX users may find themselves encountering bizarre output on their terminals in some situations. This is a known problem and basically requires more frequent Window.refresh()'ing to get everything to display properly.

Requirements

Terminology

Functions that accept window/screen coordinates use a "row, column" format.

Also, stdscr is the name of the first window that is created and fills the terminal/screen by default. It cannot be resized or moved, it is always the bottom-most window, and it is the window you get when you first create a new Window.

API Documentation

node-ncurses exposes only one class: Window.

Special data types

  • Result is simply an integer indicating success or failure of the function. 0 for success or -1 for error.

  • Attributes is an (unsigned) integer used as a bitmask for holding window attributes. All available attributes are stored in the 'attrs' property of the module.

  • ACS_Character is a special character used when dealing with line graphics. These are automatically determined at runtime by ncurses and thus cannot be defined as constants. Instead, they are accessible statically via the Window class after at least one window has been created (so that ncurses has initialized this special character set). See the Additional notes at the bottom for a list of the available characters.

    • An ACS_Character can currently be retrieved by using the 'ACS' property of the module. Example:
      var nc = require('ncurses'),
          win = new nc.Window();
      win.hline(nc.cols, nc.ACS.DIAMOND);

Module Functions

  • colorPair(< Integer >colorPair, < Integer >fgColor, < Integer >bgColor) - Integer - Sets the foreground and background colors for the given color pair number. The color pair number is always returned.

  • colorFg(< Integer >colorPair) - Integer - Returns the foreground color currently set for the given color pair number.

  • colorBg(< Integer >colorPair) - Integer - Returns the background color currently set for the given color pair number.

  • setEscDelay(< Integer >delay) - (void) - Sets the duration (in milliseconds) to wait after ESC is pressed.

  • cleanup() - (void) - Restores the terminal after using ncurses. This function is automatically called when the last window is closed and thus should never be used except when handling unexpected exceptions (i.e. in node.js's uncaughtException event) so that you can safely restore the terminal back to normal.

  • redraw() - (void) - Redraws all windows.

  • flash() - (void) - Flashes the screen.

  • bell() - (void) - Sounds the terminal bell.

  • leave() - (void) - Saves the current state of ncurses in memory and exits ncurses.

  • restore() - (void) - Restores the state saved by leave and updates the screen appropriately.

Module Properties

  • ACS - Object [Read-only] - Contains a map of all of the available ACS characters keyed by their character names

  • attrs - Object [Read-only] - Contains all of the available terminal attributes:

    • NORMAL - normal display
    • STANDOUT - "best" highlighting mode of the terminal
    • UNDERLINE - underlining
    • REVERSE - reverses the foreground and background colors
    • BLINK - blinking
    • DIM - half bright
    • BOLD - extra bright or bold
    • INVISIBLE - invisible or blank mode
    • PROTECT - protected mode (unsure of the real behavior for this one)
  • colors - Object [Read-only] - Contains a map of names to the basic 8 ANSI colors:

    • BLACK
    • RED
    • GREEN
    • YELLOW
    • BLUE
    • MAGENTA
    • CYAN
    • WHITE
    • Additional colors (if available) can be accessed by using their numerical value instead (the above list is 0 through 7 and 8 through 15 -- if available -- are generally the bright/bold versions of the above list)
  • keys - Object [Read-only] - Contains a map of keys on the keyboard (this is a long list -- see "Additional Notes" for all mapped keys)

  • numwins - Integer [Read-only] - Returns the number of currently open windows.

  • lines - Integer [Read-only] - The total number of rows of the terminal

  • cols - Integer [Read-only] - The total number of columns of the terminal

  • tabsize - Integer [Read-only] - The terminal's tab size

  • hasMouse - Boolean [Read-only] - Indicates whether the terminal supports mouse (clicks) functionality

  • hasColors - Boolean [Read-only] - Indicates whether the terminal supports colors

  • numColors - Integer [Read-only] - Indicates the (maximum) number of colors the terminal supports colors

  • maxColorPairs - Integer [Read-only] - The maximum number of foreground-background color pairs supported by the terminal

  • echo - Boolean [Read/Write] - Enable/disable local echoing of keyboard input

  • showCursor - Boolean [Read/Write] - Show/hide the cursor

  • raw - Boolean [Read/Write] - Enable/disable terminal's raw mode

Window Events

  • inputChar(< String >char, < Integer >charCode, < Boolean >isKey) - Emitted when a key has been pressed. isKey is true when a non-character key has been presssed (e.g. ESC, arrow key, Page Up, etc.).

Window Functions

  • clearok(< Boolean >clearOnRefresh) - Result - If redraw is true, the next call to refresh() will clear the screen completely and redraw the entire screen from scratch.

  • scrollok(< Boolean >scroll) - Result - Controls what happens when the cursor of a window is moved off the edge of the window or scrolling region, either as a result of a newline action on the bottom line, or typing the last character of the last row. If scroll is true, the window is scrolled up one line (Note: that in order to get the physical scrolling effect on the terminal, it is also necessary to call idlok()), otherwise the cursor is left at the bottom line.

  • idlok(< Boolean >useInsDelLine) - Result - If useInsDelTerm is true, ncurses considers using the hardware insert/delete line feature of the terminal (if available). Otherwise if useInsDelTerm is false, hardware line insertion and deletion is disabled. This option should be enabled only if the application needs insert/delete line, for example, for a screen editor. It is disabled by default because insert/delete line tends to be visually annoying when used in applications where it isn't really needed. If insert/delete line cannot be used, ncurses redraws the changed portions of all lines.

  • idcok(< Boolean >useInsDelChar) - Result - If useInsDelChar is true, ncurses considers using the hardware insert/delete character feature of the terminal (if available). Otherwise if useInsDelChar is false, ncurses no longer considers using the hardware insert/delete character feature of the terminal. Use of character insert/delete is enabled by default.

  • leaveok(< Boolean >moveCursor) - Result - Normally, the hardware cursor is left at the location of the window cursor being refreshed. If moveCursor is true, ncurses will allow the cursor to be left wherever an update happens to leave it. It is useful for applications where the cursor is not used, since it reduces the need for cursor motions. If possible, the cursor is made invisible when this function is called.

  • immedok(< Boolean >immedUpdate) - Result - If immedUpdate is true, any change in the virtual window, such as the ones caused by addch(), clrtobot(), scroll(), etc., automatically cause a call to refresh(). However, it may degrade performance considerably, due to repeated calls to refresh(). It is disabled by default.

  • standout(< Boolean >enable) - Result - If enable is true, the standout Attribute is enabled. Otherwise, it is disabled.

  • syncok(< Boolean >autoSyncUp) - Result - If autoSyncUp is true, syncup() is automatically called whenever there is a change in this window.

  • syncdown() - Result - Touches each location in the window that has been touched in any of its ancestor windows. This function is called by refresh(), so it should almost never be necessary to call it manually.

  • syncup() - Result - Touches all locations in ancestors of this window that are changed in this window.

  • cursyncup() - Result - Updates the current cursor position of all the ancestors of the window to reflect the current cursor position of the window.

  • hide() - (void) - Hides the window.

  • show() - (void) - Un-hides the window.

  • top() - (void) - Bring the window to the front.

  • bottom() - (void) - Send the window to the back (stdscr is always the bottom-most window, so this function will actually make the window the bottom-most window right above stdscr).

  • move(< Integer >row, < Integer >column) - (void) - Moves the window to the given row and column.

  • refresh() - Result - Update the physical screen to match that of the virtual screen.

  • frame([< String >header[, < String >footer]]) - (void) - Draws a frame around the window and calls label() with the optional arguments.

  • boldframe([< String >header[, < String >footer]]) - (void) - Same as frame(), except the frame is highlighted.

  • label([< String >header[, < String >footer]]) - (void) - Displays an optional centered header at the top and an optional centered footer at the bottom of the window.

  • centertext(< Integer >row, < String >text) - (void) - Display a centered string at the given row.

  • cursor(< Integer >row, < Integer >column) - Result - Moves the cursor to the given row and column.

  • insertln() - Result - Inserts an empty row above the current row.

  • insdelln([< Integer >nRows=1]) - Result - If nRows > 0, then nRows rows will be inserted above the current row. If nRows < 0, then nRows rows are deleted, beginning with the current row.

  • insstr(< String >text[, < Integer >charLimit=-1]) - Result - Insert the string into the window before the current cursor position. Insert stops at the end of the string or when charLimit has been reached. If charLimit < 0, it is ignored.

  • insstr(< Integer >row, < Integer >column, < String >text[, < Integer >charLimit=-1]) - Result - Moves the cursor to the given row and column, then calls the above version of insstr() with the rest of the arguments.

  • attron(< Attributes >attrs) - Result - Switch on the specified window attributes.

  • attroff(< Attributes >attrs) - Result - Switch off the specified window attributes.

  • attrset(< Attributes >attrs) - Result - Sets the window's attributes to be exactly that of the attributes specified.

  • attrget() - Attributes - Get the window's current set of attributes.

  • chgat(< Integer >nChars, < Attributes >attrs[, < Integer >colorPair]) - Result - Changes the attributes of the next nChars characters starting at the current cursor position to have the given attributes. colorPair specifies a color to use (defaults to the Window's current color pair).

  • chgat(< Integer >row, < Integer >column, < Integer >nChars, < Attributes >attrs[, < Integer >colorPair]) - Result - Same as the above, except the given row and column are used as the start position.

  • box([<ACS_Character>vertChar=0[, <ACS_Character>horizChar=0]]) - Result - Draws a box around the window using the optional vertical and horizontal characters. If a zero is given for any of the arguments, ncurses will use the POSIX default characters instead (See Additional notes).

  • border([<ACS_Character>leftChar=0[, <ACS_Character>rightChar=0[, <ACS_Character>topChar=0[, <ACS_Character>bottomChar=0[, <ACS_Character>topLeftChar=0[, <ACS_Character>topRightChar=0[, <ACS_Character>bottomLeftChar=0[, <ACS_Character>bottomRightChar=0]]]]]]]]) - Result - Draws a border around the window using the optionally specified left, right, top, bottom, top left, top right, bottom left, bottom right characters. If any of the characters are zero, ncurses will use the POSIX default characters instead (See Additional notes).

  • hline(< Integer >length[, <ACS_Character>lineChar=0]) - Result - Draws a horizontal line on the current row with the given length. lineChar specifies the character to be used when drawing the line. If lineChar is zero, ncurses will use the POSIX default characters instead (See Additional notes).

  • vline(< Integer >length[, <ACS_Character>lineChar=0]) - Result - Draws a vertical line on the current column with the given length. lineChar specifies the character to be used when drawing the line. If lineChar is zero, ncurses will use the POSIX default characters instead (See Additional notes).

  • erase() - Result - Copies blanks to every position in the window, clearing the screen.

  • clear() - Result - Similar to erase(), but it also calls clearok(true), so that the screen is cleared completely on the next call to refresh() for the window and is repainted from scratch.

  • clrtobot() - Result - Clears to the end of the window.

  • clrtoeol() - Result - Clears to the end of the current row.

  • delch() - Result - Deletes the character under the cursor.

  • delch(< Integer >row, < Integer >column) - Result - Moves the cursor to the given row and column and then deletes the character under the cursor.

  • deleteln() - Result - Deletes the current row.

  • scroll([< Integer >nLines=1]) - Result - Scrolls nLines lines. Positive values scroll up and negative values scroll down.

  • setscrreg(< Integer >startRow, < Integer >endRow) - Result - Sets the scrolling region of a window bounded by startRow and endRow (both inclusive).

  • touchlines(< Integer >startRow, < Integer >nRows[, < Boolean >markModified=true]) - Result - Marks nRows rows starting at startRow as having been modified if markModified is true or unmodified otherwise.

  • is_linetouched(< Integer >row) - Boolean - Indicates whether row has been marked as modified.

  • redrawln(< Integer >startRow, < Integer >nRows) - Result - Redraws nRows rows starting at startRow.

  • touch() - Result - Marks the entire window as having been modified.

  • untouch() - Result - Marks the entire window as having been unmodified.

  • resize(< Integer >rows, < Integer >columns) - Result - Resizes the window to have the given number of rows and columns.

  • print(< String >text) - Result - Writes text at the current cursor position.

  • print(< Integer >row, < Integer >column, < String >text) - Result - Moves the cursor to the given row and column and writes text.

  • addstr(< String >text[, < Integer >charLimit=-1]) - Result - Writes the specified string at the current cursor position. Writing stops at the end of the string or when charLimit has been reached. If charLimit < 0, it is ignored.

  • addstr(< Integer >row, < Integer >column, < String >text[, < Integer >charLimit=-1]) - Result - Moves the cursor to the given row and column and calls the version of addstr() above with the rest of the arguments.

  • close() - Result - Destroys the window and any of its children. Only call this once and when you are completely finished with the window.

Window Properties

  • hidden - Boolean [Read-only] - Is this window hidden?

  • height - Integer [Read-only] - Current window height

  • width - Integer [Read-only] - Current window width

  • begx - Integer [Read-only] - Column of the top-left corner of the window, relative to stdscr

  • begy - Integer [Read-only] - Row of the top-left corner of the window, relative to stdscr

  • curx - Integer [Read-only] - Column of the current cursor position

  • cury - Integer [Read-only] - Row of the current cursor position

  • maxx - Integer [Read-only] - Largest column number for this window

  • maxy - Integer [Read-only] - Largest row number for this window

  • touched - Integer [Read-only] - Indicates whether the window has been marked as modified

  • bkgd - Attributes [Read/Write] - Get/set the window's background attributes

Additional notes

Using ncurses with X

A resize operation in X sends SIGWINCH to the running application. The ncurses library does not catch this signal, because it cannot in general know how you want the screen re-painted. You will have to write the SIGWINCH handler yourself.

At minimum, your SIGWINCH handler should do a clearok(), followed by a refresh() on each of your windows.

ACS_Character descriptions

Character Name   POSIX Default  Description
--------------   -------------  -----------
ULCORNER              +         upper left-hand corner
LLCORNER              +         lower left-hand corner
URCORNER              +         upper right-hand corner
LRCORNER              +         lower right-hand corner
RTEE                  +         right tee
LTEE                  +         left tee
BTEE                  +         bottom tee
TTEE                  +         top tee
HLINE                 -         horizontal line
VLINE                 |         vertical line
PLUS                  +         plus
S1                    -         scan line 1
S9                    _         scan line 9
DIAMOND               +         diamond
CKBOARD               :         checker board (stipple)
DEGREE                '         degree symbol
PLMINUS               #         plus/minus
BULLET                o         bullet
LARROW                <         arrow pointing left
RARROW                >         arrow pointing right
DARROW                v         arrow pointing down
UARROW                ^         arrow pointing up
BOARD                 #         board of squares
LANTERN               #         lantern symbol
BLOCK                 #         solid square block

Keyboard key names

Keys prefixed with 'S_' denote SHIFT + the key.

  • SPACE
  • NEWLINE (the real Enter key)
  • ESC
  • UP
  • DOWN
  • LEFT
  • RIGHT
  • HOME
  • BACKSPACE
  • BREAK
  • F0
  • F1
  • F2
  • F3
  • F4
  • F5
  • F6
  • F7
  • F8
  • F9
  • F10
  • F11
  • F12
  • DEL
  • INS
  • EIC
  • CLEAR
  • EOS
  • EOL
  • SF
  • SR
  • NPAGE (page down)
  • PPAGE (page up)
  • STAB
  • CTAB
  • CATAB
  • ENTER
  • SRESET
  • RESET
  • PRINT
  • LL
  • UPLEFT
  • UPRIGHT
  • CENTER
  • DOWNLEFT
  • DOWNRIGHT
  • BTAB
  • BEG
  • CANCEL
  • CLOSE
  • COMMAND
  • COPY
  • CREATE
  • END
  • EXIT
  • FIND
  • FIND
  • MARK
  • MESSAGE
  • MOVE
  • NEXT
  • OPEN
  • OPTIONS
  • PREVIOUS
  • REDO
  • REFERENCE
  • REFRESH
  • REPLACE
  • RESTART
  • RESUME
  • SAVE
  • SELECT
  • SEND
  • SUSPEND
  • S_BEG
  • S_CANCEL
  • S_COMMAND
  • S_COPY
  • S_CREATE
  • S_DC
  • S_DL
  • S_EOL
  • S_EXIT
  • S_FIND
  • S_HELP
  • S_HOME
  • S_IC
  • S_LEFT
  • S_MESSAGE
  • S_MOVE
  • S_NEXT
  • S_OPTIONS
  • S_PREVIOUS
  • S_PRINT
  • S_REDO
  • S_REPLACE
  • S_RIGHT
  • S_RESUME
  • S_SAVE
  • S_SUSPEND
  • S_UNDO
  • UNDO

More Repositories

1

ssh2

SSH2 client and server modules written in pure JavaScript for node.js
JavaScript
5,493
star
2

busboy

A streaming parser for HTML form data for node.js
JavaScript
2,825
star
3

node-imap

An IMAP client module for node.js.
JavaScript
2,149
star
4

node-ftp

An FTP client module for node.js
JavaScript
1,128
star
5

mmmagic

An async libmagic binding for node.js for detecting content types by data inspection
C++
617
star
6

node-mariasql

A node.js binding to MariaDB's non-blocking (MySQL-compatible) client library
C++
485
star
7

socksv5

SOCKS protocol version 5 server and client implementations for node.js
JavaScript
400
star
8

cap

A cross-platform binding for performing packet capturing with node.js
JavaScript
360
star
9

ssh2-streams

SSH2 and SFTP client/server protocol streams for node.js
JavaScript
204
star
10

node-xxhash

An xxhash binding for node.js
C++
193
star
11

sipster

A pjsip/pjsua2 binding for node.js
C++
190
star
12

dicer

A very fast streaming multipart parser for node.js
JavaScript
186
star
13

httpolyglot

Serve http and https connections over the same port with node.js
JavaScript
181
star
14

connect-busboy

Connect middleware for busboy
JavaScript
155
star
15

node-asterisk

An Asterisk module for node.js
JavaScript
96
star
16

spellcheck

An async hunspell binding for node.js
C++
82
star
17

node-nntp

An NNTP client module for node.js
JavaScript
74
star
18

streamsearch

Streaming Boyer-Moore-Horspool searching for node.js
JavaScript
69
star
19

node-rtp

An RTP module in pure JavaScript for node.js
JavaScript
59
star
20

node-oscar

An OSCAR protocol client module for node.js
JavaScript
54
star
21

cpu-features

A simple node.js binding to Google's cpu_features library for obtaining information about installed CPU(s)
C++
40
star
22

node-pcre

A pcre binding for node.js
C++
39
star
23

esqlite

An SQLite binding for node.js with built-in encryption, focused on simplicity and (async) performance
C++
36
star
24

base91.js

basE91 encoding/decoding for node.js and browsers
JavaScript
31
star
25

bellhop

A node.js module that exposes streams for doing Pubsub and RPC.
JavaScript
28
star
26

ssh-repl

SSH into your node.js process and access a REPL
JavaScript
26
star
27

groan

A PHP session file parser written in JavaScript
JavaScript
24
star
28

paclient

PulseAudio client written in pure JavaScript for node.js
JavaScript
23
star
29

pg2

A PostgreSQL driver for node.js that focuses on performance
JavaScript
21
star
30

pmq

A node.js addon for using POSIX message queues
C++
19
star
31

grappler

A minimalistic server for "comet" connections in Node.js.
JavaScript
19
star
32

reformed

A high-level form field handling and validation module for busboy
JavaScript
18
star
33

zup

A simple, fast template engine for node.js
JavaScript
15
star
34

express-optimized

A minimal, optimized version of Express
JavaScript
13
star
35

xfer

Simple binary TLV reader/writer for node.js
JavaScript
12
star
36

youknow

A realtime, multiplayer card game for node.js that supports multiple frontends
JavaScript
11
star
37

odroid-c2-minimal-debian-ubuntu

Fork of various scripts to setup a minimal debian/ubuntu installation for the odroid c2
Shell
8
star
38

print

A node.js module for communicating with printers
JavaScript
7
star
39

filebounce

A server for bouncing files from point A to point B
JavaScript
7
star
40

node-poormansmysql

MySQL driver module for node.js that executes queries using the mysql command-line client.
JavaScript
7
star
41

buffy

Access and manipulate multiple node.js Buffers as if they were one continuous Buffer
JavaScript
6
star
42

nodebench

Node.js Benchmark Results
HTML
6
star
43

xsys

A node.js binding to useful system-level functions
C++
5
star
44

speaky

A binding to the SVOX Pico engine (libttspico) for performing text-to-speech
C++
4
star
45

lrused

An LRU cache for node.js
JavaScript
4
star
46

conveyor

Feed multiple node.js streams sequentially into one stream
JavaScript
3
star
47

benchd

Benchmark JavaScript code across different node.js/io.js versions from the browser
JavaScript
3
star
48

beepjs

A BEEP protocol implementation for node.js
JavaScript
3
star
49

vermal

A VRML 1.0 push parser for node.js
JavaScript
2
star
50

datatables.sortpriorities

Display column sort orders in your Datatables table headers
JavaScript
1
star
51

build-addons

Build node.js addon binaries for releases using Github Actions
JavaScript
1
star
52

buildcheck

Build environment checking (a la autoconf) for node.js
JavaScript
1
star