Ncurses is a library that provides an API for advanced terminal-based, text interface designs.
Ncurses not only gives you additional options and controls not typically available in a console application, but also aims to be optimized around screen rendering time; something that can be quite slow when you render lots of small data chunks to the standard terminal.
This module provides bindings to various Ncurses functionality. See GNU.org's ncurses page for more details on what Ncurses provides.
- Global Variables
- ncurses.init()
- ncurses.cleanup()
- ncurses.print()
- ncurses.refresh()
- ncurses.scrollok()
- ncurses.clear()
- ncurses.move()
- ncurses.createWindow()
- ncurses.getWindowSize()
- ncurses.resizeWindow()
- ncurses.moveWindow()
- ncurses.getString()
- ncurses.getPair()
- ncurses.setPair()
- ncurses.attributeOn()
- ncurses.attributeOff()
- ncurses.setAttribute()
- ncurses.getAttribute()
- ncurses.setBackground()
- A working example
Colors
The following color constants are available for use the Ncurses windows through functions like ncurses.setPair(), ncurses.setBackground(), or ncurses.setAttribute().
In order to actually print colored text, you will need to first create a color pair, then use setAttribute() or setBackground() using the pair. Like this:
Style attributes
These constants may also be used in pairs, backgrounds, or attribute masks. Be warned, many of them do not work in a Windows console.
For an example of what each attribute looks like, refer to this image.
Default window
The default Ncurses window can be identified by
As you can probably imagine, this initializes the Ncurses module. By default, Ncurses is not enabled.
By calling this function, you will create the default Ncurses window (
When you are in Ncurses mode, calling this function will destroy the Ncurses environment and return you to standard output.
Prints data to an Ncurses window. The output begins at the virtual cursor's position
(use ncurses.move() to reposition the cursor) in the specified Ncurses window.
As with most Ncurses functions, you should pass
Take note that this function will not display the information immediately. The screen is only redrawn (and becomes visible) after you call ncurses.refresh().
Redraw the given window to commit any changes. Call this after a single call or batch of calls to any output function to update the screen.
Sets (or unsets) scrolling on the given window. By default, scrolling is disabled on Ncurses windows.
If you want text to scroll off the top as you continue to dump more text into it, set 'scrolling'
to
Erase the contents of window 'win'.
Moves the position of the virtual cursor to y,x in the given window. Notice that the orientation is Y (row) before X (column) and not the other way around. The virtual cursor position is where output will be placed in the given Ncurses window.
Should the position you request be unavailable (probably because it extends beyond the constraints of the window), this function will fail and do nothing.
Creates a new Ncurses window and returns it. 'sy' and 'sx' indicate the top-left corner of the window (in characters). 'width' and 'height' represent the window's width/height in characters.
If this function fails for any reason, it will return
Note that the position (sy,sx) is in Y,X order.
Returns the size of a window.
Note that this is in Y,X order.
Resize a Ncurses
Move a Ncurses
Note that the position is in Y,X order.
Prompt the user for some input on a Ncurses
Returns the attribute mask of a given color pair. You may call ncurses.setPair() on the pair to modify the value.
The 'pairIndex' must be in the range of 0 to 63; 0 is the default pair.
Modifies the color (foreground/background) pair at a given index.
The 'pairIndex' must be in the range of 1 to 63; 0 is reserved for the default pair.
Turns an attribute (identified by 'attrib') on for the given window.
Turns an attribute (identified by 'attrib') off for the given window.
Sets an attribute mask (identified by 'attrib') on the given window. The attribute mask can represent a handful of attributes at once. You should use Bitwise Operator OR (|) to combine them.
Returns the attribute mask and color pair for a Ncurses window. If this function fails, it will
return
Sets the background on the given window to the attribute mask.
Page last updated at 2024-04-20 14:58:15