1notcurses_direct(3) notcurses_direct(3)
2
3
4
6 notcurses_direct - minimal notcurses instances for styling text
7
9 #include <notcurses/direct.h>
10
11 #define NCDIRECT_OPTION_INHIBIT_SETLOCALE 0x0001ull
12 #define NCDIRECT_OPTION_INHIBIT_CBREAK 0x0002ull
13 #define NCDIRECT_OPTION_NO_QUIT_SIGHANDLERS 0x0008ull
14 #define NCDIRECT_OPTION_VERBOSE 0x0010ull
15 #define NCDIRECT_OPTION_VERY_VERBOSE 0x0020ull
16
17 struct ncdirect* ncdirect_init(const char* termtype, FILE* fp, uint64_t
18 flags);
19
20 unsigned ncdirect_palette_size(const struct ncdirect* nc);
21
22 int ncdirect_set_bg_rgb8(struct ncdirect* nc, unsigned r, unsigned g,
23 unsigned b);
24
25 int ncdirect_set_fg_rgb8(struct ncdirect* nc, unsigned r, unsigned g,
26 unsigned b);
27
28 int ncdirect_set_fg_rgb(struct ncdirect* nc, unsigned rgb);
29
30 int ncdirect_set_bg_rgb(struct ncdirect* nc, unsigned rgb);
31
32 int ncdirect_set_fg_default(struct ncdirect* nc);
33
34 int ncdirect_set_bg_default(struct ncdirect* nc);
35
36 int ncdirect_set_fg_palindex(struct ncdirect* nc, int pidx);
37
38 int ncdirect_set_bg_palindex(struct ncdirect* nc, int pidx);
39
40 int ncdirect_dim_x(const struct ncdirect* nc);
41
42 int ncdirect_dim_y(const struct ncdirect* nc);
43
44 unsigned ncdirect_supported_styles(const struct ncdirect* nc);
45
46 int ncdirect_styles_set(struct ncdirect* n, unsigned stylebits);
47
48 int ncdirect_styles_on(struct ncdirect* n, unsigned stylebits);
49
50 int ncdirect_styles_off(struct ncdirect* n, unsigned stylebits);
51
52 unsigned ncdirect_styles(struct ncdirect* n);
53
54 int ncdirect_clear(struct ncdirect* nc)
55
56 int ncdirect_stop(struct ncdirect* nc);
57
58 int ncdirect_cursor_move_yx(struct ncdirect* n, int y, int x);
59
60 int ncdirect_cursor_enable(struct ncdirect* nc);
61
62 int ncdirect_cursor_disable(struct ncdirect* nc);
63
64 int ncdirect_cursor_up(struct ncdirect* nc, int num);
65
66 int ncdirect_cursor_left(struct ncdirect* nc, int num);
67
68 int ncdirect_cursor_right(struct ncdirect* nc, int num);
69
70 int ncdirect_cursor_down(struct ncdirect* nc, int num);
71
72 int ncdirect_putstr(struct ncdirect* nc, uint64_t channels, const char*
73 utf8);
74
75 int ncdirect_putegc(struct ncdirect* nc, uint64_t channels, const char*
76 utf8, int* sbytes);
77
78 int ncdirect_printf_aligned(struct ncdirect* n, int y, ncalign_e align,
79 const char* fmt, ...);
80
81 const char* ncdirect_detected_terminal(const struct ncdirect* n);
82
83 int ncdirect_hline_interp(struct ncdirect* n, const char* egc, int len,
84 uint64_t h1, uint64_t h2);
85
86 int ncdirect_vline_interp(struct ncdirect* n, const char* egc, int len,
87 uint64_t h1, uint64_t h2);
88
89 int ncdirect_box(struct ncdirect* n, uint64_t ul, uint64_t ur, uint64_t
90 ll, uint64_t lr, const wchar_t* wchars, int ylen, int xlen, unsigned
91 ctlword);
92
93 int ncdirect_rounded_box(struct ncdirect* n, uint64_t ul, uint64_t ur,
94 uint64_t ll, uint64_t lr, int ylen, int xlen, unsigned ctlword);
95
96 int ncdirect_double_box(struct ncdirect* n, uint64_t ul, uint64_t ur,
97 uint64_t ll, uint64_t lr, int ylen, int xlen, unsigned ctlword);
98
99 ncdirectv* ncdirect_render_frame(struct ncdirect* n, const char* file‐
100 name, ncblitter_e blitter, ncscale_e scale, int maxy, int maxx);
101
102 char* ncdirect_readline(struct ncdirect* n, const char* prompt);
103
104 bool ncdirect_cantruecolor(const struct ncdirect* nc);
105
106 bool ncdirect_canchangecolor(const struct ncdirect* nc);
107
108 bool ncdirect_canfade(const struct ncdirect* nc);
109
110 bool ncdirect_canopen_images(const struct ncdirect* nc);
111
112 bool ncdirect_canopen_videos(const struct ncdirect* nc);
113
114 bool ncdirect_canutf8(const struct ncdirect* nc);
115
116 int ncdirect_check_pixel_support(const struct ncdirect* nc);
117
118 bool ncdirect_canhalfblock(const struct ncdirect* nc);
119
120 bool ncdirect_canquadrant(const struct ncdirect* nc);
121
122 bool ncdirect_cansextant(const struct ncdirect* nc);
123
124 bool ncdirect_canbraille(const struct ncdirect* nc);
125
126 bool ncdirect_canget_cursor(const struct ncdirect* nc);
127
128 typedef struct ncvgeom {
129 int pixy, pixx; // true pixel geometry of ncvisual data
130 int cdimy, cdimx; // terminal cell geometry when this was calculated
131 int rpixy, rpixx; // rendered pixel geometry
132 int rcelly, rcellx; // rendered cell geometry
133 int scaley, scalex; // pixels per filled cell
134 // only defined for NCBLIT_PIXEL
135 int maxpixely, maxpixelx;
136 } ncvgeom;
137
138 int ncdirect_render_image(struct ncdirect* n, const char* filename,
139 ncblitter_e blitter, ncscale_e scale);
140
141 int ncdirect_raster_frame(struct ncdirect* n, ncdirectv* ncdv,
142 ncalign_e align);
143
144 int ncdirect_stream(struct ncdirect* n, const char* filename, ncstream‐
145 cb streamer, struct ncvisual_options* vopts, void* curry);
146
147 int ncdirect_raster_frame(struct ncdirect* n, ncdirectv* ncdv,
148 ncalign_e align);
149
150 struct ncdirectf* ncdirectf_from_file(struct ncdirect* n, const char*
151 filename);*
152
153 void ncdirectf_free(struct ncdirectf* frame);
154
155 ncdirectv* ncdirectf_render(struct ncdirect* n, struct ncdirectf*
156 frame, const struct ncvisual_options vopts);
157
158 int ncdirectf_geom(struct ncdirect* n, struct ncdirectf* frame, const
159 struct ncvisual_options vopts, ncvgeom* geom);
160
162 ncdirect_init prepares the FILE provided as fp for colorizing and
163 styling. On success, a pointer to a valid struct ncdirect is returned.
164 NULL is returned on failure. Before the process exits, ncdirect_stop
165 should be called to reset the terminal and free up resources. ncdi‐
166 rect_init places the terminal into "cbreak" (also known as "rare")
167 mode, disabling line-buffering and echo of input. ncdirect_stop re‐
168 stores the terminal state as it was when the corresponding ncdi‐
169 rect_init call was made. A process can have only one context active at
170 once.
171
172 The following flags are defined:
173
174 • NCDIRECT_OPTION_INHIBIT_SETLOCALE: Unless this flag is set, ncdi‐
175 rect_init will call setlocale(LC_ALL, NULL). If the result is either
176 "C" or "POSIX", it will print a diagnostic to stderr, and then call
177 setlocale(LC_ALL, ""). This will attempt to set the locale based off
178 the LANG environment variable. Your program should call setlocale(3)
179 itself, usually as one of the first lines.
180
181 • NCDIRECT_OPTION_INHIBIT_CBREAK: Unless this flag is set, ncdi‐
182 rect_init will place the terminal into cbreak mode (i.e. disabling
183 echo and line buffering; see tcgetattr(3)).
184
185 • NCDIRECT_OPTION_DRAIN_INPUT: Standard input may be freely discarded.
186 If you do not intend to process input, pass this flag. Otherwise,
187 input can buffer up, eventually preventing Notcurses from processing
188 terminal messages. It will furthermore avoid wasting time processing
189 useless input.
190
191 • NCDIRECT_OPTION_NO_QUIT_SIGHANDLERS: A signal handler will usually be
192 installed for SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGINT, SIGQUIT,
193 SIGSEGV, and SIGTERM, cleaning up the terminal on such exceptions.
194 With this flag, the handler will not be installed.
195
196 • NCDIRECT_OPTION_VERBOSE: Enable diagnostics to stderr at the level of
197 NCLOGLEVEL_WARNING.
198
199 • NCDIRECT_OPTION_VERY_VERBOSE: Enable all diagnostics (equivalent to
200 NCLOGLEVEL_TRACE). Implies NCDIRECT_OPTION_VERBOSE.
201
202 The loglevel can also be set externally using the NOTCURSES_LOGLEVEL
203 environment variable. See notcurses_init(3) for more information.
204
205 An appropriate terminfo(5) entry must exist for the terminal. This en‐
206 try is usually selected using the value of the TERM environment vari‐
207 able (see getenv(3)), but a non-NULL value for termtype will override
208 this. An invalid terminfo specification can lead to reduced perfor‐
209 mance, reduced display capabilities, and/or display errors. notcurses
210 natively targets 24bpp/8bpc RGB color, and it is thus desirable to use
211 a terminal with the rgb capability (e.g. xterm's xterm-direct).
212
213 ncdirect_dim_x returns the current number of columns, and ncdi‐
214 rect_dim_y the current number of rows.
215
216 ncdirect_clear clears the screen using a control code if one exists in
217 terminfo. Otherwise, it prints successive newlines to scroll every‐
218 thing off.
219
220 ncdirect_cursor_move_yx moves the cursor to the specified coordinate.
221 -1 can be specified for either y or x to leave that axis unchanged.
222
223 ncdirect_enable_cursor and ncdirect_disable_cursor always flush the
224 output stream, taking effect immediately.
225
226 ncdirect_cursor_up and friends all move relative to the current posi‐
227 tion. Attempting to e.g. move up while on the top row will return 0,
228 but have no effect.
229
230 ncdirect_readline reads a (heap-allocated) line of arbitrary length,
231 supporting some libreadline-style line-editing controls. NCDIRECT_OP‐
232 TION_INHIBIT_CBREAK should not be used if you intend to use ncdi‐
233 rect_readline; if used, line-editing keybindings cannot be implemented.
234 Input will be echoed whether this option is used or not.
235
236 ncdirect_check_pixel_support must be called (and successfully return)
237 before NCBLIT_PIXEL can be used to render images; see notcurses_vis‐
238 ual(3) for more details.
239
240 When rendering an image, maxy and maxx specify a maximum number of
241 (cell) rows and columns to use, respectively. Passing 0 means "use as
242 much space as is necessary". It is an error to pass a negative number
243 for either.
244
246 ncdirect_init returns NULL on failure. Otherwise, the return value
247 points to a valid struct ncdirect, which can be used until it is pro‐
248 vided to ncdirect_stop.
249
250 ncdirect_printf_aligned returns the number of bytes written on success.
251 On failure, it returns some negative number.
252
253 ncdirect_putstr returns a nonnegative number on success, and EOF on
254 failure.
255
256 ncdirect_putegc returns the number of columns consumed on success, or
257 -1 on failure. If sbytes is not NULL, the number of bytes consumed
258 will be written to it.
259
260 ncdirect_check_pixel_support returns -1 on error, 0 if there is no pix‐
261 el support, and 1 if pixel support is successfully detected.
262
263 ncdirect_styles returns the current styling, a bitmask over the various
264 NCSTYLE_ constants.
265
266 All other functions return 0 on success, and non-zero on error.
267
269 You are recommended to accept -v and -vv as command-line options, map‐
270 ping them to NCDIRECT_OPTION_VERBOSE and NCDIRECT_OPTION_VERY_VERBOSE
271 respectively.
272
274 getenv(3), notcurses(3), notcurses_init(3), notcurses_plane(3),
275 notcurses_visual(3), terminfo(5), termios(3)
276
278 nick black <nickblack@linux.com>.
279
280
281
282 v2.4.9 notcurses_direct(3)