百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
N

node-ncurses

> 编程语言
开源

一个用于 Node.js 的 ncurses 绑定

388 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一个用于 Node.js 的 ncurses 绑定

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

  • node.js -- v0.8.0+

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:
javascript
      var nc = require('ncurses'),
          win = new nc.Window();
      win.hline(nc.cols, nc.ACS.DIAMOND);

Module Functions

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

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

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

  • setEscDelay(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(char, charCode, 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(clearOnRefresh) - Result - If redraw is true, the next call to refresh() will clear the screen completely and redraw the entire screen from scratch.

  • scrollok(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(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(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(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(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(enable) - Result - If enable is true, the standout Attribute is enabled. Otherwise, it is disabled.

  • syncok(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(row, 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([header[, footer]]) - (void) - Draws a frame around the window and calls label() with the optional arguments.

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

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

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

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

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

  • insdelln([nRows=1]) - Result - If nRows > 0, then nRows rows will be inserted above the current row. If nRows text[, 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 row, column, text[, 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(attrs) - Result - Switch on the specified window attributes.

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

  • attrset(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(nChars, attrs[, 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(row, column, nChars, attrs[, colorPair]) - Result - Same as the above, except the given row and column are used as the start position.

  • box([vertChar=0[, 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([leftChar=0[, rightChar=0[, topChar=0[, bottomChar=0[, topLeftChar=0[, topRightChar=0[, bottomLeftChar=0[, 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(length[, lineChar=0]) - Result - Draws a horizontal line on the current row with the given length. l

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C++

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言