2021-02-03 05:18:10 +00:00
|
|
|
% notcurses_direct(3)
|
2020-01-25 06:13:04 +00:00
|
|
|
% nick black <nickblack@linux.com>
|
2021-11-19 02:36:24 +00:00
|
|
|
% v2.4.97
|
2020-01-25 06:13:04 +00:00
|
|
|
|
|
|
|
# NAME
|
|
|
|
|
2021-02-03 05:18:10 +00:00
|
|
|
notcurses_direct - minimal notcurses instances for styling text
|
2020-01-25 06:13:04 +00:00
|
|
|
|
|
|
|
# SYNOPSIS
|
|
|
|
|
2021-01-03 04:18:28 +00:00
|
|
|
```c
|
|
|
|
#include <notcurses/direct.h>
|
|
|
|
|
|
|
|
#define NCDIRECT_OPTION_INHIBIT_SETLOCALE 0x0001ull
|
|
|
|
#define NCDIRECT_OPTION_INHIBIT_CBREAK 0x0002ull
|
|
|
|
#define NCDIRECT_OPTION_NO_QUIT_SIGHANDLERS 0x0008ull
|
2021-06-19 07:16:39 +00:00
|
|
|
#define NCDIRECT_OPTION_VERBOSE 0x0010ull
|
|
|
|
#define NCDIRECT_OPTION_VERY_VERBOSE 0x0020ull
|
2021-01-03 04:18:28 +00:00
|
|
|
```
|
2020-01-25 06:13:04 +00:00
|
|
|
|
2020-11-06 21:41:17 +00:00
|
|
|
**struct ncdirect* ncdirect_init(const char* ***termtype***, FILE* ***fp***, uint64_t ***flags***);**
|
2020-01-25 06:13:04 +00:00
|
|
|
|
2020-11-06 21:41:17 +00:00
|
|
|
**unsigned ncdirect_palette_size(const struct ncdirect* ***nc***);**
|
2020-06-30 10:20:09 +00:00
|
|
|
|
2020-12-28 18:52:58 +00:00
|
|
|
**int ncdirect_set_bg_rgb8(struct ncdirect* ***nc***, unsigned ***r***, unsigned ***g***, unsigned ***b***);**
|
2020-02-02 09:15:12 +00:00
|
|
|
|
2020-12-28 18:52:58 +00:00
|
|
|
**int ncdirect_set_fg_rgb8(struct ncdirect* ***nc***, unsigned ***r***, unsigned ***g***, unsigned ***b***);**
|
2020-01-25 06:13:04 +00:00
|
|
|
|
2020-12-28 18:52:58 +00:00
|
|
|
**int ncdirect_set_fg_rgb(struct ncdirect* ***nc***, unsigned ***rgb***);**
|
2020-01-25 06:13:04 +00:00
|
|
|
|
2020-12-28 18:52:58 +00:00
|
|
|
**int ncdirect_set_bg_rgb(struct ncdirect* ***nc***, unsigned ***rgb***);**
|
2020-02-02 09:15:12 +00:00
|
|
|
|
2020-12-28 18:52:58 +00:00
|
|
|
**int ncdirect_set_fg_default(struct ncdirect* ***nc***);**
|
2020-02-14 04:16:41 +00:00
|
|
|
|
2020-12-28 18:52:58 +00:00
|
|
|
**int ncdirect_set_bg_default(struct ncdirect* ***nc***);**
|
2020-02-14 04:16:41 +00:00
|
|
|
|
2020-12-28 18:57:13 +00:00
|
|
|
**int ncdirect_set_fg_palindex(struct ncdirect* ***nc***, int ***pidx***);**
|
|
|
|
|
|
|
|
**int ncdirect_set_bg_palindex(struct ncdirect* ***nc***, int ***pidx***);**
|
|
|
|
|
2021-11-07 02:32:20 +00:00
|
|
|
**unsigned ncdirect_dim_x(const struct ncdirect* ***nc***);**
|
2020-02-05 07:27:41 +00:00
|
|
|
|
2021-11-07 02:32:20 +00:00
|
|
|
**unsigned ncdirect_dim_y(const struct ncdirect* ***nc***);**
|
2020-02-04 08:04:38 +00:00
|
|
|
|
2021-05-26 10:38:51 +00:00
|
|
|
**unsigned ncdirect_supported_styles(const struct ncdirect* ***nc***);**
|
|
|
|
|
2020-11-06 21:41:17 +00:00
|
|
|
**int ncdirect_styles_set(struct ncdirect* ***n***, unsigned ***stylebits***);**
|
2020-02-05 07:27:41 +00:00
|
|
|
|
2020-11-06 21:41:17 +00:00
|
|
|
**int ncdirect_styles_on(struct ncdirect* ***n***, unsigned ***stylebits***);**
|
2020-02-05 07:27:41 +00:00
|
|
|
|
2020-11-06 21:41:17 +00:00
|
|
|
**int ncdirect_styles_off(struct ncdirect* ***n***, unsigned ***stylebits***);**
|
2020-02-05 07:27:41 +00:00
|
|
|
|
2021-06-01 00:07:10 +00:00
|
|
|
**unsigned ncdirect_styles(struct ncdirect* ***n***);**
|
|
|
|
|
2020-11-06 21:41:17 +00:00
|
|
|
**int ncdirect_clear(struct ncdirect* ***nc***)**
|
2020-02-14 09:03:16 +00:00
|
|
|
|
2020-11-06 21:41:17 +00:00
|
|
|
**int ncdirect_stop(struct ncdirect* ***nc***);**
|
2020-01-25 06:13:04 +00:00
|
|
|
|
2020-11-06 21:41:17 +00:00
|
|
|
**int ncdirect_cursor_move_yx(struct ncdirect* ***n***, int ***y***, int ***x***);**
|
2020-02-24 21:56:51 +00:00
|
|
|
|
2021-11-07 02:32:20 +00:00
|
|
|
**int ncdirect_cursor_yx(struct ncdirect* ***n***, unsigned* ***y***, unsigned* ***x***);**
|
|
|
|
|
2020-11-06 21:41:17 +00:00
|
|
|
**int ncdirect_cursor_enable(struct ncdirect* ***nc***);**
|
2020-03-13 13:56:46 +00:00
|
|
|
|
2020-11-06 21:41:17 +00:00
|
|
|
**int ncdirect_cursor_disable(struct ncdirect* ***nc***);**
|
2020-03-13 13:56:46 +00:00
|
|
|
|
2020-11-06 21:41:17 +00:00
|
|
|
**int ncdirect_cursor_up(struct ncdirect* ***nc***, int ***num***);**
|
2020-04-08 13:07:49 +00:00
|
|
|
|
2020-11-06 21:41:17 +00:00
|
|
|
**int ncdirect_cursor_left(struct ncdirect* ***nc***, int ***num***);**
|
2020-04-08 13:07:49 +00:00
|
|
|
|
2020-11-06 21:41:17 +00:00
|
|
|
**int ncdirect_cursor_right(struct ncdirect* ***nc***, int ***num***);**
|
2020-04-08 13:07:49 +00:00
|
|
|
|
2020-11-06 21:41:17 +00:00
|
|
|
**int ncdirect_cursor_down(struct ncdirect* ***nc***, int ***num***);**
|
2020-04-08 13:07:49 +00:00
|
|
|
|
2020-11-06 21:41:17 +00:00
|
|
|
**int ncdirect_putstr(struct ncdirect* ***nc***, uint64_t ***channels***, const char* ***utf8***);**
|
2020-06-30 10:20:09 +00:00
|
|
|
|
2021-07-07 09:54:47 +00:00
|
|
|
**int ncdirect_putegc(struct ncdirect* ***nc***, uint64_t ***channels***, const char* ***utf8***, int* ***sbytes***);**
|
|
|
|
|
2020-11-06 21:41:17 +00:00
|
|
|
**int ncdirect_printf_aligned(struct ncdirect* ***n***, int ***y***, ncalign_e ***align***, const char* ***fmt***, ***...***);**
|
2020-10-19 13:34:41 +00:00
|
|
|
|
2021-06-12 17:10:16 +00:00
|
|
|
**const char* ncdirect_detected_terminal(const struct ncdirect* ***n***);**
|
|
|
|
|
2021-11-04 06:09:07 +00:00
|
|
|
**int ncdirect_hline_interp(struct ncdirect* ***n***, const char* ***egc***, unsigned ***len***, uint64_t ***h1***, uint64_t ***h2***);**
|
2020-07-10 22:37:41 +00:00
|
|
|
|
2021-11-04 06:09:07 +00:00
|
|
|
**int ncdirect_vline_interp(struct ncdirect* ***n***, const char* ***egc***, unsigned ***len***, uint64_t ***h1***, uint64_t ***h2***);**
|
2020-07-10 22:37:41 +00:00
|
|
|
|
2020-11-06 21:41:17 +00:00
|
|
|
**int ncdirect_box(struct ncdirect* ***n***, uint64_t ***ul***, uint64_t ***ur***, uint64_t ***ll***, uint64_t ***lr***, const wchar_t* ***wchars***, int ***ylen***, int ***xlen***, unsigned ***ctlword***);**
|
2020-07-10 22:37:41 +00:00
|
|
|
|
2020-11-06 21:41:17 +00:00
|
|
|
**int ncdirect_rounded_box(struct ncdirect* ***n***, uint64_t ***ul***, uint64_t ***ur***, uint64_t ***ll***, uint64_t ***lr***, int ***ylen***, int ***xlen***, unsigned ***ctlword***);**
|
2020-07-10 22:37:41 +00:00
|
|
|
|
2020-11-06 21:41:17 +00:00
|
|
|
**int ncdirect_double_box(struct ncdirect* ***n***, uint64_t ***ul***, uint64_t ***ur***, uint64_t ***ll***, uint64_t ***lr***, int ***ylen***, int ***xlen***, unsigned ***ctlword***);**
|
2020-07-10 22:37:41 +00:00
|
|
|
|
2021-03-15 03:16:29 +00:00
|
|
|
**ncdirectv* ncdirect_render_frame(struct ncdirect* ***n***, const char* ***filename***, ncblitter_e ***blitter***, ncscale_e ***scale***, int ***maxy***, int ***maxx***);**
|
|
|
|
|
2021-05-16 15:43:09 +00:00
|
|
|
**char* ncdirect_readline(struct ncdirect* ***n***, const char* ***prompt***);**
|
|
|
|
|
2021-06-18 18:24:26 +00:00
|
|
|
**bool ncdirect_cantruecolor(const struct ncdirect* ***nc***);**
|
|
|
|
|
|
|
|
**bool ncdirect_canchangecolor(const struct ncdirect* ***nc***);**
|
|
|
|
|
|
|
|
**bool ncdirect_canfade(const struct ncdirect* ***nc***);**
|
|
|
|
|
|
|
|
**bool ncdirect_canopen_images(const struct ncdirect* ***nc***);**
|
|
|
|
|
|
|
|
**bool ncdirect_canopen_videos(const struct ncdirect* ***nc***);**
|
|
|
|
|
|
|
|
**bool ncdirect_canutf8(const struct ncdirect* ***nc***);**
|
|
|
|
|
|
|
|
**int ncdirect_check_pixel_support(const struct ncdirect* ***nc***);**
|
|
|
|
|
|
|
|
**bool ncdirect_canhalfblock(const struct ncdirect* ***nc***);**
|
|
|
|
|
|
|
|
**bool ncdirect_canquadrant(const struct ncdirect* ***nc***);**
|
|
|
|
|
|
|
|
**bool ncdirect_cansextant(const struct ncdirect* ***nc***);**
|
|
|
|
|
|
|
|
**bool ncdirect_canbraille(const struct ncdirect* ***nc***);**
|
|
|
|
|
|
|
|
**bool ncdirect_canget_cursor(const struct ncdirect* ***nc***);**
|
|
|
|
|
2021-11-09 05:54:29 +00:00
|
|
|
**uint32_t ncdirect_get(struct ncdirect* ***n***, const struct timespec* ***absdl***, ncinput* ***ni***);**
|
|
|
|
|
2021-05-16 15:43:09 +00:00
|
|
|
```c
|
|
|
|
typedef struct ncvgeom {
|
|
|
|
int pixy, pixx; // true pixel geometry of ncvisual data
|
|
|
|
int cdimy, cdimx; // terminal cell geometry when this was calculated
|
|
|
|
int rpixy, rpixx; // rendered pixel geometry
|
|
|
|
int rcelly, rcellx; // rendered cell geometry
|
|
|
|
int scaley, scalex; // pixels per filled cell
|
|
|
|
// only defined for NCBLIT_PIXEL
|
|
|
|
int maxpixely, maxpixelx;
|
|
|
|
} ncvgeom;
|
|
|
|
```
|
|
|
|
|
|
|
|
**int ncdirect_render_image(struct ncdirect* ***n***, const char* ***filename***, ncblitter_e ***blitter***, ncscale_e ***scale***);**
|
|
|
|
|
2021-03-15 03:16:29 +00:00
|
|
|
**int ncdirect_raster_frame(struct ncdirect* ***n***, ncdirectv* ***ncdv***, ncalign_e ***align***);**
|
|
|
|
|
2021-04-10 08:07:16 +00:00
|
|
|
**int ncdirect_stream(struct ncdirect* ***n***, const char* ***filename***, ncstreamcb ***streamer***, struct ncvisual_options* ***vopts***, void* ***curry***);**
|
|
|
|
|
2021-05-16 15:43:09 +00:00
|
|
|
**int ncdirect_raster_frame(struct ncdirect* ***n***, ncdirectv* ***ncdv***, ncalign_e ***align***);**
|
|
|
|
|
|
|
|
**struct ncdirectf* ncdirectf_from_file(struct ncdirect* ***n***, const char* ***filename***);***
|
|
|
|
|
|
|
|
**void ncdirectf_free(struct ncdirectf* ***frame***);**
|
|
|
|
|
2021-06-09 10:52:02 +00:00
|
|
|
**ncdirectv* ncdirectf_render(struct ncdirect* ***n***, struct ncdirectf* ***frame***, const struct ncvisual_options ***vopts***);**
|
2021-05-16 15:43:09 +00:00
|
|
|
|
2021-06-10 01:52:42 +00:00
|
|
|
**int ncdirectf_geom(struct ncdirect* ***n***, struct ncdirectf* ***frame***, const struct ncvisual_options ***vopts***, ncvgeom* ***geom***);**
|
2021-05-16 15:43:09 +00:00
|
|
|
|
2021-02-03 05:18:10 +00:00
|
|
|
|
2020-01-25 06:13:04 +00:00
|
|
|
# DESCRIPTION
|
|
|
|
|
2020-10-26 18:33:35 +00:00
|
|
|
**ncdirect_init** prepares the **FILE** provided as **fp** for colorizing and
|
|
|
|
styling. On success, a pointer to a valid **struct ncdirect** is returned.
|
|
|
|
**NULL** is returned on failure. Before the process exits, **ncdirect_stop**
|
|
|
|
should be called to reset the terminal and free up resources. **ncdirect_init**
|
|
|
|
places the terminal into "cbreak" (also known as "rare") mode, disabling
|
|
|
|
line-buffering and echo of input. **ncdirect_stop** restores the terminal state
|
2021-06-01 21:35:04 +00:00
|
|
|
as it was when the corresponding **ncdirect_init** call was made. A process
|
|
|
|
can have only one context active at once.
|
2020-01-25 06:13:04 +00:00
|
|
|
|
2020-10-07 11:24:04 +00:00
|
|
|
The following flags are defined:
|
|
|
|
|
|
|
|
* **NCDIRECT_OPTION_INHIBIT_SETLOCALE**: Unless this flag is set,
|
|
|
|
**ncdirect_init** will call **setlocale(LC_ALL, NULL)**. If the result is
|
2020-11-04 17:27:36 +00:00
|
|
|
either "**C**" or "**POSIX**", it will print a diagnostic to **stderr**, and
|
2020-10-07 11:24:04 +00:00
|
|
|
then call **setlocale(LC_ALL, "").** This will attempt to set the locale
|
|
|
|
based off the **LANG** environment variable. Your program should call
|
|
|
|
**setlocale(3)** itself, usually as one of the first lines.
|
|
|
|
|
|
|
|
* **NCDIRECT_OPTION_INHIBIT_CBREAK**: Unless this flag is set, **ncdirect_init**
|
|
|
|
will place the terminal into cbreak mode (i.e. disabling echo and line
|
|
|
|
buffering; see **tcgetattr(3)**).
|
2020-08-30 17:00:41 +00:00
|
|
|
|
2021-09-12 07:25:37 +00:00
|
|
|
* **NCDIRECT_OPTION_DRAIN_INPUT**: Standard input may be freely discarded. If
|
|
|
|
you do not intend to process input, pass this flag. Otherwise, input can
|
|
|
|
buffer up, eventually preventing Notcurses from processing terminal
|
|
|
|
messages. It will furthermore avoid wasting time processing useless input.
|
|
|
|
|
2021-10-23 02:07:41 +00:00
|
|
|
* **NCDIRECT_OPTION_NO_QUIT_SIGHANDLERS**: A signal handler will usually be
|
|
|
|
installed for **SIGABRT**, **SIGBUS**, **SIGFPE**, **SIGILL**, **SIGINT**,
|
|
|
|
**SIGQUIT**, **SIGSEGV**, and **SIGTERM**, cleaning up the terminal on
|
|
|
|
such exceptions. With this flag, the handler will not be installed.
|
2021-01-03 04:18:28 +00:00
|
|
|
|
2021-06-19 07:16:39 +00:00
|
|
|
* **NCDIRECT_OPTION_VERBOSE**: Enable diagnostics to **stderr** at the level of
|
|
|
|
**NCLOGLEVEL_WARNING**.
|
|
|
|
|
|
|
|
* **NCDIRECT_OPTION_VERY_VERBOSE**: Enable all diagnostics (equivalent to
|
|
|
|
**NCLOGLEVEL_TRACE**). Implies **NCDIRECT_OPTION_VERBOSE**.
|
|
|
|
|
2021-10-17 21:28:35 +00:00
|
|
|
The loglevel can also be set externally using the **NOTCURSES_LOGLEVEL**
|
|
|
|
environment variable. See **notcurses_init(3)** for more information.
|
|
|
|
|
2020-01-25 06:13:04 +00:00
|
|
|
An appropriate **terminfo(5)** entry must exist for the terminal. This entry is
|
|
|
|
usually selected using the value of the **TERM** environment variable (see
|
|
|
|
**getenv(3)**), but a non-**NULL** value for **termtype** 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
|
|
|
|
**rgb** capability (e.g. xterm's **xterm-direct**).
|
|
|
|
|
2020-02-04 08:04:38 +00:00
|
|
|
**ncdirect_dim_x** returns the current number of columns, and **ncdirect_dim_y**
|
|
|
|
the current number of rows.
|
|
|
|
|
2020-02-14 09:03:16 +00:00
|
|
|
**ncdirect_clear** clears the screen using a control code if one exists in
|
|
|
|
terminfo. Otherwise, it prints successive newlines to scroll everything off.
|
|
|
|
|
2020-02-24 21:56:51 +00:00
|
|
|
**ncdirect_cursor_move_yx** moves the cursor to the specified coordinate. -1 can
|
|
|
|
be specified for either **y** or **x** to leave that axis unchanged.
|
|
|
|
|
2020-03-13 13:56:46 +00:00
|
|
|
**ncdirect_enable_cursor** and **ncdirect_disable_cursor** always flush the
|
|
|
|
output stream, taking effect immediately.
|
|
|
|
|
2020-04-08 13:07:49 +00:00
|
|
|
**ncdirect_cursor_up** and friends all move relative to the current position.
|
|
|
|
Attempting to e.g. move up while on the top row will return 0, but have no
|
|
|
|
effect.
|
|
|
|
|
2021-09-28 05:37:44 +00:00
|
|
|
**ncdirect_readline** reads a (heap-allocated) line of arbitrary length,
|
|
|
|
supporting some libreadline-style line-editing controls.
|
|
|
|
**NCDIRECT_OPTION_INHIBIT_CBREAK** should not be used if you intend to
|
|
|
|
use **ncdirect_readline**; if used, line-editing keybindings cannot be
|
|
|
|
implemented. Input will be echoed whether this option is used or not.
|
2021-02-03 05:18:10 +00:00
|
|
|
|
2021-02-27 19:52:16 +00:00
|
|
|
**ncdirect_check_pixel_support** must be called (and successfully return)
|
|
|
|
before **NCBLIT_PIXEL** can be used to render images; see
|
|
|
|
**notcurses_visual(3)** for more details.
|
|
|
|
|
2021-05-18 07:28:50 +00:00
|
|
|
When rendering an image, ***maxy*** and ***maxx*** specify a maximum number
|
|
|
|
of (cell) rows and columns to use, respectively. Passing 0 means "use as much
|
|
|
|
space as is necessary". It is an error to pass a negative number for either.
|
|
|
|
|
2020-01-25 06:13:04 +00:00
|
|
|
# RETURN VALUES
|
|
|
|
|
2020-03-03 01:19:16 +00:00
|
|
|
**ncdirect_init** returns **NULL** on failure. Otherwise, the return value
|
|
|
|
points to a valid **struct ncdirect**, which can be used until it is provided
|
|
|
|
to **ncdirect_stop**.
|
2020-01-25 06:13:04 +00:00
|
|
|
|
2021-11-04 12:41:53 +00:00
|
|
|
**ncdirect_printf_aligned** returns the number of bytes written on success. On
|
|
|
|
failure, it returns some negative number.
|
|
|
|
|
|
|
|
**ncdirect_putstr** returns a nonnegative number on success, and **EOF**
|
|
|
|
on failure.
|
2020-10-19 08:24:40 +00:00
|
|
|
|
2021-07-07 09:54:47 +00:00
|
|
|
**ncdirect_putegc** returns the number of columns consumed on success, or -1
|
|
|
|
on failure. If ***sbytes*** is not **NULL**, the number of bytes consumed
|
|
|
|
will be written to it.
|
|
|
|
|
2021-02-27 19:52:16 +00:00
|
|
|
**ncdirect_check_pixel_support** returns -1 on error, 0 if there is no pixel
|
|
|
|
support, and 1 if pixel support is successfully detected.
|
|
|
|
|
2021-06-01 00:07:10 +00:00
|
|
|
**ncdirect_styles** returns the current styling, a bitmask over the various
|
|
|
|
**NCSTYLE_** constants.
|
|
|
|
|
2020-03-13 13:56:46 +00:00
|
|
|
All other functions return 0 on success, and non-zero on error.
|
|
|
|
|
2021-06-19 07:16:39 +00:00
|
|
|
# NOTES
|
|
|
|
|
|
|
|
You are recommended to accept **-v** and **-vv** as command-line options,
|
|
|
|
mapping them to **NCDIRECT_OPTION_VERBOSE** and
|
|
|
|
**NCDIRECT_OPTION_VERY_VERBOSE** respectively.
|
|
|
|
|
2020-01-25 06:13:04 +00:00
|
|
|
# SEE ALSO
|
|
|
|
|
2020-02-14 04:16:41 +00:00
|
|
|
**getenv(3)**,
|
|
|
|
**notcurses(3)**,
|
2021-10-17 21:28:35 +00:00
|
|
|
**notcurses_init(3)**,
|
2020-05-09 00:56:39 +00:00
|
|
|
**notcurses_plane(3)**,
|
2021-02-27 19:52:16 +00:00
|
|
|
**notcurses_visual(3)**,
|
2021-01-08 12:27:26 +00:00
|
|
|
**terminfo(5)**,
|
|
|
|
**termios(3)**
|