blingful character graphics/TUI library. definitely not curses.
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Go to file
nick black 826ddbc7c7
hrmm
5 years ago
debian dep on ncurses for tinfo 5 years ago
include notcurses_version: add to README 5 years ago
src ncurses_render: don't resend unchanged colors 5 years ago
tests don't try to destroy nullptr ncplane in tests 5 years ago
tools version string, notcurses_version() 5 years ago
.drone.yml sign that fucker 5 years ago
CMakeLists.txt cmake: turn on -Wshadow 5 years ago
LICENSE Initial commit 5 years ago
README.md hrmm 5 years ago

README.md

notcurses

cleanroom TUI library for modern terminal emulators. definitely not curses.

Build Status

  • What it is: a library facilitating complex TUIs on modern terminal emulators, supporting vivid colors and wide characters to the maximum degree possible. Many tasks delegated to Curses can be achieved using notcurses (and vice versa).

  • What it is not: a source-compatible X/Open Curses implementation, nor a replacement for NCURSES on existing systems, nor a widely-ported and -tested bedrock of Open Source, nor a battle-proven, veteran library.

notcurses abandons the X/Open Curses API bundled as part of the Single UNIX Specification. The latter shows its age, and seems not capable of making use of terminal functionality such as unindexed 24-bit color ("DirectColor", not to be confused with 8-bit indexed 24-bit color, aka "TrueColor"). For some necessary background, consult Thomas E. Dickey's superb and authoritative NCURSES FAQ. As such, it is not a drop-in Curses replacement. It is almost certainly less portable, and definitely tested on less hardware. Sorry about that. Ultimately, I hope to properly support all terminals supporting the features necessary for complex TUIs. I would argue that teletypes etc. are fundamentally unsuitable. Most operating systems seem reasonable targets, but I only have Linux and FreeBSD available for testing.

notcurses makes use of the Terminfo library shipped with NCURSES.

notcurses opens up advanced functionality for the interactive user on workstations, phones, laptops, and tablets, at the expense of e.g. industrial and retail terminals (or even the Linux virtual console, which offers only eight colors and limited glyphs).

Why use this non-standard library?

  • A svelter design than that codified in X/Open. All exported identifiers are prefixed with notcurses_ to avoid namespace pollution. Fewer identifiers overall. All APIs natively suport wide characters and 24-bit RGB color.

  • Visual features not directly available via NCURSES, including images, fonts, and video.

  • Thread safety, and use in parallel programs, has been a design consideration from the beginning.

On the other hand, if you're targeting industrial or critical applications, or wish to benefit from the time-tested reliability and portability of Curses, you should by all means use that fine library.

Basic use

A program wishing to use notcurses will need to link it, ideally using the output of pkg-config --libs notcurses. It is advised to compile with the output of pkg-config --cflags notcurses. If using CMake, a support file is provided, and can be accessed as notcurses.

Before calling into notcurses—and usually as one of the first calls of the program—be sure to call setlocale(3) with an appropriate UTF-8 LC_ALL locale. It is usually appropriate to pass NULL to setlocale(), relying on the user to properly set the LANG environment variable.

notcurses requires an available terminfo(5) definition appropriate for the terminal. It is usually appropriate to pass NULL in the termtype field of a notcurses_options struct, relying on the user to properly set the TERM environment variable. This variable is usually set by the terminal itself. It might be necessary to manually select a higher-quality definition for your terminal, i.e. xterm-direct as opposed to xterm or xterm-256color.

Each terminal can be prepared via a call to notcurses_init(), which is supplied a struct of type notcurses_options:

// Get a human-readable string describing the running ncurses version.
const char* notcurses_version(void);

// Configuration for notcurses_init().
typedef struct notcurses_options {
  // The name of the terminfo database entry describing this terminal. If NULL,
  // the environment variable TERM is used. Failure to open the terminal
  // definition will result in failure to initialize notcurses.
  const char* termtype;
  // A file descriptor for this terminal on which we will generate output.
  // Must be a valid file descriptor attached to a terminal, or notcurses will
  // refuse to start. You'll usually want STDOUT_FILENO.
  int outfd;
  // If smcup/rmcup capabilities are indicated, notcurses defaults to making
  // use of the "alternate screen". This flag inhibits use of smcup/rmcup.
  bool inhibit_alternate_screen;
} notcurses_options;

struct notcurses; // notcurses state for a given terminal

// Initialize a notcurses context, corresponding to a connected terminal.
// Returns NULL on error, including any failure to initialize terminfo.
struct notcurses* notcurses_init(const notcurses_options* opts);

// Destroy a notcurses context.
int notcurses_stop(struct notcurses* nc);

notcurses_stop should be called before exiting your program to restore the terminal settings and free resources.

The vast majority of the notcurses API draws into virtual buffers. Only upon a call to notcurses_render will the visible terminal display be updated to reflect the changes:

// Make the physical screen match the virtual screen. Changes made to the
// virtual screen (i.e. most other calls) will not be visible until after a
// successful call to notcurses_render().
int notcurses_render(struct notcurses* nc);

Planes

Fundamental to notcurses is a z-buffer of rectilinear virtual screens, known as ncplanes. An ncplane can be larger than the physical screen, or smaller, or the same size; it can be entirely contained within the physical screen, or overlap in part, or lie wholly beyond the boundaries, never to be rendered. Each ncplane has a current writing state (cursor position, foreground and background color, etc.), a backing array of wide characters, and a z-index. If opaque, a cell on a higher ncplane completely obstructs a corresponding cell from a lower ncplane from being seen. An ncplane corresponds loosely to an NCURSES Panel, but is the primary drawing surface of notcurses—there is no object corresponding to a bare NCURSES WINDOW.