.\" Automatically generated by Pandoc 2.9.2.1 .\" .TH "notcurses_init" "3" "v3.0.0" "" "" .hy .SH NAME .PP notcurses_init - initialize a notcurses instance .SH SYNOPSIS .PP \f[B]#include \f[R] .IP .nf \f[C] #define NCOPTION_INHIBIT_SETLOCALE 0x0001ull #define NCOPTION_NO_CLEAR_BITMAPS 0x0002ull #define NCOPTION_NO_WINCH_SIGHANDLER 0x0004ull #define NCOPTION_NO_QUIT_SIGHANDLERS 0x0008ull #define NCOPTION_PRESERVE_CURSOR 0x0010ull #define NCOPTION_SUPPRESS_BANNERS 0x0020ull #define NCOPTION_NO_ALTERNATE_SCREEN 0x0040ull #define NCOPTION_NO_FONT_CHANGES 0x0080ull #define NCOPTION_DRAIN_INPUT 0x0100ull typedef enum { NCLOGLEVEL_SILENT, // print nothing once fullscreen service begins NCLOGLEVEL_PANIC, // default. print diagnostics before we crash/exit NCLOGLEVEL_FATAL, // we\[aq]re hanging around, but we\[aq]ve had a horrible fault NCLOGLEVEL_ERROR, // we can\[aq]t keep doing this, but we can do other things NCLOGLEVEL_WARNING, // you probably don\[aq]t want what\[aq]s happening to happen NCLOGLEVEL_INFO, // \[dq]standard information\[dq] NCLOGLEVEL_VERBOSE, // \[dq]detailed information\[dq] NCLOGLEVEL_DEBUG, // this is honestly a bit much NCLOGLEVEL_TRACE, // there\[aq]s probably a better way to do what you want } ncloglevel_e; typedef struct notcurses_options { const char* termtype; ncloglevel_e loglevel; unsigned margin_t, margin_r, margin_b, margin_l; uint64_t flags; // from NCOPTION_* bits } notcurses_options; \f[R] .fi .PP \f[B]struct notcurses* notcurses_init(const notcurses_options* \f[R]\f[I]opts\f[R]\f[B], FILE* \f[R]\f[I]fp\f[R]\f[B]);\f[R] .PP \f[B]void notcurses_version_components(int* \f[R]\f[I]major\f[R]\f[B], int* \f[R]\f[I]minor\f[R]\f[B], int* \f[R]\f[I]patch\f[R]\f[B], int* \f[R]\f[I]tweak\f[R]\f[B]);\f[R] .PP \f[B]int notcurses_lex_margins(const char* \f[R]\f[I]op\f[R]\f[B], notcurses_options* \f[R]\f[I]opts\f[R]\f[B]);\f[R] .PP \f[B]int notcurses_cursor_enable(struct notcurses* \f[R]\f[I]nc\f[R]\f[B], int \f[R]\f[I]y\f[R]\f[B], int \f[R]\f[I]x\f[R]\f[B]);\f[R] .PP \f[B]int notcurses_cursor_yx(struct notcurses* \f[R]\f[I]nc\f[R]\f[B], int* \f[R]\f[I]y\f[R]\f[B], int* \f[R]\f[I]x\f[R]\f[B]);\f[R] .PP \f[B]int notcurses_cursor_disable(struct notcurses* \f[R]\f[I]nc\f[R]\f[B]);\f[R] .SH DESCRIPTION .PP \f[B]notcurses_init\f[R] prepares the terminal for cursor-addressable (multiline) mode. The \f[B]FILE\f[R] provided as \f[B]\f[BI]fp\f[B]\f[R] must be writable, or \f[B]NULL\f[R] (if it is \f[B]NULL\f[R], \f[B]stdout\f[R] will be used). If the \f[B]FILE\f[R] is not connected to a terminal, \f[B]/dev/tty\f[R] will be opened (if possible) for communication with the controlling terminal. The \f[B]struct notcurses_option\f[R] passed as \f[B]\f[BI]opts\f[B]\f[R] controls behavior. Passing a \f[B]NULL\f[R] \f[B]\f[BI]opts\f[B]\f[R] is equivalent to passing an all-zero (default) \f[B]\f[BI]opts\f[B]\f[R]. A process can have only one Notcurses context active at a time; calling \f[B]notcurses_init\f[R] again before calling \f[B]notcurses_stop\f[R] will return \f[B]NULL\f[R]. .PP On success, a pointer to a valid \f[B]struct notcurses\f[R] is returned. \f[B]NULL\f[R] is returned on failure. Before the process exits, \f[B]notcurses_stop(3)\f[R] should be called to reset the terminal and free up resources. .PP An appropriate \f[B]terminfo(5)\f[R] entry must exist for the terminal. This entry is usually selected using the value of the \f[B]TERM\f[R] environment variable (see \f[B]getenv(3)\f[R]), but a non-\f[B]NULL\f[R] value for \f[B]termtype\f[R] will override this (terminfo is not used on Microsoft Windows, and it is neither meaningful nor necessary to define \f[B]TERM\f[R] there). An invalid terminfo specification can lead to reduced performance, reduced display capabilities, and/or display errors. notcurses natively targets 24bpp/8bpc RGB color, and it is thus desirable to use a terminal with the \f[B]rgb\f[R] capability (e.g. xterm\[aq]s \f[B]xterm-direct\f[R]). Colors will otherwise be quantized down to whatever the terminal supports. .PP If the terminal advertises support for an \[dq]alternate screen\[dq] via the \f[B]smcup\f[R] terminfo capability, notcurses will employ it by default. This can be prevented by setting \f[B]NCOPTION_NO_ALTERNATE_SCREEN\f[R] in \f[B]\f[BI]flags\f[B]\f[R]. Users tend to have strong opinions regarding the alternate screen, so it\[aq]s often useful to expose this via a command-line option. When the alternate screen is not used, the contents of the terminal at startup remain visible until obliterated, on a cell-by-cell basis (see \f[B]notcurses_plane(3)\f[R] for details on clearing the screen at startup without using the alternate screen). If the alternate screen is not available, the display will still be cleared without \f[B]NCOPTION_NO_ALTERNATE_SCREEN\f[R]. .PP notcurses hides the cursor by default. It can be dynamically enabled, moved, or disabled during execution via \f[B]notcurses_cursor_enable\f[R] and \f[B]notcurses_cursor_disable\f[R]. It will be hidden while updating the screen. The current location of the terminal cursor can be acquired with \f[B]notcurses_cursor_yx\f[R], whether visible or not. .PP \f[B]notcurses_init\f[R] typically emits some diagnostics at startup, including version information and some details of the configured terminal. This can be inhibited with \f[B]NCOPTION_SUPPRESS_BANNERS\f[R]. This will also inhibit the performance summary normally printed by \f[B]notcurses_stop(3)\f[R]. .PP Notcurses can render to a subregion of the terminal by specifying desired margins on all four sides. By default, all margins are zero, and thus rendering will be performed on the entirety of the viewing area. This is orthogonal to use of the alternate screen; using the alternate screen plus margins will see the full screen cleared, followed by rendering to a subregion. Inhibiting the alternate screen plus margins will see rendering to a subregion, with the screen outside this region not cleared. Margins are best-effort. Supplying any negative margin is an error. \f[B]notcurses_lex_margins\f[R] provides lexing a margin argument expression in one of two forms: .IP \[bu] 2 a single number, which will be applied to all sides, or .IP \[bu] 2 four comma-delimited numbers, applied to top, right, bottom, and left. .PP To allow future options without requiring redefinition of the structure, the \f[B]flags\f[R] field is only a partially-defined bitfield. Undefined bits should be zero. The following flags are defined: .IP \[bu] 2 \f[B]NCOPTION_INHIBIT_SETLOCALE\f[R]: Unless this flag is set, \f[B]notcurses_init\f[R] will call \f[B]setlocale(LC_ALL, NULL)\f[R]. If the result is either \[dq]\f[B]C\f[R]\[dq] or \[dq]\f[B]POSIX\f[R]\[dq], it will print a diagnostic to \f[B]stderr\f[R], and then call \f[B]setlocale(LC_ALL, \[dq]\[dq]).\f[R] This will attempt to set the locale based off the \f[B]LANG\f[R] environment variable. Your program should call \f[B]setlocale(3)\f[R] itself, usually as one of the first lines. .IP \[bu] 2 \f[B]NCOPTION_NO_CLEAR_BITMAPS\f[R]: On entry, make no special attempt to clear any preexisting bitmaps. Note that they might still get cleared even if this is set, and they might not get cleared even if this is not set. .IP \[bu] 2 \f[B]NCOPTION_NO_WINCH_SIGHANDLER\f[R]: A signal handler will usually be installed for \f[B]SIGWINCH\f[R] and \f[B]SIGCONT\f[R], resulting in \f[B]NCKEY_RESIZE\f[R] events being generated on input. With this flag, the handler will not be installed. .IP \[bu] 2 \f[B]NCOPTION_NO_QUIT_SIGHANDLERS\f[R]: A signal handler will usually be installed for \f[B]SIGABRT\f[R], \f[B]SIGBUS\f[R], \f[B]SIGFPE\f[R], \f[B]SIGILL\f[R], \f[B]SIGINT\f[R], \f[B]SIGQUIT\f[R], \f[B]SIGSEGV\f[R], and \f[B]SIGTERM\f[R], cleaning up the terminal on such exceptions. With this flag, the handler will not be installed. .IP \[bu] 2 \f[B]NCOPTION_PRESERVE_CURSOR\f[R]: The virtual cursor is typically placed at the screen\[aq]s origin at startup. With this flag, it is instead placed wherever the cursor was at program launch. .IP \[bu] 2 \f[B]NCOPTION_SUPPRESS_BANNERS\f[R]: Disables the diagnostics and version information printed on startup, and the performance summary on exit. .IP \[bu] 2 \f[B]NCOPTION_NO_ALTERNATE_SCREEN\f[R]: Do not use the alternate screen (see \f[B]terminfo(5)\f[R]), even if it is available. .IP \[bu] 2 \f[B]NCOPTION_NO_FONT_CHANGES\f[R]: Do not touch the font. Notcurses might otherwise attempt to extend the font, especially in the Linux console. .IP \[bu] 2 \f[B]NCOPTION_DRAIN_INPUT\f[R]: Standard input may be freely discarded. If you do not intend to process input, pass this flag. Otherwise, input can buffer up, and eventually prevent Notcurses from processing messages from the terminal. It will furthermore avoid wasting time processing useless input. .SS Fatal signals .PP It is important to reset the terminal before exiting, whether terminating due to intended operation or a received signal. This is usually accomplished by explicitly calling \f[B]notcurses_stop(3)\f[R] during shutdown. For convenience, notcurses by default installs signal handlers for various signals which would typically result in process termination (see \f[B]signal(7)\f[R]). These signal handlers call \f[B]notcurses_stop(3)\f[R] for each \f[B]struct notcurses\f[R] in the process, and then propagate the signal to any previously-configured handler. These handlers are disabled upon entry to \f[B]notcurses_stop(3)\f[R]. .PP To prevent signal handler registration, provide \f[B]NCOPTION_NO_QUIT_SIGHANDLERS\f[R]. No means is provided to selectively register fatal signal handlers. If this is done, the caller ought be sure to effect similar functionality themselves. .SS Resize events .PP \f[B]SIGWINCH\f[R] (SIGnal WINdow CHange) is delivered to the process when the terminal is resized. The default action is to ignore it (\f[B]SIG_IGN\f[R]). notcurses installs a handler for this signal. The handler causes notcurses to update its idea of the terminal\[aq]s size using \f[B]TIOCGWINSZ\f[R] (see \f[B]ioctl_tty(2)\f[R]), and generates an \f[B]NCKEY_RESIZE\f[R] input event (see \f[B]notcurses_input(3)\f[R]. This signal handler can be inhibited by setting \f[B]NCOPTION_NO_WINCH_SIGHANDLER\f[R] in \f[B]flags\f[R]. If this is done, the caller should probably watch for the signal, and invoke \f[B]notcurses_refresh(3)\f[R] or \f[B]notcurses_render(3)\f[R] upon its receipt. .PP A resize event does not invalidate any references returned earlier by notcurses. The content of any new screen area is undefined until the next call to \f[B]notcurses_render(3)\f[R]. This is true even if an existing \f[B]struct ncplane\f[R] (see \f[B]notcurses_plane(3)\f[R]) overlaps the new area, since the signal could arrive while the ncplanes are being modified. Signal handlers are quite restricted as to what actions they can perform, so minimal work is performed in the handler proper. .PP Thus, in the absence of \f[B]NCOPTION_NO_WINCH_SIGHANDLER\f[R], \f[B]SIGWINCH\f[R] results in: .IP \[bu] 2 interruption of some thread to process the signal .IP \[bu] 2 a \f[B]TIOCGWINSZ\f[R] \f[B]ioctl\f[R] to retrieve the new screen size .IP \[bu] 2 queuing of a \f[B]NCKEY_RESIZE\f[R] input event (if there is space in the queue) .PP Upon the next call to \f[B]notcurses_render(3)\f[R] or \f[B]notcurses_refresh(3)\f[R], the standard plane (see \f[B]notcurses_stdplane(3)\f[R]) will be resized to the new screen size. The next \f[B]notcurses_render(3)\f[R] call will function as expected across the new screen geometry. .SS The hardware cursor .PP Most terminals provide a cursor, a visual indicator of where output will next be placed. There is usually (but not always) some degree of control over what glyph forms this cursor, and whether it e.g. blinks. .PP By default, Notcurses disables this cursor in rendered mode. It can be turned back on with \f[B]notcurses_enable_cursor\f[R], which has immediate effect (there is no need to call \f[B]notcurses_render(3)\f[R]). If already visible, this function updates the location. Each time the physical screen is updated, Notcurses will disable the cursor, write the update, move the cursor back to this location, and finally make the cursor visible. \f[B]notcurses_cursor_yx\f[R] retrieves the location of the cursor, whether visible or not. \f[B]notcurses_disable_cursor\f[R] hides the cursor. .PP You generally shouldn\[aq]t need to touch the terminal cursor. It\[aq]s only really relevant with echoed user input, and you don\[aq]t want echoed user input in rendered mode (instead, read the input, and write it to a plane yourself). A subprocess can be streamed to a plane with an \f[B]ncsubproc\f[R], etc. .PP If the \f[B]NCOPTION_PRESERVE_CURSOR\f[R] flag is provided, the cursor\[aq]s location will be determined at startup, and the standard plane\[aq]s virtual cursor will be placed to match it (instead of in the upper-left corner). Combined with \f[B]NCOPTION_NO_ALTERNATE_SCREEN\f[R] and a scrolling standard plane, this allows rendered mode to be used as a normal scrolling shell application. .SH RETURN VALUES .PP \f[B]NULL\f[R] is returned on failure. Otherwise, the return value points at a valid \f[B]struct notcurses\f[R], which can be used until it is provided to \f[B]notcurses_stop(3)\f[R]. .PP \f[B]notcurses_cursor_disable\f[R] returns -1 if the cursor is already invisible. .SH ENVIRONMENT VARIABLES .PP The \f[B]NOTCURSES_LOGLEVEL\f[R] environment variable, if defined, ought be an integer between -1 and 7. These values correspond to \f[B]NCLOGLEVEL_SILENT\f[R] through \f[B]NCLOGLEVEL_TRACE\f[R], and override the \f[B]loglevel\f[R] field of \f[B]notcurses_options\f[R]. .PP The \f[B]TERM\f[R] environment variable will be used by \f[B]setupterm(3ncurses)\f[R] to select an appropriate terminfo database. .SH NOTES .PP Several command-line options and keybindings are recommended for Notcurses rendered-mode programs: .IP \[bu] 2 \f[B]-l[0-8]\f[R] ought be mapped to the various \f[B]NCLOGLEVEL\f[R] values. Alternatively, map \f[B]-v\f[R] to \f[B]NCLOGLEVEL_WARNING\f[R], and map \f[B]-vv\f[R] to \f[B]NCLOGLEVEL_INFO\f[R]. .IP \[bu] 2 \f[B]-k\f[R] ought be mapped to \f[B]NCOPTION_NO_ALTERNATE_SCREEN\f[R]. .IP \[bu] 2 Ctrl+L ought be mapped to \f[B]notcurses_refresh(3)\f[R]. .SH SEE ALSO .PP \f[B]getenv(3)\f[R], \f[B]setlocale(3)\f[R], \f[B]termios(3)\f[R], \f[B]notcurses(3)\f[R], \f[B]notcurses_input(3)\f[R], \f[B]notcurses_plane(3)\f[R], \f[B]notcurses_refresh(3)\f[R], \f[B]notcurses_render(3)\f[R], \f[B]notcurses_stop(3)\f[R], \f[B]setupterm(3ncurses)\f[R], \f[B]terminfo(5)\f[R], \f[B]signal(7)\f[R] .SH AUTHORS nick black .