.\" Automatically generated by Pandoc 2.9.2.1 .\" .TH "notcurses_init" "3" "v2.0.4" "" "" .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_VERIFY_SIXEL 0x0002ull #define NCOPTION_NO_WINCH_SIGHANDLER 0x0004ull #define NCOPTION_NO_QUIT_SIGHANDLERS 0x0008ull #define NCOPTION_SUPPRESS_BANNERS 0x0020ull #define NCOPTION_NO_ALTERNATE_SCREEN 0x0040ull #define NCOPTION_NO_FONT_CHANGES 0x0080ull typedef enum { NCLOGLEVEL_SILENT, // default. print nothing once fullscreen service begins NCLOGLEVEL_PANIC, // print diagnostics immediately related to crashing NCLOGLEVEL_FATAL, // we\[aq]re hanging around, but we\[aq]ve had a horrible fault NCLOGLEVEL_ERROR, // we can\[aq]t keep doin\[aq] 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; FILE* renderfp; ncloglevel_e loglevel; int 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_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]fp\f[R] must be writable and attached to a terminal, or \f[B]NULL\f[R]. If it is \f[B]NULL\f[R], \f[B]/dev/tty\f[R] will be opened. The \f[B]struct notcurses_option\f[R] passed as \f[B]opts\f[R] controls behavior. Only one instance should be associated with a given terminal at a time, though it is no problem to have multiple instances in a given process. .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. 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\[cq]s \f[B]xterm-direct\f[R]). .PP If the terminal advertises support for an \[lq]alternate screen\[rq] 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]flags\f[R]. Users tend to have strong opinions regarding the alternate screen, so it\[cq]s often useful to expose this via a command-line option. .PP notcurses hides the cursor by default. It can be dynamically enabled, moved, or disabled during execution via \f[B]notcurses_cursor_enable(3)\f[R] and \f[B]notcurses_cursor_disable(3)\f[R]. .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. This is the only means by which existing output can be undisturbed by notcurses. 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 \[lq]\f[B]C\f[R]\[rq] or \[lq]\f[B]POSIX\f[R]\[rq], 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_VERIFY_SIXEL\f[R]: Checking for Sixel support requires writing an escape, and then reading an inline reply from the terminal. Since this can interact poorly with actual user input, it\[cq]s not done unless Sixel will actually be used. Set this flag to unconditionally test for Sixel support in \f[B]notcurses_init\f[R]. .IP \[bu] 2 \f[B]NCOPTION_NO_WINCH_SIGHANDLER\f[R]: A signal handler will usually be installed for \f[B]SIGWINCH\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]SIGINT\f[R], \f[B]SIGQUIT\f[R], \f[B]SIGSEGV\f[R], \f[B]SIGTERM\f[R], and \f[B]SIGABRT\f[R], cleaning up the terminal on such exceptions. With this flag, the handler will not be installed. .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. .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, set \f[B]no_quit_sighandlers\f[R] to \f[B]true\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\[cq]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. .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]. .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]terminfo(5)\f[R], \f[B]signal(7)\f[R] .SH AUTHORS nick black .