Notcurses 3.0.13
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
notcurses.h
Go to the documentation of this file.
1#ifndef NOTCURSES_NOTCURSES
2#define NOTCURSES_NOTCURSES
3
4#include <time.h>
5#include <ctype.h>
6#include <wchar.h>
7#include <stdio.h>
8#include <stdint.h>
9#include <stdlib.h>
10#include <stdarg.h>
11#include <string.h>
12#include <signal.h>
13#include <limits.h>
14#include <stdbool.h>
15#include <notcurses/ncport.h>
16#include <notcurses/nckeys.h>
17#include <notcurses/ncseqs.h>
18
19#ifdef __cplusplus
20extern "C" {
21#define RESTRICT
22#define _Static_assert(...)
23#else
24#define RESTRICT restrict
25#endif
26
27#ifdef NOTCURSES_FFI
28#define static API
29#endif
30
31#ifndef __MINGW32__
32#define API __attribute__((visibility("default")))
33#else
34#define API __declspec(dllexport)
35#endif
36#define ALLOC __attribute__((malloc)) __attribute__((warn_unused_result))
37
38// Get a human-readable string describing the running Notcurses version.
39API const char* notcurses_version(void);
40// Cannot be inline, as we want to get the versions of the actual Notcurses
41// library we loaded, not what we compile against.
42API void notcurses_version_components(int* major, int* minor, int* patch, int* tweak);
43
44struct notcurses; // Notcurses state for a given terminal, composed of ncplanes
45struct ncplane; // a drawable Notcurses surface, composed of cells
46struct ncvisual; // a visual bit of multimedia opened with LibAV|OIIO
47struct ncuplot; // uint64_t histogram
48struct ncdplot; // double histogram
49struct ncprogbar; // progress bar
50struct ncfdplane; // i/o wrapper to dump file descriptor to plane
51struct ncsubproc; // ncfdplane wrapper with subprocess management
52struct ncselector;// widget supporting selecting 1 from a list of options
53struct ncmultiselector; // widget supporting selecting 0..n from n options
54struct ncreader; // widget supporting free string input ala readline
55struct ncfadectx; // context for a palette fade operation
56struct nctablet; // grouped item within an ncreel
57struct ncreel; // hierarchical block-based data browser
58struct nctab; // grouped item within an nctabbed
59struct nctabbed; // widget with one tab visible at a time
60struct ncdirect; // direct mode context
61
62// we never blit full blocks, but instead spaces (more efficient) with the
63// background set to the desired foreground. these need be kept in the same
64// order as the blitters[] definition in lib/blit.c.
65typedef enum {
66 NCBLIT_DEFAULT, // let the ncvisual pick
67 NCBLIT_1x1, // space, compatible with ASCII
68 NCBLIT_2x1, // halves + 1x1 (space) ▄▀
69 NCBLIT_2x2, // quadrants + 2x1 ▗▐ ▖▀▟▌▙
70 NCBLIT_3x2, // sextants + 2x1 🬀🬁🬂🬃🬄🬅🬆🬇🬈🬉🬊🬋🬌🬍🬎🬏🬐🬑🬒🬓🬔🬕🬖🬗🬘🬙🬚🬛🬜🬝🬞
71 NCBLIT_4x2, // octants + 2x2 there are a great many octants
72 NCBLIT_BRAILLE, // 4 rows, 2 cols (braille) ⡀⡄⡆⡇⢀⣀⣄⣆⣇⢠⣠⣤⣦⣧⢰⣰⣴⣶⣷⢸⣸⣼⣾⣿
73 NCBLIT_PIXEL, // pixel graphics
74 // these blitters are suitable only for plots, not general media
75 NCBLIT_4x1, // four vertical levels █▆▄▂
76 NCBLIT_8x1, // eight vertical levels █▇▆▅▄▃▂▁
78
79// Alignment within a plane or terminal. Left/right-justified, or centered.
86
87#define NCALIGN_TOP NCALIGN_LEFT
88#define NCALIGN_BOTTOM NCALIGN_RIGHT
89
90// How to scale an ncvisual during rendering. NCSCALE_NONE will apply no
91// scaling. NCSCALE_SCALE scales a visual to the plane's size, maintaining
92// aspect ratio. NCSCALE_STRETCH stretches and scales the image in an attempt
93// to fill the entirety of the plane. NCSCALE_NONE_HIRES and
94// NCSCALE_SCALE_HIRES behave like their counterparts, but admit blitters
95// which don't preserve aspect ratio.
103
104// background cannot be highcontrast, only foreground
105#define NCALPHA_HIGHCONTRAST 0x30000000ull
106#define NCALPHA_TRANSPARENT 0x20000000ull
107#define NCALPHA_BLEND 0x10000000ull
108#define NCALPHA_OPAQUE 0x00000000ull
109
110// we support palette-indexed color up to 8 bits.
111#define NCPALETTESIZE 256
112
113// Does this glyph completely obscure the background? If so, there's no need
114// to emit a background when rasterizing, a small optimization. These are
115// also used to track regions into which we must not cellblit.
116#define NC_NOBACKGROUND_MASK 0x8700000000000000ull
117// if this bit is set, we are *not* using the default background color
118#define NC_BGDEFAULT_MASK 0x0000000040000000ull
119// extract these bits to get the background RGB value
120#define NC_BG_RGB_MASK 0x0000000000ffffffull
121// if this bit *and* NC_BGDEFAULT_MASK are set, we're using a
122// palette-indexed background color
123#define NC_BG_PALETTE 0x0000000008000000ull
124// extract these bits to get the background alpha mask
125#define NC_BG_ALPHA_MASK 0x30000000ull
126
127// initialize a 32-bit channel pair with specified RGB
128#define NCCHANNEL_INITIALIZER(r, g, b) \
129 (((uint32_t)(r) << 16u) + ((uint32_t)(g) << 8u) + (b) + NC_BGDEFAULT_MASK)
130
131// initialize a 64-bit channel pair with specified RGB fg/bg
132#define NCCHANNELS_INITIALIZER(fr, fg, fb, br, bg, bb) \
133 ((NCCHANNEL_INITIALIZER((fr), (fg), (fb)) << 32ull) + \
134 (NCCHANNEL_INITIALIZER((br), (bg), (bb))))
135
136// These lowest-level functions directly manipulate a channel. Users will
137// typically manipulate ncplanes' and nccells' channels through their APIs,
138// rather than calling these explicitly.
139
140// Extract the 2-bit alpha component from a 32-bit channel. It is not
141// shifted down, and can be directly compared to NCALPHA_* values.
142static inline uint32_t
143ncchannel_alpha(uint32_t channel){
144 return channel & NC_BG_ALPHA_MASK;
145}
146
147// Set the 2-bit alpha component of the 32-bit channel. Background channels
148// must not be set to NCALPHA_HIGHCONTRAST. It is an error if alpha contains
149// any bits other than NCALPHA_*.
150static inline int
151ncchannel_set_alpha(uint32_t* channel, unsigned alpha){
152 if(alpha & ~NC_BG_ALPHA_MASK){
153 return -1;
154 }
155 *channel = (uint32_t)alpha | (*channel & (uint32_t)~NC_BG_ALPHA_MASK);
156 if(alpha != NCALPHA_OPAQUE){
157 *channel |= NC_BGDEFAULT_MASK;
158 }
159 return 0;
160}
161
162// Is this channel using the "default color" rather than RGB/palette-indexed?
163static inline bool
164ncchannel_default_p(uint32_t channel){
165 return !(channel & NC_BGDEFAULT_MASK);
166}
167
168// Mark the channel as using its default color. Alpha is set opaque.
169static inline uint32_t
170ncchannel_set_default(uint32_t* channel){
171 *channel &= (uint32_t)~NC_BGDEFAULT_MASK; // turn off not-default bit
172 ncchannel_set_alpha(channel, NCALPHA_OPAQUE);
173 return *channel;
174}
175
176// Is this channel using palette-indexed color?
177static inline bool
178ncchannel_palindex_p(uint32_t channel){
179 return !ncchannel_default_p(channel) && (channel & NC_BG_PALETTE);
180}
181
182// Extract the palette index from a channel. Only valid if
183// ncchannel_palindex_p() would return true for the channel.
184static inline unsigned
185ncchannel_palindex(uint32_t channel){
186 return channel & 0xff;
187}
188
189// Mark the channel as using the specified palette color. It is an error if
190// the index is greater than NCPALETTESIZE. Alpha is set opaque.
191static inline int
192ncchannel_set_palindex(uint32_t* channel, unsigned idx){
193 if(idx >= NCPALETTESIZE){
194 return -1;
195 }
196 ncchannel_set_alpha(channel, NCALPHA_OPAQUE);
197 *channel &= 0xff000000ull;
198 *channel |= NC_BGDEFAULT_MASK | NC_BG_PALETTE | idx;
199 return 0;
200}
201
202// Is this channel using RGB color?
203static inline bool
204ncchannel_rgb_p(uint32_t channel){
205 return !(ncchannel_default_p(channel) || ncchannel_palindex_p(channel));
206}
207
208// Extract the 8-bit red component from a 32-bit channel. Only valid if
209// ncchannel_rgb_p() would return true for the channel.
210static inline unsigned
211ncchannel_r(uint32_t channel){
212 return (channel & 0xff0000u) >> 16u;
213}
214
215// Extract the 8-bit green component from a 32-bit channel. Only valid if
216// ncchannel_rgb_p() would return true for the channel.
217static inline unsigned
218ncchannel_g(uint32_t channel){
219 return (channel & 0x00ff00u) >> 8u;
220}
221
222// Extract the 8-bit blue component from a 32-bit channel. Only valid if
223// ncchannel_rgb_p() would return true for the channel.
224static inline unsigned
225ncchannel_b(uint32_t channel){
226 return (channel & 0x0000ffu);
227}
228
229// Extract the 24-bit RGB value from a 32-bit channel.
230// Only valid if ncchannel_rgb_p() would return true for the channel.
231static inline uint32_t
232ncchannel_rgb(uint32_t channel){
233 return channel & NC_BG_RGB_MASK;
234}
235
236// Extract the three 8-bit R/G/B components from a 32-bit channel.
237// Only valid if ncchannel_rgb_p() would return true for the channel.
238static inline uint32_t
239ncchannel_rgb8(uint32_t channel, unsigned* RESTRICT r, unsigned* RESTRICT g,
240 unsigned* RESTRICT b){
241 *r = ncchannel_r(channel);
242 *g = ncchannel_g(channel);
243 *b = ncchannel_b(channel);
244 return channel;
245}
246
247// Set the three 8-bit components of a 32-bit channel, and mark it as not using
248// the default color. Retain the other bits unchanged. Any value greater than
249// 255 will result in a return of -1 and no change to the channel.
250static inline int
251ncchannel_set_rgb8(uint32_t* channel, unsigned r, unsigned g, unsigned b){
252 if(r >= 256 || g >= 256 || b >= 256){
253 return -1;
254 }
255 uint32_t c = (r << 16u) | (g << 8u) | b;
256 // clear the existing rgb bits, clear the palette index indicator, set
257 // the not-default bit, and or in the new rgb.
258 *channel = (uint32_t)((*channel & ~(NC_BG_RGB_MASK | NC_BG_PALETTE)) | NC_BGDEFAULT_MASK | c);
259 return 0;
260}
261
262// Same, but provide an assembled, packed 24 bits of rgb.
263static inline int
264ncchannel_set(uint32_t* channel, uint32_t rgb){
265 if(rgb > 0xffffffu){
266 return -1;
267 }
268 *channel = (uint32_t)((*channel & ~(NC_BG_RGB_MASK | NC_BG_PALETTE)) | NC_BGDEFAULT_MASK | rgb);
269 return 0;
270}
271
272// Set the three 8-bit components of a 32-bit channel, and mark it as not using
273// the default color. Retain the other bits unchanged. r, g, and b will be
274// clipped to the range [0..255].
275static inline void
276ncchannel_set_rgb8_clipped(uint32_t* channel, int r, int g, int b){
277 if(r >= 256){
278 r = 255;
279 }
280 if(g >= 256){
281 g = 255;
282 }
283 if(b >= 256){
284 b = 255;
285 }
286 if(r <= -1){
287 r = 0;
288 }
289 if(g <= -1){
290 g = 0;
291 }
292 if(b <= -1){
293 b = 0;
294 }
295 uint32_t c = (uint32_t)((r << 16u) | (g << 8u) | b);
296 *channel = (uint32_t)((*channel & ~(NC_BG_RGB_MASK | NC_BG_PALETTE)) | NC_BGDEFAULT_MASK | c);
297}
298
299// Extract the background alpha and coloring bits from a 64-bit channel
300// pair as a single 32-bit value.
301static inline uint32_t
302ncchannels_bchannel(uint64_t channels){
305}
306
307// Extract the foreground alpha and coloring bits from a 64-bit channel
308// pair as a single 32-bit value.
309static inline uint32_t
310ncchannels_fchannel(uint64_t channels){
311 return ncchannels_bchannel(channels >> 32u);
312}
313
314// Extract the background alpha and coloring bits from a 64-bit channel pair.
315static inline uint64_t
316ncchannels_channels(uint64_t channels){
317 return ncchannels_bchannel(channels) |
318 ((uint64_t)ncchannels_fchannel(channels) << 32u);
319}
320
321static inline bool
322ncchannels_bg_rgb_p(uint64_t channels){
323 return ncchannel_rgb_p(ncchannels_bchannel(channels));
324}
325
326static inline bool
327ncchannels_fg_rgb_p(uint64_t channels){
328 return ncchannel_rgb_p(ncchannels_fchannel(channels));
329}
330
331// Extract 2 bits of background alpha from 'channels', shifted to LSBs.
332static inline unsigned
333ncchannels_bg_alpha(uint64_t channels){
334 return ncchannel_alpha(ncchannels_bchannel(channels));
335}
336
337// Set the background alpha and coloring bits of the 64-bit channel pair
338// from a single 32-bit value.
339static inline uint64_t
340ncchannels_set_bchannel(uint64_t* channels, uint32_t channel){
341 // drop the background color and alpha bit
342 *channels &= ((0xffffffffllu << 32u) | NC_NOBACKGROUND_MASK);
343 *channels |= (uint32_t)(channel & ~NC_NOBACKGROUND_MASK);
344 return *channels;
345}
346
347// Set the foreground alpha and coloring bits of the 64-bit channel pair
348// from a single 32-bit value.
349static inline uint64_t
350ncchannels_set_fchannel(uint64_t* channels, uint32_t channel){
351 // drop the foreground color and alpha bit
352 *channels &= (0xffffffffllu | ((uint64_t)NC_NOBACKGROUND_MASK << 32u));
353 *channels |= (uint64_t)(channel & ~NC_NOBACKGROUND_MASK) << 32u;
354 return *channels;
355}
356
357// Set the alpha and coloring bits of a channel pair from another channel pair.
358static inline uint64_t
359ncchannels_set_channels(uint64_t* dst, uint64_t channels){
360 ncchannels_set_bchannel(dst, channels & 0xffffffffull);
361 ncchannels_set_fchannel(dst, (uint32_t)((channels >> 32u) & 0xffffffffull));
362 return *dst;
363}
364
365// Set the 2-bit alpha component of the background channel.
366static inline int
367ncchannels_set_bg_alpha(uint64_t* channels, unsigned alpha){
368 if(alpha == NCALPHA_HIGHCONTRAST){ // forbidden for background alpha
369 return -1;
370 }
371 uint32_t channel = ncchannels_bchannel(*channels);
372 if(ncchannel_set_alpha(&channel, alpha) < 0){
373 return -1;
374 }
375 ncchannels_set_bchannel(channels, channel);
376 return 0;
377}
378
379// Extract 2 bits of foreground alpha from 'channels', shifted to LSBs.
380static inline unsigned
381ncchannels_fg_alpha(uint64_t channels){
382 return ncchannel_alpha(ncchannels_fchannel(channels));
383}
384
385// Set the 2-bit alpha component of the foreground channel.
386static inline int
387ncchannels_set_fg_alpha(uint64_t* channels, unsigned alpha){
388 uint32_t channel = ncchannels_fchannel(*channels);
389 if(ncchannel_set_alpha(&channel, alpha) < 0){
390 return -1;
391 }
392 *channels = ((uint64_t)channel << 32llu) | (*channels & 0xffffffffllu);
393 return 0;
394}
395
396// Returns the channels with the fore- and background's color information
397// swapped, but without touching housekeeping bits. Alpha is retained unless
398// it would lead to an illegal state: HIGHCONTRAST, TRANSPARENT, and BLEND
399// are taken to OPAQUE unless the new value is RGB.
400static inline uint64_t
401ncchannels_reverse(uint64_t channels){
402 const uint64_t raw = ((uint64_t)ncchannels_bchannel(channels) << 32u) +
403 ncchannels_fchannel(channels);
404 const uint64_t statemask = ((NC_NOBACKGROUND_MASK | NC_BG_ALPHA_MASK) << 32u) |
406 uint64_t ret = raw & ~statemask;
407 ret |= channels & statemask;
408 if(ncchannels_bg_alpha(ret) != NCALPHA_OPAQUE){
409 if(!ncchannels_bg_rgb_p(ret)){
410 ncchannels_set_bg_alpha(&ret, NCALPHA_OPAQUE);
411 }
412 }
413 if(ncchannels_fg_alpha(ret) != NCALPHA_OPAQUE){
414 if(!ncchannels_fg_rgb_p(ret)){
415 ncchannels_set_fg_alpha(&ret, NCALPHA_OPAQUE);
416 }
417 }
418 return ret;
419}
420
421// Creates a new channel pair using 'fchan' as the foreground channel
422// and 'bchan' as the background channel.
423static inline uint64_t
424ncchannels_combine(uint32_t fchan, uint32_t bchan){
425 uint64_t channels = 0;
426 ncchannels_set_fchannel(&channels, fchan);
427 ncchannels_set_bchannel(&channels, bchan);
428 return channels;
429}
430
431static inline unsigned
432ncchannels_fg_palindex(uint64_t channels){
433 return ncchannel_palindex(ncchannels_fchannel(channels));
434}
435
436static inline unsigned
437ncchannels_bg_palindex(uint64_t channels){
438 return ncchannel_palindex(ncchannels_bchannel(channels));
439}
440
441// Extract 24 bits of foreground RGB from 'channels', shifted to LSBs.
442static inline uint32_t
443ncchannels_fg_rgb(uint64_t channels){
444 return ncchannel_rgb(ncchannels_fchannel(channels));
445}
446
447// Extract 24 bits of background RGB from 'channels', shifted to LSBs.
448static inline uint32_t
449ncchannels_bg_rgb(uint64_t channels){
450 return ncchannel_rgb(ncchannels_bchannel(channels));
451}
452
453// Extract 24 bits of foreground RGB from 'channels', split into subchannels.
454static inline uint32_t
455ncchannels_fg_rgb8(uint64_t channels, unsigned* r, unsigned* g, unsigned* b){
456 return ncchannel_rgb8(ncchannels_fchannel(channels), r, g, b);
457}
458
459// Extract 24 bits of background RGB from 'channels', split into subchannels.
460static inline uint32_t
461ncchannels_bg_rgb8(uint64_t channels, unsigned* r, unsigned* g, unsigned* b){
462 return ncchannel_rgb8(ncchannels_bchannel(channels), r, g, b);
463}
464
465// Set the r, g, and b channels for the foreground component of this 64-bit
466// 'channels' variable, and mark it as not using the default color.
467static inline int
468ncchannels_set_fg_rgb8(uint64_t* channels, unsigned r, unsigned g, unsigned b){
469 uint32_t channel = ncchannels_fchannel(*channels);
470 if(ncchannel_set_rgb8(&channel, r, g, b) < 0){
471 return -1;
472 }
473 *channels = ((uint64_t)channel << 32llu) | (*channels & 0xffffffffllu);
474 return 0;
475}
476
477// Same, but clips to [0..255].
478static inline void
479ncchannels_set_fg_rgb8_clipped(uint64_t* channels, int r, int g, int b){
480 uint32_t channel = ncchannels_fchannel(*channels);
481 ncchannel_set_rgb8_clipped(&channel, r, g, b);
482 *channels = ((uint64_t)channel << 32llu) | (*channels & 0xffffffffllu);
483}
484
485static inline int
486ncchannels_set_fg_palindex(uint64_t* channels, unsigned idx){
487 uint32_t channel = ncchannels_fchannel(*channels);
488 if(ncchannel_set_palindex(&channel, idx) < 0){
489 return -1;
490 }
491 *channels = ((uint64_t)channel << 32llu) | (*channels & 0xffffffffllu);
492 return 0;
493}
494
495// Same, but set an assembled 24 bit channel at once.
496static inline int
497ncchannels_set_fg_rgb(uint64_t* channels, unsigned rgb){
498 uint32_t channel = ncchannels_fchannel(*channels);
499 if(ncchannel_set(&channel, rgb) < 0){
500 return -1;
501 }
502 *channels = ((uint64_t)channel << 32llu) | (*channels & 0xffffffffllu);
503 return 0;
504}
505
506// Set the r, g, and b channels for the background component of this 64-bit
507// 'channels' variable, and mark it as not using the default color.
508static inline int
509ncchannels_set_bg_rgb8(uint64_t* channels, unsigned r, unsigned g, unsigned b){
510 uint32_t channel = ncchannels_bchannel(*channels);
511 if(ncchannel_set_rgb8(&channel, r, g, b) < 0){
512 return -1;
513 }
514 ncchannels_set_bchannel(channels, channel);
515 return 0;
516}
517
518// Same, but clips to [0..255].
519static inline void
520ncchannels_set_bg_rgb8_clipped(uint64_t* channels, int r, int g, int b){
521 uint32_t channel = ncchannels_bchannel(*channels);
522 ncchannel_set_rgb8_clipped(&channel, r, g, b);
523 ncchannels_set_bchannel(channels, channel);
524}
525
526// Set the cell's background palette index, set the background palette index
527// bit, set it background-opaque, and clear the background default color bit.
528static inline int
529ncchannels_set_bg_palindex(uint64_t* channels, unsigned idx){
530 uint32_t channel = ncchannels_bchannel(*channels);
531 if(ncchannel_set_palindex(&channel, idx) < 0){
532 return -1;
533 }
534 ncchannels_set_bchannel(channels, channel);
535 return 0;
536}
537
538// Same, but set an assembled 24 bit channel at once.
539static inline int
540ncchannels_set_bg_rgb(uint64_t* channels, unsigned rgb){
541 uint32_t channel = ncchannels_bchannel(*channels);
542 if(ncchannel_set(&channel, rgb) < 0){
543 return -1;
544 }
545 ncchannels_set_bchannel(channels, channel);
546 return 0;
547}
548
549// Is the foreground using the "default foreground color"?
550static inline bool
551ncchannels_fg_default_p(uint64_t channels){
552 return ncchannel_default_p(ncchannels_fchannel(channels));
553}
554
555// Is the foreground using indexed palette color?
556static inline bool
557ncchannels_fg_palindex_p(uint64_t channels){
558 return ncchannel_palindex_p(ncchannels_fchannel(channels));
559}
560
561// Is the background using the "default background color"? The "default
562// background color" must generally be used to take advantage of
563// terminal-effected transparency.
564static inline bool
565ncchannels_bg_default_p(uint64_t channels){
566 return ncchannel_default_p(ncchannels_bchannel(channels));
567}
568
569// Is the background using indexed palette color?
570static inline bool
571ncchannels_bg_palindex_p(uint64_t channels){
572 return ncchannel_palindex_p(ncchannels_bchannel(channels));
573}
574
575// Mark the foreground channel as using its default color.
576static inline uint64_t
577ncchannels_set_fg_default(uint64_t* channels){
578 uint32_t channel = ncchannels_fchannel(*channels);
579 ncchannel_set_default(&channel);
580 ncchannels_set_fchannel(channels, channel);
581 return *channels;
582}
583
584// Mark the background channel as using its default color.
585static inline uint64_t
586ncchannels_set_bg_default(uint64_t* channels){
587 uint32_t channel = ncchannels_bchannel(*channels);
588 ncchannel_set_default(&channel);
589 ncchannels_set_bchannel(channels, channel);
590 return *channels;
591}
592
593// 0x0--0x10ffff can be UTF-8-encoded with only 4 bytes
594#define WCHAR_MAX_UTF8BYTES 4
595
596// Returns the number of columns occupied by the longest valid prefix of a
597// multibyte (UTF-8) string. If an invalid character is encountered, -1 will be
598// returned, and the number of valid bytes and columns will be written into
599// *|validbytes| and *|validwidth| (assuming them non-NULL). If the entire
600// string is valid, *|validbytes| and *|validwidth| reflect the entire string.
601API int ncstrwidth(const char* egcs, int* validbytes, int* validwidth)
602 __attribute__ ((nonnull (1)));
603
604// input functions like notcurses_get() return ucs32-encoded uint32_t. convert
605// a series of uint32_t to utf8. result must be at least 4 bytes per input
606// uint32_t (6 bytes per uint32_t will future-proof against Unicode expansion).
607// the number of bytes used is returned, or -1 if passed illegal ucs32, or too
608// small of a buffer.
609API int notcurses_ucs32_to_utf8(const uint32_t* ucs32, unsigned ucs32count,
610 unsigned char* resultbuf, size_t buflen)
611 __attribute__ ((nonnull (1, 3)));
612
613// An nccell corresponds to a single character cell on some plane, which can be
614// occupied by a single grapheme cluster (some root spacing glyph, along with
615// possible combining characters, which might span multiple columns). At any
616// cell, we can have a theoretically arbitrarily long UTF-8 EGC, a foreground
617// color, a background color, and an attribute set. Valid grapheme cluster
618// contents include:
619//
620// * A NUL terminator,
621// * A single control character, followed by a NUL terminator,
622// * At most one spacing character, followed by zero or more nonspacing
623// characters, followed by a NUL terminator.
624//
625// Multi-column characters can only have a single style/color throughout.
626// Existence is suffering, and thus wcwidth() is not reliable. It's just
627// quoting whether or not the EGC contains a "Wide Asian" double-width
628// character. This is set for some things, like most emoji, and not set for
629// other things, like cuneiform. True display width is a *function of the
630// font and terminal*. Among the longest Unicode codepoints is
631//
632// U+FDFD ARABIC LIGATURE BISMILLAH AR-RAHMAN AR-RAHEEM ﷽
633//
634// wcwidth() rather optimistically claims this most exalted glyph to occupy
635// a single column. BiDi text is too complicated for me to even get into here.
636// Be assured there are no easy answers; ours is indeed a disturbing Universe.
637//
638// Each nccell occupies 16 static bytes (128 bits). The surface is thus ~1.6MB
639// for a (pretty large) 500x200 terminal. At 80x43, it's less than 64KB.
640// Dynamic requirements (the egcpool) can add up to 16MB to an ncplane, but
641// such large pools are unlikely in common use.
642//
643// We implement some small alpha compositing. Foreground and background both
644// have two bits of inverted alpha. The actual grapheme written to a cell is
645// the topmost non-zero grapheme. If its alpha is 00, its foreground color is
646// used unchanged. If its alpha is 10, its foreground color is derived entirely
647// from cells underneath it. Otherwise, the result will be a composite.
648// Likewise for the background. If the bottom of a coordinate's zbuffer is
649// reached with a cumulative alpha of zero, the default is used. In this way,
650// a terminal configured with transparent background can be supported through
651// multiple occluding ncplanes. A foreground alpha of 11 requests high-contrast
652// text (relative to the computed background). A background alpha of 11 is
653// currently forbidden.
654//
655// Default color takes precedence over palette or RGB, and cannot be used with
656// transparency. Indexed palette takes precedence over RGB. It cannot
657// meaningfully set transparency, but it can be mixed into a cascading color.
658// RGB is used if neither default terminal colors nor palette indexing are in
659// play, and fully supports all transparency options.
660//
661// This structure is exposed only so that most functions can be inlined. Do not
662// directly modify or access the fields of this structure; use the API.
663typedef struct nccell {
664 // These 32 bits, together with the associated plane's associated egcpool,
665 // completely define this cell's EGC. Unless the EGC requires more than four
666 // bytes to encode as UTF-8, it will be inlined here. If more than four bytes
667 // are required, it will be spilled into the egcpool. In either case, there's
668 // a NUL-terminated string available without copying, because (1) the egcpool
669 // is all NUL-terminated sequences and (2) the fifth byte of this struct (the
670 // gcluster_backstop field, see below) is guaranteed to be zero, as are any
671 // unused bytes in gcluster.
672 //
673 // The gcluster + gcluster_backstop thus form a valid C string of between 0
674 // and 4 non-NUL bytes. Interpreting them in this fashion requires that
675 // gcluster be stored as a little-endian number (strings have no byte order).
676 // This gives rise to three simple rules:
677 //
678 // * when storing to gcluster from a numeric, always use htole()
679 // * when loading from gcluster for numeric use, always use htole()
680 // * when referencing gcluster as a string, always use a pointer cast
681 //
682 // Uses of gcluster ought thus always have exactly one htole() or pointer
683 // cast associated with them, and we otherwise always work as host-endian.
684 //
685 // A spilled EGC is indicated by the value 0x01XXXXXX. This cannot alias a
686 // true supra-ASCII EGC, because UTF-8 only encodes bytes <= 0x80 when they
687 // are single-byte ASCII-derived values. The XXXXXX is interpreted as a 24-bit
688 // index into the egcpool. These pools may thus be up to 16MB.
689 //
690 // The cost of this scheme is that the character 0x01 (SOH) cannot be encoded
691 // in a nccell, which we want anyway. It must not be allowed through the API,
692 // or havoc will result.
693 uint32_t gcluster; // 4B → 4B little endian EGC
694 uint8_t gcluster_backstop; // 1B → 5B (8 bits of zero)
695 // we store the column width in this field. for a multicolumn EGC of N
696 // columns, there will be N nccells, and each has a width of N...for now.
697 // eventually, such an EGC will set more than one subsequent cell to
698 // WIDE_RIGHT, and this won't be necessary. it can then be used as a
699 // bytecount. see #1203. FIXME iff width >= 2, the cell is part of a
700 // multicolumn glyph. whether a cell is the left or right side of the glyph
701 // can be determined by checking whether ->gcluster is zero.
702 uint8_t width; // 1B → 6B (8 bits of EGC column width)
703 uint16_t stylemask; // 2B → 8B (16 bits of NCSTYLE_* attributes)
704 // (channels & 0x8000000000000000ull): blitted to upper-left quadrant
705 // (channels & 0x4000000000000000ull): foreground is *not* "default color"
706 // (channels & 0x3000000000000000ull): foreground alpha (2 bits)
707 // (channels & 0x0800000000000000ull): foreground uses palette index
708 // (channels & 0x0400000000000000ull): blitted to upper-right quadrant
709 // (channels & 0x0200000000000000ull): blitted to lower-left quadrant
710 // (channels & 0x0100000000000000ull): blitted to lower-right quadrant
711 // (channels & 0x00ffffff00000000ull): foreground in 3x8 RGB (rrggbb) / pindex
712 // (channels & 0x0000000080000000ull): reserved, must be 0
713 // (channels & 0x0000000040000000ull): background is *not* "default color"
714 // (channels & 0x0000000030000000ull): background alpha (2 bits)
715 // (channels & 0x0000000008000000ull): background uses palette index
716 // (channels & 0x0000000007000000ull): reserved, must be 0
717 // (channels & 0x0000000000ffffffull): background in 3x8 RGB (rrggbb) / pindex
718 // At render time, these 24-bit values are quantized down to terminal
719 // capabilities, if necessary. There's a clear path to 10-bit support should
720 // we one day need it, but keep things cagey for now. "default color" is
721 // best explained by color(3NCURSES). ours is the same concept. until the
722 // "not default color" bit is set, any color you load will be ignored.
723 uint64_t channels; // + 8B == 16B
725
726// do *not* load invalid EGCs using these macros! there is no way for us to
727// protect against such misuse here. problems *will* ensue. similarly, do not
728// set channel flags other than colors/alpha. we assign non-printing glyphs
729// a width of 1 to match utf8_egc_len()'s behavior for whitespace/NUL.
730// FIXME can we enforce this with static_assert?
731#define NCCELL_INITIALIZER(c, s, chan) { .gcluster = (htole(c)), .gcluster_backstop = 0,\
732 .width = (uint8_t)((wcwidth(c) < 0 || !c) ? 1 : wcwidth(c)), .stylemask = (s), .channels = (chan), }
733// python fails on #define CELL_CHAR_INITIALIZER(c) CELL_INITIALIZER(c, 0, 0)
734#define NCCELL_CHAR_INITIALIZER(c) { .gcluster = (htole(c)), .gcluster_backstop = 0,\
735 .width = (uint8_t)((wcwidth(c) < 0 || !c) ? 1 : wcwidth(c)), .stylemask = 0, .channels = 0, }
736// python fails on #define CELL_TRIVIAL_INITIALIZER CELL_CHAR_INITIALIZER(0)
737#define NCCELL_TRIVIAL_INITIALIZER { .gcluster = 0, .gcluster_backstop = 0,\
738 .width = 1, .stylemask = 0, .channels = 0, }
739
740static inline void
741nccell_init(nccell* c){
742 memset(c, 0, sizeof(*c));
743}
744
745// Breaks the UTF-8 string in 'gcluster' down, setting up the nccell 'c'.
746// Returns the number of bytes copied out of 'gcluster', or -1 on failure. The
747// styling of the cell is left untouched, but any resources are released.
748API int nccell_load(struct ncplane* n, nccell* c, const char* gcluster);
749
750// nccell_load(), plus blast the styling with 'attr' and 'channels'.
751static inline int
752nccell_prime(struct ncplane* n, nccell* c, const char* gcluster,
753 uint16_t stylemask, uint64_t channels){
754 c->stylemask = stylemask;
755 c->channels = channels;
756 int ret = nccell_load(n, c, gcluster);
757 return ret;
758}
759
760// Duplicate 'c' into 'targ'; both must be/will be bound to 'n'. Returns -1 on
761// failure, and 0 on success.
762API int nccell_duplicate(struct ncplane* n, nccell* targ, const nccell* c);
763
764// Release resources held by the nccell 'c'.
765API void nccell_release(struct ncplane* n, nccell* c);
766
767// if you want reverse video, try ncchannels_reverse(). if you want blink, try
768// ncplane_pulse(). if you want protection, put things on a different plane.
769#define NCSTYLE_MASK 0xffffu
770#define NCSTYLE_ITALIC 0x0010u
771#define NCSTYLE_UNDERLINE 0x0008u
772#define NCSTYLE_UNDERCURL 0x0004u
773#define NCSTYLE_BOLD 0x0002u
774#define NCSTYLE_STRUCK 0x0001u
775#define NCSTYLE_NONE 0
776
777// Set the specified style bits for the nccell 'c', whether they're actively
778// supported or not. Only the lower 16 bits are meaningful.
779static inline void
780nccell_set_styles(nccell* c, unsigned stylebits){
781 c->stylemask = stylebits & NCSTYLE_MASK;
782}
783
784// Extract the style bits from the nccell.
785static inline uint16_t
786nccell_styles(const nccell* c){
787 return c->stylemask;
788}
789
790// Add the specified styles (in the LSBs) to the nccell's existing spec,
791// whether they're actively supported or not.
792static inline void
793nccell_on_styles(nccell* c, unsigned stylebits){
794 c->stylemask |= (uint16_t)(stylebits & NCSTYLE_MASK);
795}
796
797// Remove the specified styles (in the LSBs) from the nccell's existing spec.
798static inline void
799nccell_off_styles(nccell* c, unsigned stylebits){
800 c->stylemask &= (uint16_t)~(stylebits & NCSTYLE_MASK);
801}
802
803// Use the default color for the foreground.
804static inline void
805nccell_set_fg_default(nccell* c){
806 ncchannels_set_fg_default(&c->channels);
807}
808
809// Use the default color for the background.
810static inline void
811nccell_set_bg_default(nccell* c){
812 ncchannels_set_bg_default(&c->channels);
813}
814
815static inline int
816nccell_set_fg_alpha(nccell* c, unsigned alpha){
817 return ncchannels_set_fg_alpha(&c->channels, alpha);
818}
819
820static inline int
821nccell_set_bg_alpha(nccell* c, unsigned alpha){
822 return ncchannels_set_bg_alpha(&c->channels, alpha);
823}
824
825static inline uint64_t
826nccell_set_bchannel(nccell* c, uint32_t channel){
827 return ncchannels_set_bchannel(&c->channels, channel);
828}
829
830static inline uint64_t
831nccell_set_fchannel(nccell* c, uint32_t channel){
832 return ncchannels_set_fchannel(&c->channels, channel);
833}
834
835static inline uint64_t
836nccell_set_channels(nccell* c, uint64_t channels){
837 return ncchannels_set_channels(&c->channels, channels);
838}
839
840// Is the cell part of a multicolumn element?
841static inline bool
842nccell_double_wide_p(const nccell* c){
843 return (c->width >= 2);
844}
845
846// Is this the right half of a wide character?
847static inline bool
848nccell_wide_right_p(const nccell* c){
849 return nccell_double_wide_p(c) && c->gcluster == 0;
850}
851
852// Is this the left half of a wide character?
853static inline bool
854nccell_wide_left_p(const nccell* c){
855 return nccell_double_wide_p(c) && c->gcluster;
856}
857
858// return a pointer to the NUL-terminated EGC referenced by 'c'. this pointer
859// can be invalidated by any further operation on the plane 'n', so...watch out!
860API __attribute__ ((returns_nonnull)) const char*
862
863static inline uint64_t
864nccell_channels(const nccell* c){
865 return ncchannels_channels(c->channels);
866}
867
868// Extract the background alpha and coloring bits from a cell's channels
869// as a single 32-bit value.
870static inline uint32_t
871nccell_bchannel(const nccell* cl){
872 return ncchannels_bchannel(cl->channels);
873}
874
875// Extract the foreground alpha and coloring bits from a cell's channels
876// as a single 32-bit value.
877static inline uint32_t
878nccell_fchannel(const nccell* cl){
879 return ncchannels_fchannel(cl->channels);
880}
881
882// return the number of columns occupied by 'c'. see ncstrwidth() for an
883// equivalent for multiple EGCs.
884static inline unsigned
885nccell_cols(const nccell* c){
886 return c->width ? c->width : 1;
887}
888
889// copy the UTF8-encoded EGC out of the nccell. the result is not tied to any
890// ncplane, and persists across erases / destruction.
891ALLOC static inline char*
892nccell_strdup(const struct ncplane* n, const nccell* c){
893 return strdup(nccell_extended_gcluster(n, c));
894}
895
896// Extract the three elements of a nccell.
897static inline char*
898nccell_extract(const struct ncplane* n, const nccell* c,
899 uint16_t* stylemask, uint64_t* channels){
900 if(stylemask){
901 *stylemask = c->stylemask;
902 }
903 if(channels){
904 *channels = c->channels;
905 }
906 return nccell_strdup(n, c);
907}
908
909// Returns true if the two nccells are distinct EGCs, attributes, or channels.
910// The actual egcpool index needn't be the same--indeed, the planes needn't even
911// be the same. Only the expanded EGC must be equal. The EGC must be bit-equal;
912// it would probably be better to test whether they're Unicode-equal FIXME.
913// probably needs be fixed up for sprixels FIXME.
914static inline bool
915nccellcmp(const struct ncplane* n1, const nccell* RESTRICT c1,
916 const struct ncplane* n2, const nccell* RESTRICT c2){
917 if(c1->stylemask != c2->stylemask){
918 return true;
919 }
920 if(c1->channels != c2->channels){
921 return true;
922 }
923 return strcmp(nccell_extended_gcluster(n1, c1), nccell_extended_gcluster(n2, c2));
924}
925
926// Load a 7-bit char 'ch' into the nccell 'c'. Returns the number of bytes
927// used, or -1 on error.
928static inline int
929nccell_load_char(struct ncplane* n, nccell* c, char ch){
930 char gcluster[2];
931 gcluster[0] = ch;
932 gcluster[1] = '\0';
933 return nccell_load(n, c, gcluster);
934}
935
936// Load a UTF-8 encoded EGC of up to 4 bytes into the nccell 'c'. Returns the
937// number of bytes used, or -1 on error.
938static inline int
939nccell_load_egc32(struct ncplane* n, nccell* c, uint32_t egc){
940 char gcluster[sizeof(egc) + 1];
941 egc = htole(egc);
942 memcpy(gcluster, &egc, sizeof(egc));
943 gcluster[4] = '\0';
944 return nccell_load(n, c, gcluster);
945}
946
947// Load a UCS-32 codepoint into the nccell 'c'. Returns the number of bytes
948// used, or -1 on error.
949static inline int
950nccell_load_ucs32(struct ncplane* n, nccell* c, uint32_t u){
951 unsigned char utf8[WCHAR_MAX_UTF8BYTES];
952 if(notcurses_ucs32_to_utf8(&u, 1, utf8, sizeof(utf8)) < 0){
953 return -1;
954 }
955 uint32_t utf8asegc;
956 _Static_assert(WCHAR_MAX_UTF8BYTES == sizeof(utf8asegc),
957 "WCHAR_MAX_UTF8BYTES didn't equal sizeof(uint32_t)");
958 memcpy(&utf8asegc, utf8, sizeof(utf8));
959 return nccell_load_egc32(n, c, utf8asegc);
960}
961
962// These log levels consciously map cleanly to those of libav; Notcurses itself
963// does not use this full granularity. The log level does not affect the opening
964// and closing banners, which can be disabled via the notcurses_option struct's
965// 'suppress_banner'. Note that if stderr is connected to the same terminal on
966// which we're rendering, any kind of logging will disrupt the output (which is
967// undesirable). The "default" zero value is NCLOGLEVEL_PANIC.
968typedef enum {
969 NCLOGLEVEL_SILENT = -1,// default. print nothing once fullscreen service begins
970 NCLOGLEVEL_PANIC = 0, // print diagnostics related to catastrophic failure
971 NCLOGLEVEL_FATAL = 1, // we're hanging around, but we've had a horrible fault
972 NCLOGLEVEL_ERROR = 2, // we can't keep doing this, but we can do other things
973 NCLOGLEVEL_WARNING = 3,// you probably don't want what's happening to happen
974 NCLOGLEVEL_INFO = 4, // "standard information"
975 NCLOGLEVEL_VERBOSE = 5,// "detailed information"
976 NCLOGLEVEL_DEBUG = 6, // this is honestly a bit much
977 NCLOGLEVEL_TRACE = 7, // there's probably a better way to do what you want
979
980// Bits for notcurses_options->flags.
981
982// notcurses_init() will call setlocale() to inspect the current locale. If
983// that locale is "C" or "POSIX", it will call setlocale(LC_ALL, "") to set
984// the locale according to the LANG environment variable. Ideally, this will
985// result in UTF8 being enabled, even if the client app didn't call
986// setlocale() itself. Unless you're certain that you're invoking setlocale()
987// prior to notcurses_init(), you should not set this bit. Even if you are
988// invoking setlocale(), this behavior shouldn't be an issue unless you're
989// doing something weird (setting a locale not based on LANG).
990#define NCOPTION_INHIBIT_SETLOCALE 0x0001ull
991
992// We typically try to clear any preexisting bitmaps. If we ought *not* try
993// to do this, pass NCOPTION_NO_CLEAR_BITMAPS. Note that they might still
994// get cleared even if this is set, and they might not get cleared even if
995// this is not set. It's a tough world out there.
996#define NCOPTION_NO_CLEAR_BITMAPS 0x0002ull
997
998// We typically install a signal handler for SIGWINCH that generates a resize
999// event in the notcurses_get() queue. Set to inhibit this handler.
1000#define NCOPTION_NO_WINCH_SIGHANDLER 0x0004ull
1001
1002// We typically install a signal handler for SIG{INT, ILL, SEGV, ABRT, TERM,
1003// QUIT} that restores the screen, and then calls the old signal handler. Set
1004// to inhibit registration of these signal handlers.
1005#define NCOPTION_NO_QUIT_SIGHANDLERS 0x0008ull
1006
1007// Initialize the standard plane's virtual cursor to match the physical cursor
1008// at context creation time. Together with NCOPTION_NO_ALTERNATE_SCREEN and a
1009// scrolling standard plane, this facilitates easy scrolling-style programs in
1010// rendered mode.
1011#define NCOPTION_PRESERVE_CURSOR 0x0010ull
1012
1013// Notcurses typically prints version info in notcurses_init() and performance
1014// info in notcurses_stop(). This inhibits that output.
1015#define NCOPTION_SUPPRESS_BANNERS 0x0020ull
1016
1017// If smcup/rmcup capabilities are indicated, Notcurses defaults to making use
1018// of the "alternate screen". This flag inhibits use of smcup/rmcup.
1019#define NCOPTION_NO_ALTERNATE_SCREEN 0x0040ull
1020
1021// Do not modify the font. Notcurses might attempt to change the font slightly,
1022// to support certain glyphs (especially on the Linux console). If this is set,
1023// no such modifications will be made. Note that font changes will not affect
1024// anything but the virtual console/terminal in which Notcurses is running.
1025#define NCOPTION_NO_FONT_CHANGES 0x0080ull
1026
1027// Input may be freely dropped. This ought be provided when the program does not
1028// intend to handle input. Otherwise, input can accumulate in internal buffers,
1029// eventually preventing Notcurses from processing terminal messages.
1030#define NCOPTION_DRAIN_INPUT 0x0100ull
1031
1032// Prepare the standard plane in scrolling mode, useful for CLIs. This is
1033// equivalent to calling ncplane_set_scrolling(notcurses_stdplane(nc), true).
1034#define NCOPTION_SCROLLING 0x0200ull
1035
1036// "CLI mode" is just setting these four options.
1037#define NCOPTION_CLI_MODE (NCOPTION_NO_ALTERNATE_SCREEN \
1038 |NCOPTION_NO_CLEAR_BITMAPS \
1039 |NCOPTION_PRESERVE_CURSOR \
1040 |NCOPTION_SCROLLING)
1041
1042// Configuration for notcurses_init().
1043typedef struct notcurses_options {
1044 // The name of the terminfo database entry describing this terminal. If NULL,
1045 // the environment variable TERM is used. Failure to open the terminal
1046 // definition will result in failure to initialize notcurses.
1047 const char* termtype;
1048 // Progressively higher log levels result in more logging to stderr. By
1049 // default, nothing is printed to stderr once fullscreen service begins.
1051 // Desirable margins. If all are 0 (default), we will render to the entirety
1052 // of the screen. If the screen is too small, we do what we can--this is
1053 // strictly best-effort. Absolute coordinates are relative to the rendering
1054 // area ((0, 0) is always the origin of the rendering area).
1056 // General flags; see NCOPTION_*. This is expressed as a bitfield so that
1057 // future options can be added without reshaping the struct. Undefined bits
1058 // must be set to 0.
1059 uint64_t flags;
1061
1062// Lex a margin argument according to the standard Notcurses definition. There
1063// can be either a single number, which will define all margins equally, or
1064// there can be four numbers separated by commas.
1065API int notcurses_lex_margins(const char* op, notcurses_options* opts)
1066 __attribute__ ((nonnull (1)));
1067
1068// Lex a blitter.
1069API int notcurses_lex_blitter(const char* op, ncblitter_e* blitter)
1070 __attribute__ ((nonnull (1)));
1071
1072// Get the name of a blitter.
1073API const char* notcurses_str_blitter(ncblitter_e blitter);
1074
1075// Lex a scaling mode (one of "none", "stretch", "scale", "hires",
1076// "scalehi", or "inflate").
1077API int notcurses_lex_scalemode(const char* op, ncscale_e* scalemode)
1078 __attribute__ ((nonnull (1)));
1079
1080// Get the name of a scaling mode.
1081API const char* notcurses_str_scalemode(ncscale_e scalemode);
1082
1083// Initialize a Notcurses context on the connected terminal at 'fp'. 'fp' must
1084// be a tty. You'll usually want stdout. NULL can be supplied for 'fp', in
1085// which case /dev/tty will be opened. Returns NULL on error, including any
1086// failure initializing terminfo.
1088
1089// The same as notcurses_init(), but without any multimedia functionality,
1090// allowing for a svelter binary. Link with notcurses-core if this is used.
1092
1093// Destroy a Notcurses context. A NULL 'nc' is a no-op.
1094API int notcurses_stop(struct notcurses* nc);
1095
1096// Shift to the alternate screen, if available. If already using the alternate
1097// screen, this returns 0 immediately. If the alternate screen is not
1098// available, this returns -1 immediately. Entering the alternate screen turns
1099// off scrolling for the standard plane.
1101 __attribute__ ((nonnull (1)));
1102
1103// Exit the alternate screen. Immediately returns 0 if not currently using the
1104// alternate screen.
1106 __attribute__ ((nonnull (1)));
1107
1108// Get a reference to the standard plane (one matching our current idea of the
1109// terminal size) for this terminal. The standard plane always exists, and its
1110// origin is always at the uppermost, leftmost cell of the terminal.
1111API struct ncplane* notcurses_stdplane(struct notcurses* nc)
1112 __attribute__ ((nonnull (1)));
1113API const struct ncplane* notcurses_stdplane_const(const struct notcurses* nc)
1114 __attribute__ ((nonnull (1)));
1115
1116// Return the topmost plane of the pile containing 'n'.
1117API struct ncplane* ncpile_top(struct ncplane* n)
1118 __attribute__ ((nonnull (1)));
1119
1120// Return the bottommost plane of the pile containing 'n'.
1121API struct ncplane* ncpile_bottom(struct ncplane* n)
1122 __attribute__ ((nonnull (1)));
1123
1124// Return the topmost plane of the standard pile.
1125static inline struct ncplane*
1126notcurses_top(struct notcurses* n){
1128}
1129
1130// Return the bottommost plane of the standard pile.
1131static inline struct ncplane*
1132notcurses_bottom(struct notcurses* n){
1134}
1135
1136// Renders the pile of which 'n' is a part. Rendering this pile again will blow
1137// away the render. To actually write out the render, call ncpile_rasterize().
1138API int ncpile_render(struct ncplane* n)
1139 __attribute__ ((nonnull (1)));
1140
1141// Make the physical screen match the last rendered frame from the pile of
1142// which 'n' is a part. This is a blocking call. Don't call this before the
1143// pile has been rendered (doing so will likely result in a blank screen).
1144API int ncpile_rasterize(struct ncplane* n)
1145 __attribute__ ((nonnull (1)));
1146
1147// Renders and rasterizes the standard pile in one shot. Blocking call.
1148static inline int
1149notcurses_render(struct notcurses* nc){
1150 struct ncplane* stdn = notcurses_stdplane(nc);
1151 if(ncpile_render(stdn)){
1152 return -1;
1153 }
1154 return ncpile_rasterize(stdn);
1155}
1156
1157// Perform the rendering and rasterization portion of ncpile_render() and
1158// ncpile_rasterize(), but do not write the resulting buffer out to the
1159// terminal. Using this function, the user can control the writeout process.
1160// The returned buffer must be freed by the caller.
1161API int ncpile_render_to_buffer(struct ncplane* p, char** buf, size_t* buflen)
1162 __attribute__ ((nonnull (1, 2, 3)));
1163
1164// Write the last rendered frame, in its entirety, to 'fp'. If a frame has
1165// not yet been rendered, nothing will be written.
1166API int ncpile_render_to_file(struct ncplane* p, FILE* fp)
1167 __attribute__ ((nonnull (1, 2)));
1168
1169// Destroy all ncplanes other than the stdplane.
1170API void notcurses_drop_planes(struct notcurses* nc)
1171 __attribute__ ((nonnull (1)));
1172
1173// All input is taken from stdin. We attempt to read a single UTF8-encoded
1174// Unicode codepoint, *not* an entire Extended Grapheme Cluster. It is also
1175// possible that we will read a special keypress, i.e. anything that doesn't
1176// correspond to a Unicode codepoint (e.g. arrow keys, function keys, screen
1177// resize events, etc.). These are mapped into a Unicode's area beyond the
1178// 17 65536-entry Planes, starting at U+1115000. See <notcurses/nckeys.h>.
1179//
1180// notcurses_get_nblock() is nonblocking. notcurses_get_blocking() blocks
1181// until a codepoint or special key is read, or until interrupted by a signal.
1182// notcurses_get() allows an optional timeout to be controlled.
1183//
1184// In the case of a valid read, a 32-bit Unicode codepoint is returned. 0 is
1185// returned to indicate that no input was available. Otherwise (including on
1186// EOF) (uint32_t)-1 is returned.
1187
1188// Is the event a synthesized mouse event?
1189static inline bool
1190nckey_mouse_p(uint32_t r){
1191 return r >= NCKEY_MOTION && r <= NCKEY_BUTTON11;
1192}
1193
1200
1201// Note: changing this also means adding kitty_cb_atxt functions in
1202// in.c otherwise extra codepoints won't be picked up.
1203#define NCINPUT_MAX_EFF_TEXT_CODEPOINTS 4
1204
1205// An input event. Cell coordinates are currently defined only for mouse
1206// events. It is not guaranteed that we can set the modifiers for a given
1207// ncinput. We encompass single Unicode codepoints, not complete EGCs.
1208// FIXME for abi4, combine the bools into |modifiers|
1209typedef struct ncinput {
1210 uint32_t id; // Unicode codepoint or synthesized NCKEY event
1211 int y, x; // y/x cell coordinate of event, -1 for undefined
1212 char utf8[5]; // utf8 representation, if one exists
1213 // DEPRECATED do not use! going away in 4.0
1214 bool alt; // was alt held?
1215 bool shift; // was shift held?
1216 bool ctrl; // was ctrl held?
1217 // END DEPRECATION
1219 unsigned modifiers;// bitmask over NCKEY_MOD_*
1220 int ypx, xpx; // pixel offsets within cell, -1 for undefined
1222 // utf32 representation, taking modifier
1223 // keys into account. This can be multiple
1224 // codepoints. Array is zero-terminated.
1226
1227static inline bool
1228ncinput_shift_p(const ncinput* n){
1229 return (n->modifiers & NCKEY_MOD_SHIFT);
1230}
1231
1232static inline bool
1233ncinput_ctrl_p(const ncinput* n){
1234 return (n->modifiers & NCKEY_MOD_CTRL);
1235}
1236
1237static inline bool
1238ncinput_alt_p(const ncinput* n){
1239 return (n->modifiers & NCKEY_MOD_ALT);
1240}
1241
1242static inline bool
1243ncinput_meta_p(const ncinput* n){
1244 return (n->modifiers & NCKEY_MOD_META);
1245}
1246
1247static inline bool
1248ncinput_super_p(const ncinput* n){
1249 return (n->modifiers & NCKEY_MOD_SUPER);
1250}
1251
1252static inline bool
1253ncinput_hyper_p(const ncinput* n){
1254 return (n->modifiers & NCKEY_MOD_HYPER);
1255}
1256
1257static inline bool
1258ncinput_capslock_p(const ncinput* n){
1259 return (n->modifiers & NCKEY_MOD_CAPSLOCK);
1260}
1261
1262static inline bool
1263ncinput_numlock_p(const ncinput* n){
1264 return (n->modifiers & NCKEY_MOD_NUMLOCK);
1265}
1266
1267// compare two ncinput structs for data equality. NCTYPE_PRESS and
1268// NCTYPE_UNKNOWN are considered to be equivalent. NCKEY_MOD_CAPSLOCK
1269// and NCKEY_MOD_NUMLOCK are not considered relevant.
1270static inline bool
1271ncinput_equal_p(const ncinput* n1, const ncinput* n2){
1272 // don't need to check ->utf8; it's derived from id
1273 if(n1->id != n2->id){
1274 return false;
1275 }
1276 if(n1->y != n2->y || n1->x != n2->x){
1277 return false;
1278 }
1279 // don't need to check deprecated alt, ctrl, shift
1280 if((n1->modifiers & ~(unsigned)(NCKEY_MOD_CAPSLOCK | NCKEY_MOD_NUMLOCK))
1281 != (n2->modifiers & ~(unsigned)(NCKEY_MOD_CAPSLOCK | NCKEY_MOD_NUMLOCK))){
1282 return false;
1283 }
1284 if(n1->evtype != n2->evtype){
1285 if((n1->evtype != NCTYPE_UNKNOWN && n1->evtype != NCTYPE_PRESS) ||
1286 (n2->evtype != NCTYPE_UNKNOWN && n2->evtype != NCTYPE_PRESS)){
1287 return false;
1288 }
1289 }
1290 if(n1->ypx != n2->ypx || n1->xpx != n2->xpx){
1291 return false;
1292 }
1293 return true;
1294}
1295
1296// Read a UTF-32-encoded Unicode codepoint from input. This might only be part
1297// of a larger EGC. Provide a NULL 'ts' to block at length, and otherwise a
1298// timespec specifying an absolute deadline calculated using CLOCK_MONOTONIC.
1299// Returns a single Unicode code point, or a synthesized special key constant,
1300// or (uint32_t)-1 on error. Returns 0 on a timeout. If an event is processed,
1301// the return value is the 'id' field from that event. 'ni' may be NULL.
1302API uint32_t notcurses_get(struct notcurses* n, const struct timespec* ts,
1303 ncinput* ni)
1304 __attribute__ ((nonnull (1)));
1305
1306// Acquire up to 'vcount' ncinputs at the vector 'ni'. The number read will be
1307// returned, or -1 on error without any reads, 0 on timeout.
1308API int notcurses_getvec(struct notcurses* n, const struct timespec* ts,
1309 ncinput* ni, int vcount)
1310 __attribute__ ((nonnull (1, 3)));
1311
1312// Get a file descriptor suitable for input event poll()ing. When this
1313// descriptor becomes available, you can call notcurses_get_nblock(),
1314// and input ought be ready. This file descriptor is *not* necessarily
1315// the file descriptor associated with stdin (but it might be!).
1317 __attribute__ ((nonnull (1)));
1318
1319// 'ni' may be NULL if the caller is uninterested in event details. If no event
1320// is immediately ready, returns 0.
1321static inline uint32_t
1322notcurses_get_nblock(struct notcurses* n, ncinput* ni){
1323 struct timespec ts = { .tv_sec = 0, .tv_nsec = 0 };
1324 return notcurses_get(n, &ts, ni);
1325}
1326
1327// 'ni' may be NULL if the caller is uninterested in event details. Blocks
1328// until an event is processed or a signal is received (including resize events).
1329static inline uint32_t
1330notcurses_get_blocking(struct notcurses* n, ncinput* ni){
1331 return notcurses_get(n, NULL, ni);
1332}
1333
1334// Was 'ni' free of modifiers?
1335static inline bool
1336ncinput_nomod_p(const ncinput* ni){
1337 return !(ni->modifiers);
1338}
1339
1340#define NCMICE_NO_EVENTS 0
1341#define NCMICE_MOVE_EVENT 0x1
1342#define NCMICE_BUTTON_EVENT 0x2
1343#define NCMICE_DRAG_EVENT 0x4
1344#define NCMICE_ALL_EVENTS 0x7
1345
1346// Enable mice events according to 'eventmask'; an eventmask of 0 will disable
1347// all mice tracking. On failure, -1 is returned. On success, 0 is returned, and
1348// mouse events will be published to notcurses_get().
1349API int notcurses_mice_enable(struct notcurses* n, unsigned eventmask)
1350 __attribute__ ((nonnull (1)));
1351
1352// Disable mouse events. Any events in the input queue can still be delivered.
1353__attribute__ ((nonnull (1))) static inline int
1354notcurses_mice_disable(struct notcurses* n){
1356}
1357
1358// Disable signals originating from the terminal's line discipline, i.e.
1359// SIGINT (^C), SIGQUIT (^\‍), and SIGTSTP (^Z). They are enabled by default.
1361 __attribute__ ((nonnull (1)));
1362
1363// Restore signals originating from the terminal's line discipline, i.e.
1364// SIGINT (^C), SIGQUIT (^\‍), and SIGTSTP (^Z), if disabled.
1366 __attribute__ ((nonnull (1)));
1367
1368// Refresh the physical screen to match what was last rendered (i.e., without
1369// reflecting any changes since the last call to notcurses_render()). This is
1370// primarily useful if the screen is externally corrupted, or if an
1371// NCKEY_RESIZE event has been read and you're not yet ready to render. The
1372// current screen geometry is returned in 'y' and 'x', if they are not NULL.
1373API int notcurses_refresh(struct notcurses* n, unsigned* RESTRICT y, unsigned* RESTRICT x)
1374 __attribute__ ((nonnull (1)));
1375
1376// Extract the Notcurses context to which this plane is attached.
1378 __attribute__ ((nonnull (1)));
1379
1380API const struct notcurses* ncplane_notcurses_const(const struct ncplane* n)
1381 __attribute__ ((nonnull (1)));
1382
1383// Return the dimensions of this ncplane. y or x may be NULL.
1384API void ncplane_dim_yx(const struct ncplane* n, unsigned* RESTRICT y, unsigned* RESTRICT x)
1385 __attribute__ ((nonnull (1)));
1386
1387// notcurses_stdplane(), plus free bonus dimensions written to non-NULL y/x!
1388static inline struct ncplane*
1389notcurses_stddim_yx(struct notcurses* nc, unsigned* RESTRICT y, unsigned* RESTRICT x){
1390 struct ncplane* s = notcurses_stdplane(nc); // can't fail
1391 ncplane_dim_yx(s, y, x); // accepts NULL
1392 return s;
1393}
1394
1395static inline const struct ncplane*
1396notcurses_stddim_yx_const(const struct notcurses* nc, unsigned* RESTRICT y, unsigned* RESTRICT x){
1397 const struct ncplane* s = notcurses_stdplane_const(nc); // can't fail
1398 ncplane_dim_yx(s, y, x); // accepts NULL
1399 return s;
1400}
1401
1402static inline unsigned
1403ncplane_dim_y(const struct ncplane* n){
1404 unsigned dimy;
1405 ncplane_dim_yx(n, &dimy, NULL);
1406 return dimy;
1407}
1408
1409static inline unsigned
1410ncplane_dim_x(const struct ncplane* n){
1411 unsigned dimx;
1412 ncplane_dim_yx(n, NULL, &dimx);
1413 return dimx;
1414}
1415
1416// Retrieve pixel geometry for the display region ('pxy', 'pxx'), each cell
1417// ('celldimy', 'celldimx'), and the maximum displayable bitmap ('maxbmapy',
1418// 'maxbmapx'). If bitmaps are not supported, or if there is no artificial
1419// limit on bitmap size, 'maxbmapy' and 'maxbmapx' will be 0. Any of the
1420// geometry arguments may be NULL.
1421API void ncplane_pixel_geom(const struct ncplane* n,
1422 unsigned* RESTRICT pxy, unsigned* RESTRICT pxx,
1423 unsigned* RESTRICT celldimy, unsigned* RESTRICT celldimx,
1424 unsigned* RESTRICT maxbmapy, unsigned* RESTRICT maxbmapx)
1425 __attribute__ ((nonnull (1)));
1426
1427// Return our current idea of the terminal dimensions in rows and cols.
1428static inline void
1429notcurses_term_dim_yx(const struct notcurses* n, unsigned* RESTRICT rows, unsigned* RESTRICT cols){
1431}
1432
1433// Retrieve the contents of the specified cell as last rendered. Returns the EGC
1434// or NULL on error. This EGC must be free()d by the caller. The stylemask and
1435// channels are written to 'stylemask' and 'channels', respectively.
1436API char* notcurses_at_yx(struct notcurses* nc, unsigned yoff, unsigned xoff,
1437 uint16_t* stylemask, uint64_t* channels)
1438 __attribute__ ((nonnull (1)));
1439
1440// Horizontal alignment relative to the parent plane. Use ncalign_e for 'x'.
1441#define NCPLANE_OPTION_HORALIGNED 0x0001ull
1442// Vertical alignment relative to the parent plane. Use ncalign_e for 'y'.
1443#define NCPLANE_OPTION_VERALIGNED 0x0002ull
1444// Maximize relative to the parent plane, modulo the provided margins. The
1445// margins are best-effort; the plane will always be at least 1 column by
1446// 1 row. If the margins can be effected, the plane will be sized to all
1447// remaining space. 'y' and 'x' are overloaded as the top and left margins
1448// when this flag is used. 'rows' and 'cols' must be 0 when this flag is
1449// used. This flag is exclusive with both of the alignment flags.
1450#define NCPLANE_OPTION_MARGINALIZED 0x0004ull
1451// If this plane is bound to a scrolling plane, it ought *not* scroll along
1452// with the parent (it will still move with the parent, maintaining its
1453// relative position, if the parent is moved to a new location).
1454#define NCPLANE_OPTION_FIXED 0x0008ull
1455// Enable automatic growth of the plane to accommodate output. Creating a
1456// plane with this flag is equivalent to immediately calling
1457// ncplane_set_autogrow(p, true) following plane creation.
1458#define NCPLANE_OPTION_AUTOGROW 0x0010ull
1459// Enable vertical scrolling of the plane to accommodate output. Creating a
1460// plane with this flag is equivalent to immediately calling
1461// ncplane_set_scrolling(p, true) following plane creation.
1462#define NCPLANE_OPTION_VSCROLL 0x0020ull
1463
1464typedef struct ncplane_options {
1465 int y; // vertical placement relative to parent plane
1466 int x; // horizontal placement relative to parent plane
1467 unsigned rows; // rows, must be >0 unless NCPLANE_OPTION_MARGINALIZED
1468 unsigned cols; // columns, must be >0 unless NCPLANE_OPTION_MARGINALIZED
1469 void* userptr; // user curry, may be NULL
1470 const char* name; // name (used only for debugging), may be NULL
1471 int (*resizecb)(struct ncplane*); // callback when parent is resized
1472 uint64_t flags; // closure over NCPLANE_OPTION_*
1473 unsigned margin_b, margin_r; // margins (require NCPLANE_OPTION_MARGINALIZED)
1475
1476// Create a new ncplane bound to plane 'n', at the offset 'y'x'x' (relative to
1477// the origin of 'n') and the specified size. The number of 'rows' and 'cols'
1478// must both be positive. This plane is initially at the top of the z-buffer,
1479// as if ncplane_move_top() had been called on it. The void* 'userptr' can be
1480// retrieved (and reset) later. A 'name' can be set, used in debugging.
1482 __attribute__ ((nonnull (1, 2)));
1483
1484// Same as ncplane_create(), but creates a new pile. The returned plane will
1485// be the top, bottom, and root of this new pile.
1486API ALLOC struct ncplane* ncpile_create(struct notcurses* nc, const ncplane_options* nopts)
1487 __attribute__ ((nonnull (1, 2)));
1488
1489// Utility resize callbacks. When a parent plane is resized, it invokes each
1490// child's resize callback. Any logic can be run in a resize callback, but
1491// these are some generically useful ones.
1492
1493// resize the plane to the visual region's size (used for the standard plane).
1495
1496// resize the plane to its parent's size, attempting to enforce the margins
1497// supplied along with NCPLANE_OPTION_MARGINALIZED.
1499
1500// realign the plane 'n' against its parent, using the alignments specified
1501// with NCPLANE_OPTION_HORALIGNED and/or NCPLANE_OPTION_VERALIGNED.
1502API int ncplane_resize_realign(struct ncplane* n);
1503
1504// move the plane such that it is entirely within its parent, if possible.
1505// no resizing is performed.
1507
1508// Replace the ncplane's existing resizecb with 'resizecb' (which may be NULL).
1509// The standard plane's resizecb may not be changed.
1510API void ncplane_set_resizecb(struct ncplane* n, int(*resizecb)(struct ncplane*));
1511
1512// Returns the ncplane's current resize callback.
1513API int (*ncplane_resizecb(const struct ncplane* n))(struct ncplane*);
1514
1515// Set the plane's name (may be NULL), replacing any current name.
1516API int ncplane_set_name(struct ncplane* n, const char* name)
1517 __attribute__ ((nonnull (1)));
1518
1519// Return a heap-allocated copy of the plane's name, or NULL if it has none.
1520API ALLOC char* ncplane_name(const struct ncplane* n)
1521 __attribute__ ((nonnull (1)));
1522
1523// Plane 'n' will be unbound from its parent plane, and will be made a bound
1524// child of 'newparent'. It is an error if 'n' or 'newparent' are NULL. If
1525// 'newparent' is equal to 'n', 'n' becomes the root of a new pile, unless 'n'
1526// is already the root of a pile, in which case this is a no-op. Returns 'n'.
1527// The standard plane cannot be reparented. Any planes bound to 'n' are
1528// reparented to the previous parent of 'n'.
1529API struct ncplane* ncplane_reparent(struct ncplane* n, struct ncplane* newparent)
1530 __attribute__ ((nonnull (1, 2)));
1531
1532// The same as ncplane_reparent(), except any planes bound to 'n' come along
1533// with it to its new destination. Their z-order is maintained. If 'newparent'
1534// is an ancestor of 'n', NULL is returned, and no changes are made.
1535API struct ncplane* ncplane_reparent_family(struct ncplane* n, struct ncplane* newparent)
1536 __attribute__ ((nonnull (1, 2)));
1537
1538// Duplicate an existing ncplane. The new plane will have the same geometry,
1539// will duplicate all content, and will start with the same rendering state.
1540// The new plane will be immediately above the old one on the z axis, and will
1541// be bound to the same parent (unless 'n' is a root plane, in which case the
1542// new plane will be bound to it). Bound planes are *not* duplicated; the new
1543// plane is bound to the parent of 'n', but has no bound planes.
1544API ALLOC struct ncplane* ncplane_dup(const struct ncplane* n, void* opaque)
1545 __attribute__ ((nonnull (1)));
1546
1547// provided a coordinate relative to the origin of 'src', map it to the same
1548// absolute coordinate relative to the origin of 'dst'. either or both of 'y'
1549// and 'x' may be NULL. if 'dst' is NULL, it is taken to be the standard plane.
1550API void ncplane_translate(const struct ncplane* src, const struct ncplane* dst,
1551 int* RESTRICT y, int* RESTRICT x)
1552 __attribute__ ((nonnull (1)));
1553
1554// Fed absolute 'y'/'x' coordinates, determine whether that coordinate is
1555// within the ncplane 'n'. If not, return false. If so, return true. Either
1556// way, translate the absolute coordinates relative to 'n'. If the point is not
1557// within 'n', these coordinates will not be within the dimensions of the plane.
1558API bool ncplane_translate_abs(const struct ncplane* n, int* RESTRICT y, int* RESTRICT x)
1559 __attribute__ ((nonnull (1)));
1560
1561// All planes are created with scrolling disabled. Scrolling can be dynamically
1562// controlled with ncplane_set_scrolling(). Returns true if scrolling was
1563// previously enabled, or false if it was disabled.
1564API bool ncplane_set_scrolling(struct ncplane* n, unsigned scrollp)
1565 __attribute__ ((nonnull (1)));
1566
1568 __attribute__ ((nonnull (1)));
1569
1570// By default, planes are created with autogrow disabled. Autogrow can be
1571// dynamically controlled with ncplane_set_autogrow(). Returns true if
1572// autogrow was previously enabled, or false if it was disabled.
1573API bool ncplane_set_autogrow(struct ncplane* n, unsigned growp)
1574 __attribute__ ((nonnull (1)));
1575
1576API bool ncplane_autogrow_p(const struct ncplane* n)
1577 __attribute__ ((nonnull (1)));
1578
1579// Palette API. Some terminals only support 256 colors, but allow the full
1580// palette to be specified with arbitrary RGB colors. In all cases, it's more
1581// performant to use indexed colors, since it's much less data to write to the
1582// terminal. If you can limit yourself to 256 colors, that's probably best.
1583
1584typedef struct ncpalette {
1585 uint32_t chans[NCPALETTESIZE]; // RGB values as regular ol' channels
1587
1588// Create a new palette store. It will be initialized with notcurses' best
1589// knowledge of the currently configured palette.
1591 __attribute__ ((nonnull (1)));
1592
1593// Attempt to configure the terminal with the provided palette 'p'. Does not
1594// transfer ownership of 'p'; ncpalette_free() can (ought) still be called.
1595API int ncpalette_use(struct notcurses* nc, const ncpalette* p)
1596 __attribute__ ((nonnull (1, 2)));
1597
1598// Manipulate entries in the palette store 'p'. These are *not* locked.
1599static inline int
1600ncpalette_set_rgb8(ncpalette* p, int idx, unsigned r, unsigned g, unsigned b){
1601 if(idx < 0 || (size_t)idx > sizeof(p->chans) / sizeof(*p->chans)){
1602 return -1;
1603 }
1604 return ncchannel_set_rgb8(&p->chans[idx], r, g, b);
1605}
1606
1607static inline int
1608ncpalette_set(ncpalette* p, int idx, unsigned rgb){
1609 if(idx < 0 || (size_t)idx > sizeof(p->chans) / sizeof(*p->chans)){
1610 return -1;
1611 }
1612 return ncchannel_set(&p->chans[idx], rgb);
1613}
1614
1615static inline int
1616ncpalette_get(const ncpalette* p, int idx, uint32_t* palent){
1617 if(idx < 0 || (size_t)idx > sizeof(p->chans) / sizeof(*p->chans)){
1618 return -1;
1619 }
1620 *palent = ncchannel_rgb(p->chans[idx]);
1621 return 0;
1622}
1623
1624static inline int
1625ncpalette_get_rgb8(const ncpalette* p, int idx, unsigned* RESTRICT r, unsigned* RESTRICT g, unsigned* RESTRICT b){
1626 if(idx < 0 || (size_t)idx > sizeof(p->chans) / sizeof(*p->chans)){
1627 return -1;
1628 }
1629 return (int)ncchannel_rgb8(p->chans[idx], r, g, b);
1630}
1631
1632// Free the palette store 'p'.
1634
1635// Capabilities, derived from terminfo, environment variables, and queries
1636typedef struct nccapabilities {
1637 unsigned colors; // size of palette for indexed colors
1638 bool utf8; // are we using utf-8 encoding? from nl_langinfo(3)
1639 bool rgb; // 24bit color? COLORTERM/heuristics/terminfo 'rgb'
1640 bool can_change_colors; // can we change the palette? terminfo 'ccc'
1641 // these are assigned wholly through TERM- and query-based heuristics
1642 bool halfblocks;// we assume halfblocks, but some are known to lack them
1643 bool quadrants; // do we have (good, vetted) Unicode 1 quadrant support?
1644 bool sextants; // do we have (good, vetted) Unicode 13 sextant support?
1645 bool octants; // do we have (good, vetted) Unicode 16 octant support?
1646 bool braille; // do we have Braille support? (linux console does not)
1648
1649// Returns a 16-bit bitmask of supported curses-style attributes
1650// (NCSTYLE_UNDERLINE, NCSTYLE_BOLD, etc.) The attribute is only
1651// indicated as supported if the terminal can support it together with color.
1652// For more information, see the "ncv" capability in terminfo(5).
1653API uint16_t notcurses_supported_styles(const struct notcurses* nc)
1654 __attribute__ ((nonnull (1))) __attribute__ ((pure));
1655
1656// Returns the number of simultaneous colors claimed to be supported, or 1 if
1657// there is no color support. Note that several terminal emulators advertise
1658// more colors than they actually support, downsampling internally.
1659API unsigned notcurses_palette_size(const struct notcurses* nc)
1660 __attribute__ ((nonnull (1))) __attribute__ ((pure));
1661
1662// Returns the name (and sometimes version) of the terminal, as Notcurses
1663// has been best able to determine.
1665 __attribute__ ((nonnull (1)));
1666
1668 __attribute__ ((nonnull (1)));
1669
1670// pixel blitting implementations. informative only; don't special-case
1671// based off any of this information!
1672typedef enum {
1675 NCPIXEL_LINUXFB, // linux framebuffer
1677 // C=1 (disabling scrolling) was only introduced in 0.20.0, at the same
1678 // time as animation. prior to this, graphics had to be entirely redrawn
1679 // on any change, and it wasn't possible to use the bottom line.
1681 // until 0.22.0's introduction of 'a=c' for self-referential composition, we
1682 // had to keep a complete copy of the RGBA data, in case a wiped cell needed
1683 // to be rebuilt. we'd otherwise have to unpack the glyph and store it into
1684 // the auxvec on the fly.
1686 // with 0.22.0, we only ever write transparent cells after writing the
1687 // original image (which we now deflate, since we needn't unpack it later).
1688 // the only data we need keep is the auxvecs.
1691
1692// Can we blit pixel-accurate bitmaps?
1694 __attribute__ ((nonnull (1))) __attribute__ ((pure));
1695
1696// Can we set the "hardware" palette? Requires the "ccc" terminfo capability,
1697// and that the number of colors supported is at least the size of our
1698// ncpalette structure.
1699__attribute__ ((nonnull (1))) __attribute__ ((pure)) static inline bool
1700nccapability_canchangecolor(const nccapabilities* caps){
1701 if(!caps->can_change_colors){
1702 return false;
1703 }
1704 ncpalette* p;
1705 if(caps->colors < sizeof(p->chans) / sizeof(*p->chans)){
1706 return false;
1707 }
1708 return true;
1709}
1710
1711// Can we emit 24-bit, three-channel RGB foregrounds and backgrounds?
1712__attribute__ ((nonnull (1))) __attribute__ ((pure)) static inline bool
1713notcurses_cantruecolor(const struct notcurses* nc){
1714 return notcurses_capabilities(nc)->rgb;
1715}
1716
1717// Can we directly specify RGB values per cell, or only use palettes?
1718__attribute__ ((nonnull (1))) __attribute__ ((pure)) static inline bool
1719notcurses_canchangecolor(const struct notcurses* nc){
1720 return nccapability_canchangecolor(notcurses_capabilities(nc));
1721}
1722
1723// Can we fade? Fading requires either the "rgb" or "ccc" terminfo capability.
1724__attribute__ ((nonnull (1))) __attribute__ ((pure)) static inline bool
1725notcurses_canfade(const struct notcurses* n){
1726 return notcurses_canchangecolor(n) || notcurses_cantruecolor(n);
1727}
1728
1729// Can we load images? This requires being built against FFmpeg/OIIO.
1731 __attribute__ ((pure));
1732
1733// Can we load videos? This requires being built against FFmpeg.
1735 __attribute__ ((pure));
1736
1737// Is our encoding UTF-8? Requires LANG being set to a UTF8 locale.
1738__attribute__ ((nonnull (1))) __attribute__ ((pure)) static inline bool
1739notcurses_canutf8(const struct notcurses* nc){
1740 return notcurses_capabilities(nc)->utf8;
1741}
1742
1743// Can we reliably use Unicode halfblocks? Any Unicode implementation can.
1744__attribute__ ((nonnull (1))) __attribute__ ((pure)) static inline bool
1745notcurses_canhalfblock(const struct notcurses* nc){
1746 return notcurses_canutf8(nc);
1747}
1748
1749// Can we reliably use Unicode quadrants?
1750__attribute__ ((nonnull (1))) __attribute__ ((pure)) static inline bool
1751notcurses_canquadrant(const struct notcurses* nc){
1752 return notcurses_canutf8(nc) && notcurses_capabilities(nc)->quadrants;
1753}
1754
1755// Can we reliably use Unicode 13 sextants?
1756__attribute__ ((nonnull (1))) __attribute__ ((pure)) static inline bool
1757notcurses_cansextant(const struct notcurses* nc){
1758 return notcurses_canutf8(nc) && notcurses_capabilities(nc)->sextants;
1759}
1760
1761// Can we reliably use Unicode 16 octants?
1762__attribute__ ((nonnull (1))) __attribute__ ((pure)) static inline bool
1763notcurses_canoctant(const struct notcurses* nc){
1764 return notcurses_canutf8(nc) && notcurses_capabilities(nc)->octants;
1765}
1766
1767// Can we reliably use Unicode Braille?
1768__attribute__ ((nonnull (1))) __attribute__ ((pure)) static inline bool
1769notcurses_canbraille(const struct notcurses* nc){
1770 return notcurses_canutf8(nc) && notcurses_capabilities(nc)->braille;
1771}
1772
1773// Can we blit pixel-accurate bitmaps?
1774__attribute__ ((nonnull (1))) __attribute__ ((pure)) static inline bool
1775notcurses_canpixel(const struct notcurses* nc){
1777}
1778
1779// whenever a new field is added here, ensure we add the proper rule to
1780// notcurses_stats_reset(), so that values are preserved in the stash stats.
1781typedef struct ncstats {
1782 // purely increasing stats
1783 uint64_t renders; // successful ncpile_render() runs
1784 uint64_t writeouts; // successful ncpile_rasterize() runs
1785 uint64_t failed_renders; // aborted renders, should be 0
1786 uint64_t failed_writeouts; // aborted writes
1787 uint64_t raster_bytes; // bytes emitted to ttyfp
1788 int64_t raster_max_bytes; // max bytes emitted for a frame
1789 int64_t raster_min_bytes; // min bytes emitted for a frame
1790 uint64_t render_ns; // nanoseconds spent rendering
1791 int64_t render_max_ns; // max ns spent in render for a frame
1792 int64_t render_min_ns; // min ns spent in render for a frame
1793 uint64_t raster_ns; // nanoseconds spent rasterizing
1794 int64_t raster_max_ns; // max ns spent in raster for a frame
1795 int64_t raster_min_ns; // min ns spent in raster for a frame
1796 uint64_t writeout_ns; // nanoseconds spent writing frames to terminal
1797 int64_t writeout_max_ns; // max ns spent writing out a frame
1798 int64_t writeout_min_ns; // min ns spent writing out a frame
1799 uint64_t cellelisions; // cells we elided entirely thanks to damage maps
1800 uint64_t cellemissions; // total number of cells emitted to terminal
1801 uint64_t fgelisions; // RGB fg elision count
1802 uint64_t fgemissions; // RGB fg emissions
1803 uint64_t bgelisions; // RGB bg elision count
1804 uint64_t bgemissions; // RGB bg emissions
1805 uint64_t defaultelisions; // default color was emitted
1806 uint64_t defaultemissions; // default color was elided
1807 uint64_t refreshes; // refresh requests (non-optimized redraw)
1808 uint64_t sprixelemissions; // sprixel draw count
1809 uint64_t sprixelelisions; // sprixel elision count
1810 uint64_t sprixelbytes; // sprixel bytes emitted
1811 uint64_t appsync_updates; // how many application-synchronized updates?
1812 uint64_t input_errors; // errors processing control sequences/utf8
1813 uint64_t input_events; // characters returned to userspace
1814 uint64_t hpa_gratuitous; // unnecessary hpas issued
1815 uint64_t cell_geo_changes; // cell geometry changes (resizes)
1816 uint64_t pixel_geo_changes;// pixel geometry changes (font resize)
1817
1818 // current state -- these can decrease
1819 uint64_t fbbytes; // total bytes devoted to all active framebuffers
1820 unsigned planes; // number of planes currently in existence
1822
1823// Allocate an ncstats object. Use this rather than allocating your own, since
1824// future versions of Notcurses might enlarge this structure.
1826 __attribute__ ((unused)))
1827 __attribute__ ((nonnull (1)));
1828
1829// Acquire an atomic snapshot of the Notcurses object's stats.
1830API void notcurses_stats(struct notcurses* nc, ncstats* stats)
1831 __attribute__ ((nonnull (1, 2)));
1832
1833// Reset all cumulative stats (immediate ones, such as fbbytes, are not reset),
1834// first copying them into |*stats| (if |stats| is not NULL).
1835API void notcurses_stats_reset(struct notcurses* nc, ncstats* stats)
1836 __attribute__ ((nonnull (1)));
1837
1838// Resize the specified ncplane. The four parameters 'keepy', 'keepx',
1839// 'keepleny', and 'keeplenx' define a subset of the ncplane to keep,
1840// unchanged. This may be a region of size 0, though none of these four
1841// parameters may be negative. 'keepx' and 'keepy' are relative to the ncplane.
1842// They must specify a coordinate within the ncplane's totality. 'yoff' and
1843// 'xoff' are relative to 'keepy' and 'keepx', and place the upper-left corner
1844// of the resized ncplane. Finally, 'ylen' and 'xlen' are the dimensions of the
1845// ncplane after resizing. 'ylen' must be greater than or equal to 'keepleny',
1846// and 'xlen' must be greater than or equal to 'keeplenx'. It is an error to
1847// attempt to resize the standard plane. If either of 'keepleny' or 'keeplenx'
1848// is non-zero, both must be non-zero.
1849//
1850// Essentially, the kept material does not move. It serves to anchor the
1851// resized plane. If there is no kept material, the plane can move freely.
1852API int ncplane_resize(struct ncplane* n, int keepy, int keepx,
1853 unsigned keepleny, unsigned keeplenx,
1854 int yoff, int xoff,
1855 unsigned ylen, unsigned xlen);
1856
1857// Resize the plane, retaining what data we can (everything, unless we're
1858// shrinking in some dimension). Keep the origin where it is.
1859static inline int
1860ncplane_resize_simple(struct ncplane* n, unsigned ylen, unsigned xlen){
1861 unsigned oldy, oldx;
1862 ncplane_dim_yx(n, &oldy, &oldx); // current dimensions of 'n'
1863 unsigned keepleny = oldy > ylen ? ylen : oldy;
1864 unsigned keeplenx = oldx > xlen ? xlen : oldx;
1865 return ncplane_resize(n, 0, 0, keepleny, keeplenx, 0, 0, ylen, xlen);
1866}
1867
1868// Destroy the specified ncplane. None of its contents will be visible after
1869// the next call to notcurses_render(). It is an error to attempt to destroy
1870// the standard plane.
1871API int ncplane_destroy(struct ncplane* n);
1872
1873// Set the ncplane's base nccell to 'c'. The base cell is used for purposes of
1874// rendering anywhere that the ncplane's gcluster is 0. Note that the base cell
1875// is not affected by ncplane_erase(). 'c' must not be a secondary cell from a
1876// multicolumn EGC.
1877API int ncplane_set_base_cell(struct ncplane* n, const nccell* c);
1878
1879// Set the ncplane's base nccell. It will be used for purposes of rendering
1880// anywhere that the ncplane's gcluster is 0. Note that the base cell is not
1881// affected by ncplane_erase(). 'egc' must be an extended grapheme cluster.
1882// Returns the number of bytes copied out of 'gcluster', or -1 on failure.
1883API int ncplane_set_base(struct ncplane* n, const char* egc,
1884 uint16_t stylemask, uint64_t channels);
1885
1886// Extract the ncplane's base nccell into 'c'. The reference is invalidated if
1887// 'ncp' is destroyed.
1888API int ncplane_base(struct ncplane* n, nccell* c);
1889
1890// Get the origin of plane 'n' relative to its bound plane, or pile (if 'n' is
1891// a root plane). To get absolute coordinates, use ncplane_abs_yx().
1892API void ncplane_yx(const struct ncplane* n, int* RESTRICT y, int* RESTRICT x)
1893 __attribute__ ((nonnull (1)));
1894API int ncplane_y(const struct ncplane* n) __attribute__ ((pure));
1895API int ncplane_x(const struct ncplane* n) __attribute__ ((pure));
1896
1897// Move this plane relative to the standard plane, or the plane to which it is
1898// bound (if it is bound to a plane). It is an error to attempt to move the
1899// standard plane.
1900API int ncplane_move_yx(struct ncplane* n, int y, int x);
1901
1902// Move this plane relative to its current location. Negative values move up
1903// and left, respectively. Pass 0 to hold an axis constant.
1904__attribute__ ((nonnull (1))) static inline int
1905ncplane_move_rel(struct ncplane* n, int y, int x){
1906 int oy, ox;
1907 ncplane_yx(n, &oy, &ox);
1908 return ncplane_move_yx(n, oy + y, ox + x);
1909}
1910
1911// Get the origin of plane 'n' relative to its pile. Either or both of 'x' and
1912// 'y' may be NULL.
1913API void ncplane_abs_yx(const struct ncplane* n, int* RESTRICT y, int* RESTRICT x)
1914 __attribute__ ((nonnull (1)));
1915API int ncplane_abs_y(const struct ncplane* n) __attribute__ ((pure));
1916API int ncplane_abs_x(const struct ncplane* n) __attribute__ ((pure));
1917
1918// Get the plane to which the plane 'n' is bound, if any.
1919API struct ncplane* ncplane_parent(struct ncplane* n)
1920 __attribute__ ((nonnull (1)));
1921API const struct ncplane* ncplane_parent_const(const struct ncplane* n)
1922 __attribute__ ((nonnull (1)));
1923
1924// Return non-zero iff 'n' is a proper descendent of 'ancestor'.
1925static inline int
1926ncplane_descendant_p(const struct ncplane* n, const struct ncplane* ancestor){
1927 for(const struct ncplane* parent = ncplane_parent_const(n) ; parent != ancestor ; parent = ncplane_parent_const(parent)){
1928 if(ncplane_parent_const(parent) == parent){ // reached a root plane
1929 return 0;
1930 }
1931 }
1932 return 1;
1933}
1934
1935// Splice ncplane 'n' out of the z-buffer, and reinsert it above 'above'.
1936// Returns non-zero if 'n' is already in the desired location. 'n' and
1937// 'above' must not be the same plane. If 'above' is NULL, 'n' is moved
1938// to the bottom of its pile.
1940 struct ncplane* RESTRICT above)
1941 __attribute__ ((nonnull (1)));
1942
1943// Splice ncplane 'n' out of the z-buffer, and reinsert it below 'below'.
1944// Returns non-zero if 'n' is already in the desired location. 'n' and
1945// 'below' must not be the same plane. If 'below' is NULL, 'n' is moved to
1946// the top of its pile.
1948 struct ncplane* RESTRICT below)
1949 __attribute__ ((nonnull (1)));
1950
1951// Splice ncplane 'n' out of the z-buffer; reinsert it at the top or bottom.
1952__attribute__ ((nonnull (1)))
1953static inline void
1954ncplane_move_top(struct ncplane* n){
1956}
1957
1958__attribute__ ((nonnull (1)))
1959static inline void
1960ncplane_move_bottom(struct ncplane* n){
1962}
1963
1964// Splice ncplane 'n' and its bound planes out of the z-buffer, and reinsert
1965// them above or below 'targ'. Relative order will be maintained between the
1966// reinserted planes. For a plane E bound to C, with z-ordering A B C D E,
1967// moving the C family to the top results in C E A B D, while moving it to
1968// the bottom results in A B D C E.
1970 __attribute__ ((nonnull (1)));
1971
1973 __attribute__ ((nonnull (1)));
1974
1975__attribute__ ((nonnull (1)))
1976static inline void
1977ncplane_move_family_top(struct ncplane* n){
1979}
1980
1981__attribute__ ((nonnull (1)))
1982static inline void
1983ncplane_move_family_bottom(struct ncplane* n){
1985}
1986
1987// Return the plane below this one, or NULL if this is at the bottom.
1988API struct ncplane* ncplane_below(struct ncplane* n)
1989 __attribute__ ((nonnull (1)));
1990
1991// Return the plane above this one, or NULL if this is at the top.
1992API struct ncplane* ncplane_above(struct ncplane* n)
1993 __attribute__ ((nonnull (1)));
1994
1995// Effect |r| scroll events on the plane |n|. Returns an error if |n| is not
1996// a scrolling plane, and otherwise returns the number of lines scrolled.
1997API int ncplane_scrollup(struct ncplane* n, int r)
1998 __attribute__ ((nonnull (1)));
1999
2000// Scroll |n| up until |child| is no longer hidden beneath it. Returns an
2001// error if |child| is not a child of |n|, or |n| is not scrolling, or |child|
2002// is fixed. Returns the number of scrolling events otherwise (might be 0).
2003// If the child plane is not fixed, it will likely scroll as well.
2004API int ncplane_scrollup_child(struct ncplane* n, const struct ncplane* child)
2005 __attribute__ ((nonnull (1, 2)));
2006
2007// Rotate the plane π/2 radians clockwise or counterclockwise. This cannot
2008// be performed on arbitrary planes, because glyphs cannot be arbitrarily
2009// rotated. The glyphs which can be rotated are limited: line-drawing
2010// characters, spaces, half blocks, and full blocks. The plane must have
2011// an even number of columns. Use the ncvisual rotation for a more
2012// flexible approach.
2013API int ncplane_rotate_cw(struct ncplane* n)
2014 __attribute__ ((nonnull (1)));
2015API int ncplane_rotate_ccw(struct ncplane* n)
2016 __attribute__ ((nonnull (1)));
2017
2018// Retrieve the current contents of the cell under the cursor. The EGC is
2019// returned, or NULL on error. This EGC must be free()d by the caller. The
2020// stylemask and channels are written to 'stylemask' and 'channels', respectively.
2021API char* ncplane_at_cursor(const struct ncplane* n, uint16_t* stylemask, uint64_t* channels)
2022 __attribute__ ((nonnull (1)));
2023
2024// Retrieve the current contents of the cell under the cursor into 'c'. This
2025// cell is invalidated if the associated plane is destroyed. Returns the number
2026// of bytes in the EGC, or -1 on error.
2028 __attribute__ ((nonnull (1, 2)));
2029
2030// Retrieve the current contents of the specified cell. The EGC is returned, or
2031// NULL on error. This EGC must be free()d by the caller. The stylemask and
2032// channels are written to 'stylemask' and 'channels', respectively. The return
2033// represents how the cell will be used during rendering, and thus integrates
2034// any base cell where appropriate. If called upon the secondary columns of a
2035// wide glyph, the EGC will be returned (i.e. this function does not distinguish
2036// between the primary and secondary columns of a wide glyph). If called on a
2037// sprixel plane, its control sequence is returned for all valid locations.
2038API char* ncplane_at_yx(const struct ncplane* n, int y, int x,
2039 uint16_t* stylemask, uint64_t* channels)
2040 __attribute__ ((nonnull (1)));
2041
2042// Retrieve the current contents of the specified cell into 'c'. This cell is
2043// invalidated if the associated plane is destroyed. Returns the number of
2044// bytes in the EGC, or -1 on error. Unlike ncplane_at_yx(), when called upon
2045// the secondary columns of a wide glyph, the return can be distinguished from
2046// the primary column (nccell_wide_right_p(c) will return true). It is an
2047// error to call this on a sprixel plane (unlike ncplane_at_yx()).
2048API int ncplane_at_yx_cell(struct ncplane* n, int y, int x, nccell* c)
2049 __attribute__ ((nonnull (1, 4)));
2050
2051// Create a flat string from the EGCs of the selected region of the ncplane
2052// 'n'. Start at the plane's 'begy'x'begx' coordinate (which must lie on the
2053// plane), continuing for 'leny'x'lenx' cells. Either or both of 'leny' and
2054// 'lenx' can be specified as 0 to go through the boundary of the plane.
2055// -1 can be specified for 'begx'/'begy' to use the current cursor location.
2056API char* ncplane_contents(struct ncplane* n, int begy, int begx,
2057 unsigned leny, unsigned lenx)
2058 __attribute__ ((nonnull (1)));
2059
2060// Manipulate the opaque user pointer associated with this plane.
2061// ncplane_set_userptr() returns the previous userptr after replacing
2062// it with 'opaque'. the others simply return the userptr.
2063API void* ncplane_set_userptr(struct ncplane* n, void* opaque)
2064 __attribute__ ((nonnull (1)));
2065API void* ncplane_userptr(struct ncplane* n)
2066 __attribute__ ((nonnull (1)));
2067
2068// Find the center coordinate of a plane, preferring the top/left in the
2069// case of an even number of rows/columns (in such a case, there will be one
2070// more cell to the bottom/right of the center than the top/left). The
2071// center is then modified relative to the plane's origin.
2072API void ncplane_center_abs(const struct ncplane* n, int* RESTRICT y,
2073 int* RESTRICT x)
2074 __attribute__ ((nonnull (1)));
2075
2076// Create an RGBA flat array from the selected region of the ncplane 'nc'.
2077// Start at the plane's 'begy'x'begx' coordinate (which must lie on the
2078// plane), continuing for 'leny'x'lenx' cells. Either or both of 'leny' and
2079// 'lenx' can be specified as 0 to go through the boundary of the plane.
2080// Only glyphs from the specified ncblitset may be present. If 'pxdimy' and/or
2081// 'pxdimx' are non-NULL, they will be filled in with the total pixel geometry.
2082API ALLOC uint32_t* ncplane_as_rgba(const struct ncplane* n, ncblitter_e blit,
2083 int begy, int begx,
2084 unsigned leny, unsigned lenx,
2085 unsigned* pxdimy, unsigned* pxdimx)
2086 __attribute__ ((nonnull (1)));
2087
2088// Return the offset into 'availu' at which 'u' ought be output given the
2089// requirements of 'align'. Return -INT_MAX on invalid 'align'. Undefined
2090// behavior on negative 'availu' or 'u'.
2091static inline int
2092notcurses_align(int availu, ncalign_e align, int u){
2093 if(align == NCALIGN_LEFT || align == NCALIGN_TOP){
2094 return 0;
2095 }
2096 if(align == NCALIGN_CENTER){
2097 return (availu - u) / 2;
2098 }
2099 if(align == NCALIGN_RIGHT || align == NCALIGN_BOTTOM){
2100 return availu - u;
2101 }
2102 return -INT_MAX; // invalid |align|
2103}
2104
2105// Return the column at which 'c' cols ought start in order to be aligned
2106// according to 'align' within ncplane 'n'. Return -INT_MAX on invalid
2107// 'align'. Undefined behavior on negative 'c'.
2108static inline int
2109ncplane_halign(const struct ncplane* n, ncalign_e align, int c){
2110 return notcurses_align((int)ncplane_dim_x(n), align, c);
2111}
2112
2113// Return the row at which 'r' rows ought start in order to be aligned
2114// according to 'align' within ncplane 'n'. Return -INT_MAX on invalid
2115// 'align'. Undefined behavior on negative 'r'.
2116static inline int
2117ncplane_valign(const struct ncplane* n, ncalign_e align, int r){
2118 return notcurses_align((int)ncplane_dim_y(n), align, r);
2119}
2120
2121// Move the cursor to the specified position (the cursor needn't be visible).
2122// Pass -1 as either coordinate to hold that axis constant. Returns -1 if the
2123// move would place the cursor outside the plane.
2124API int ncplane_cursor_move_yx(struct ncplane* n, int y, int x)
2125 __attribute__ ((nonnull (1)));
2126
2127// Move the cursor relative to the current cursor position (the cursor needn't
2128// be visible). Returns -1 on error, including target position exceeding the
2129// plane's dimensions.
2130API int ncplane_cursor_move_rel(struct ncplane* n, int y, int x)
2131 __attribute__ ((nonnull (1)));
2132
2133// Move the cursor to 0, 0. Can't fail.
2134API void ncplane_home(struct ncplane* n)
2135 __attribute__ ((nonnull (1)));
2136
2137// Get the current position of the cursor within n. y and/or x may be NULL.
2138API void ncplane_cursor_yx(const struct ncplane* n, unsigned* RESTRICT y, unsigned* RESTRICT x)
2139 __attribute__ ((nonnull (1)));
2140
2141static inline unsigned
2142ncplane_cursor_y(const struct ncplane* n){
2143 unsigned y;
2145 return y;
2146}
2147
2148static inline unsigned
2149ncplane_cursor_x(const struct ncplane* n){
2150 unsigned x;
2152 return x;
2153}
2154
2155// Get the current colors and alpha values for ncplane 'n'.
2156API uint64_t ncplane_channels(const struct ncplane* n)
2157 __attribute__ ((nonnull (1)));
2158
2159// Get the current styling for the ncplane 'n'.
2160API uint16_t ncplane_styles(const struct ncplane* n)
2161 __attribute__ ((nonnull (1)));
2162
2163// Replace the cell at the specified coordinates with the provided cell 'c',
2164// and advance the cursor by the width of the cell (but not past the end of the
2165// plane). On success, returns the number of columns the cursor was advanced.
2166// 'c' must already be associated with 'n'. On failure, -1 is returned.
2167API int ncplane_putc_yx(struct ncplane* n, int y, int x, const nccell* c)
2168 __attribute__ ((nonnull (1, 4)));
2169
2170// Call ncplane_putc_yx() for the current cursor location.
2171static inline int
2172ncplane_putc(struct ncplane* n, const nccell* c){
2173 return ncplane_putc_yx(n, -1, -1, c);
2174}
2175
2176// Replace the cell at the specified coordinates with the provided 7-bit char
2177// 'c'. Advance the cursor by 1. On success, returns the number of columns the
2178// cursor was advanced. On failure, returns -1. This works whether the
2179// underlying char is signed or unsigned.
2180static inline int
2181ncplane_putchar_yx(struct ncplane* n, int y, int x, char c){
2183 return ncplane_putc_yx(n, y, x, &ce);
2184}
2185
2186// Call ncplane_putchar_yx() at the current cursor location.
2187static inline int
2188ncplane_putchar(struct ncplane* n, char c){
2189 return ncplane_putchar_yx(n, -1, -1, c);
2190}
2191
2192// Replace the EGC underneath us, but retain the styling. The current styling
2193// of the plane will not be changed.
2194API int ncplane_putchar_stained(struct ncplane* n, char c)
2195 __attribute__ ((nonnull (1)));
2196
2197// Replace the cell at the specified coordinates with the provided EGC, and
2198// advance the cursor by the width of the cluster (but not past the end of the
2199// plane). On success, returns the number of columns the cursor was advanced.
2200// On failure, -1 is returned. The number of bytes converted from gclust is
2201// written to 'sbytes' if non-NULL.
2202API int ncplane_putegc_yx(struct ncplane* n, int y, int x, const char* gclust,
2203 size_t* sbytes)
2204 __attribute__ ((nonnull (1, 4)));
2205
2206// Call ncplane_putegc_yx() at the current cursor location.
2207static inline int
2208ncplane_putegc(struct ncplane* n, const char* gclust, size_t* sbytes){
2209 return ncplane_putegc_yx(n, -1, -1, gclust, sbytes);
2210}
2211
2212// Replace the EGC underneath us, but retain the styling. The current styling
2213// of the plane will not be changed.
2214API int ncplane_putegc_stained(struct ncplane* n, const char* gclust, size_t* sbytes)
2215 __attribute__ ((nonnull (1, 2)));
2216
2217// generate a heap-allocated UTF-8 encoding of the wide string 'src'.
2218ALLOC static inline char*
2219ncwcsrtombs(const wchar_t* src){
2220 mbstate_t ps;
2221 memset(&ps, 0, sizeof(ps));
2222 size_t mbytes = wcsrtombs(NULL, &src, 0, &ps);
2223 if(mbytes == (size_t)-1){
2224 return NULL;
2225 }
2226 ++mbytes;
2227 char* mbstr = (char*)malloc(mbytes); // need cast for c++ callers
2228 if(mbstr == NULL){
2229 return NULL;
2230 }
2231 size_t s = wcsrtombs(mbstr, &src, mbytes, &ps);
2232 if(s == (size_t)-1){
2233 free(mbstr);
2234 return NULL;
2235 }
2236 return mbstr;
2237}
2238
2239// ncplane_putegc(), but following a conversion from wchar_t to UTF-8 multibyte.
2240static inline int
2241ncplane_putwegc(struct ncplane* n, const wchar_t* gclust, size_t* sbytes){
2242 char* mbstr = ncwcsrtombs(gclust);
2243 if(mbstr == NULL){
2244 return -1;
2245 }
2246 int ret = ncplane_putegc(n, mbstr, sbytes);
2247 free(mbstr);
2248 return ret;
2249}
2250
2251// Call ncplane_putwegc() after successfully moving to y, x.
2252static inline int
2253ncplane_putwegc_yx(struct ncplane* n, int y, int x, const wchar_t* gclust,
2254 size_t* sbytes){
2255 if(ncplane_cursor_move_yx(n, y, x)){
2256 return -1;
2257 }
2258 return ncplane_putwegc(n, gclust, sbytes);
2259}
2260
2261// Replace the EGC underneath us, but retain the styling. The current styling
2262// of the plane will not be changed.
2263API int ncplane_putwegc_stained(struct ncplane* n, const wchar_t* gclust, size_t* sbytes)
2264 __attribute__ ((nonnull (1, 2)));
2265
2266// Write a series of EGCs to the current location, using the current style.
2267// They will be interpreted as a series of columns (according to the definition
2268// of ncplane_putc()). Advances the cursor by some positive number of columns
2269// (though not beyond the end of the plane); this number is returned on success.
2270// On error, a non-positive number is returned, indicating the number of columns
2271// which were written before the error.
2272static inline int
2273ncplane_putstr_yx(struct ncplane* n, int y, int x, const char* gclusters){
2274 int ret = 0;
2275 while(*gclusters){
2276 size_t wcs;
2277 int cols = ncplane_putegc_yx(n, y, x, gclusters, &wcs);
2278//fprintf(stderr, "wrote %.*s %d cols %zu bytes\n", (int)wcs, gclusters, cols, wcs);
2279 if(cols < 0){
2280 return -ret;
2281 }
2282 if(wcs == 0){
2283 break;
2284 }
2285 // after the first iteration, just let the cursor code control where we
2286 // print, so that scrolling is taken into account
2287 y = -1;
2288 x = -1;
2289 gclusters += wcs;
2290 ret += cols;
2291 }
2292 return ret;
2293}
2294
2295static inline int
2296ncplane_putstr(struct ncplane* n, const char* gclustarr){
2297 return ncplane_putstr_yx(n, -1, -1, gclustarr);
2298}
2299
2300static inline int
2301ncplane_putstr_aligned(struct ncplane* n, int y, ncalign_e align, const char* s){
2302 int validbytes, validwidth;
2303 // we'll want to do the partial write if there's an error somewhere within
2304 ncstrwidth(s, &validbytes, &validwidth);
2305 int xpos = ncplane_halign(n, align, validwidth);
2306 if(xpos < 0){
2307 xpos = 0;
2308 }
2309 return ncplane_putstr_yx(n, y, xpos, s);
2310}
2311
2312// Replace a string's worth of glyphs at the current cursor location, but
2313// retain the styling. The current styling of the plane will not be changed.
2314static inline int
2315ncplane_putstr_stained(struct ncplane* n, const char* gclusters){
2316 int ret = 0;
2317 while(*gclusters){
2318 size_t wcs;
2319 int cols = ncplane_putegc_stained(n, gclusters, &wcs);
2320 if(cols < 0){
2321 return -ret;
2322 }
2323 if(wcs == 0){
2324 break;
2325 }
2326 gclusters += wcs;
2327 ret += cols;
2328 }
2329 return ret;
2330}
2331
2332API int ncplane_putnstr_aligned(struct ncplane* n, int y, ncalign_e align, size_t s, const char* str)
2333 __attribute__ ((nonnull (1, 5)));
2334
2335// Write a series of EGCs to the current location, using the current style.
2336// They will be interpreted as a series of columns (according to the definition
2337// of ncplane_putc()). Advances the cursor by some positive number of columns
2338// (though not beyond the end of the plane); this number is returned on success.
2339// On error, a non-positive number is returned, indicating the number of columns
2340// which were written before the error. No more than 's' bytes will be written.
2341static inline int
2342ncplane_putnstr_yx(struct ncplane* n, int y, int x, size_t s, const char* gclusters){
2343 int ret = 0;
2344 size_t offset = 0;
2345//fprintf(stderr, "PUT %zu at %d/%d [%.*s]\n", s, y, x, (int)s, gclusters);
2346 while(offset < s && gclusters[offset]){
2347 size_t wcs;
2348 int cols = ncplane_putegc_yx(n, y, x, gclusters + offset, &wcs);
2349 if(cols < 0){
2350 return -ret;
2351 }
2352 if(wcs == 0){
2353 break;
2354 }
2355 // after the first iteration, just let the cursor code control where we
2356 // print, so that scrolling is taken into account
2357 y = -1;
2358 x = -1;
2359 offset += wcs;
2360 ret += cols;
2361 }
2362 return ret;
2363}
2364
2365static inline int
2366ncplane_putnstr(struct ncplane* n, size_t s, const char* gclustarr){
2367 return ncplane_putnstr_yx(n, -1, -1, s, gclustarr);
2368}
2369
2370// ncplane_putstr(), but following a conversion from wchar_t to UTF-8 multibyte.
2371// FIXME do this as a loop over ncplane_putegc_yx and save the big allocation+copy
2372static inline int
2373ncplane_putwstr_yx(struct ncplane* n, int y, int x, const wchar_t* gclustarr){
2374 // maximum of six UTF8-encoded bytes per wchar_t
2375 const size_t mbytes = (wcslen(gclustarr) * WCHAR_MAX_UTF8BYTES) + 1;
2376 char* mbstr = (char*)malloc(mbytes); // need cast for c++ callers
2377 if(mbstr == NULL){
2378 return -1;
2379 }
2380 mbstate_t ps;
2381 memset(&ps, 0, sizeof(ps));
2382 const wchar_t** gend = &gclustarr;
2383 size_t s = wcsrtombs(mbstr, gend, mbytes, &ps);
2384 if(s == (size_t)-1){
2385 free(mbstr);
2386 return -1;
2387 }
2388 int ret = ncplane_putstr_yx(n, y, x, mbstr);
2389 free(mbstr);
2390 return ret;
2391}
2392
2393static inline int
2394ncplane_putwstr_aligned(struct ncplane* n, int y, ncalign_e align,
2395 const wchar_t* gclustarr){
2396 int width = wcswidth(gclustarr, INT_MAX);
2397 int xpos = ncplane_halign(n, align, width);
2398 if(xpos < 0){
2399 xpos = 0;
2400 }
2401 return ncplane_putwstr_yx(n, y, xpos, gclustarr);
2402}
2403
2404API int ncplane_putwstr_stained(struct ncplane* n, const wchar_t* gclustarr)
2405 __attribute__ ((nonnull (1, 2)));
2406
2407static inline int
2408ncplane_putwstr(struct ncplane* n, const wchar_t* gclustarr){
2409 return ncplane_putwstr_yx(n, -1, -1, gclustarr);
2410}
2411
2412// Replace the cell at the specified coordinates with the provided UTF-32
2413// 'u'. Advance the cursor by the character's width as reported by wcwidth().
2414// On success, returns the number of columns written. On failure, returns -1.
2415static inline int
2416ncplane_pututf32_yx(struct ncplane* n, int y, int x, uint32_t u){
2417 if(u > WCHAR_MAX){
2418 return -1;
2419 }
2420 // we use MB_LEN_MAX (and potentially "waste" a few stack bytes to avoid
2421 // the greater sin of a VLA (and to be locale-independent).
2422 char utf8c[MB_LEN_MAX + 1];
2423 mbstate_t ps;
2424 memset(&ps, 0, sizeof(ps));
2425 // this isn't going to be valid for reconstructued surrogate pairs...
2426 // we need our own, or to use unistring or something.
2427 size_t s = wcrtomb(utf8c, (wchar_t)u, &ps);
2428 if(s == (size_t)-1){
2429 return -1;
2430 }
2431 utf8c[s] = '\0';
2432 return ncplane_putegc_yx(n, y, x, utf8c, NULL);
2433}
2434
2435static inline int
2436ncplane_putwc_yx(struct ncplane* n, int y, int x, wchar_t w){
2437 return ncplane_pututf32_yx(n, y, x, (uint32_t)w);
2438}
2439
2440// Write 'w' at the current cursor position, using the plane's current styling.
2441static inline int
2442ncplane_putwc(struct ncplane* n, wchar_t w){
2443 return ncplane_putwc_yx(n, -1, -1, w);
2444}
2445
2446// Write the first Unicode character from 'w' at the current cursor position,
2447// using the plane's current styling. In environments where wchar_t is only
2448// 16 bits (Windows, essentially), a single Unicode might require two wchar_t
2449// values forming a surrogate pair. On environments with 32-bit wchar_t, this
2450// should not happen. If w[0] is a surrogate, it is decoded together with
2451// w[1], and passed as a single reconstructed UTF-32 character to
2452// ncplane_pututf32(); 'wchars' will get a value of 2 in this case. 'wchars'
2453// otherwise gets a value of 1. A surrogate followed by an invalid pairing
2454// will set 'wchars' to 2, but return -1 immediately.
2455static inline int
2456ncplane_putwc_utf32(struct ncplane* n, const wchar_t* w, unsigned* wchars){
2457 uint32_t utf32;
2458 if(*w >= 0xd000 && *w <= 0xdbff){
2459 *wchars = 2;
2460 if(w[1] < 0xdc00 || w[1] > 0xdfff){
2461 return -1; // invalid surrogate pairing
2462 }
2463 utf32 = (w[0] & 0x3fflu) << 10lu;
2464 utf32 += (w[1] & 0x3fflu);
2465 }else{
2466 *wchars = 1;
2467 utf32 = (uint32_t)*w;
2468 }
2469 return ncplane_pututf32_yx(n, -1, -1, utf32);
2470}
2471
2472// Write 'w' at the current cursor position, using any preexisting styling
2473// at that cell.
2474static inline int
2475ncplane_putwc_stained(struct ncplane* n, wchar_t w){
2476 wchar_t warr[2] = { w, L'\0' };
2477 return ncplane_putwstr_stained(n, warr);
2478}
2479
2480// The ncplane equivalents of printf(3) and vprintf(3).
2482 const char* format, va_list ap)
2483 __attribute__ ((nonnull (1, 4)))
2484 __attribute__ ((format (printf, 4, 0)));
2485
2486API int ncplane_vprintf_yx(struct ncplane* n, int y, int x,
2487 const char* format, va_list ap)
2488 __attribute__ ((nonnull (1, 4)))
2489 __attribute__ ((format (printf, 4, 0)));
2490
2491static inline int
2492ncplane_vprintf(struct ncplane* n, const char* format, va_list ap){
2493 return ncplane_vprintf_yx(n, -1, -1, format, ap);
2494}
2495
2496API int ncplane_vprintf_stained(struct ncplane* n, const char* format, va_list ap)
2497 __attribute__ ((nonnull (1, 2)))
2498 __attribute__ ((format (printf, 2, 0)));
2499
2500static inline int
2501ncplane_printf(struct ncplane* n, const char* format, ...)
2502 __attribute__ ((nonnull (1, 2)))
2503 __attribute__ ((format (printf, 2, 3)));
2504
2505static inline int
2506ncplane_printf(struct ncplane* n, const char* format, ...){
2507 va_list va;
2508 va_start(va, format);
2509 int ret = ncplane_vprintf(n, format, va);
2510 va_end(va);
2511 return ret;
2512}
2513
2514static inline int
2515ncplane_printf_yx(struct ncplane* n, int y, int x, const char* format, ...)
2516 __attribute__ ((nonnull (1, 4))) __attribute__ ((format (printf, 4, 5)));
2517
2518static inline int
2519ncplane_printf_yx(struct ncplane* n, int y, int x, const char* format, ...){
2520 va_list va;
2521 va_start(va, format);
2522 int ret = ncplane_vprintf_yx(n, y, x, format, va);
2523 va_end(va);
2524 return ret;
2525}
2526
2527static inline int
2528ncplane_printf_aligned(struct ncplane* n, int y, ncalign_e align,
2529 const char* format, ...)
2530 __attribute__ ((nonnull (1, 4))) __attribute__ ((format (printf, 4, 5)));
2531
2532static inline int
2533ncplane_printf_aligned(struct ncplane* n, int y, ncalign_e align, const char* format, ...){
2534 va_list va;
2535 va_start(va, format);
2536 int ret = ncplane_vprintf_aligned(n, y, align, format, va);
2537 va_end(va);
2538 return ret;
2539}
2540
2541static inline int
2542ncplane_printf_stained(struct ncplane* n, const char* format, ...)
2543 __attribute__ ((nonnull (1, 2))) __attribute__ ((format (printf, 2, 3)));
2544
2545static inline int
2546ncplane_printf_stained(struct ncplane* n, const char* format, ...){
2547 va_list va;
2548 va_start(va, format);
2549 int ret = ncplane_vprintf_stained(n, format, va);
2550 va_end(va);
2551 return ret;
2552}
2553
2554// Write the specified text to the plane, breaking lines sensibly, beginning at
2555// the specified line. Returns the number of columns written. When breaking a
2556// line, the line will be cleared to the end of the plane (the last line will
2557// *not* be so cleared). The number of bytes written from the input is written
2558// to '*bytes' if it is not NULL. Cleared columns are included in the return
2559// value, but *not* included in the number of bytes written. Leaves the cursor
2560// at the end of output. A partial write will be accomplished as far as it can;
2561// determine whether the write completed by inspecting '*bytes'. Can output to
2562// multiple rows even in the absence of scrolling, but not more rows than are
2563// available. With scrolling enabled, arbitrary amounts of data can be emitted.
2564// All provided whitespace is preserved -- ncplane_puttext() followed by an
2565// appropriate ncplane_contents() will read back the original output.
2566//
2567// If 'y' is -1, the first row of output is taken relative to the current
2568// cursor: it will be left-, right-, or center-aligned in whatever remains
2569// of the row. On subsequent rows -- or if 'y' is not -1 -- the entire row can
2570// be used, and alignment works normally.
2571//
2572// A newline at any point will move the cursor to the next row.
2573API int ncplane_puttext(struct ncplane* n, int y, ncalign_e align,
2574 const char* text, size_t* bytes)
2575 __attribute__ ((nonnull (1, 4)));
2576
2577// Draw horizontal or vertical lines using the specified cell, starting at the
2578// current cursor position. The cursor will end at the cell following the last
2579// cell output (even, perhaps counter-intuitively, when drawing vertical
2580// lines), just as if ncplane_putc() was called at that spot. Return the
2581// number of cells drawn on success. On error, return the negative number of
2582// cells drawn. A length of 0 is an error, resulting in a return of -1.
2584 unsigned len, uint64_t c1, uint64_t c2)
2585 __attribute__ ((nonnull (1, 2)));
2586
2587__attribute__ ((nonnull (1, 2))) static inline int
2588ncplane_hline(struct ncplane* n, const nccell* c, unsigned len){
2590}
2591
2593 unsigned len, uint64_t c1, uint64_t c2)
2594 __attribute__ ((nonnull (1, 2)));
2595
2596__attribute__ ((nonnull (1, 2))) static inline int
2597ncplane_vline(struct ncplane* n, const nccell* c, unsigned len){
2599}
2600
2601#define NCBOXMASK_TOP 0x0001
2602#define NCBOXMASK_RIGHT 0x0002
2603#define NCBOXMASK_BOTTOM 0x0004
2604#define NCBOXMASK_LEFT 0x0008
2605#define NCBOXGRAD_TOP 0x0010
2606#define NCBOXGRAD_RIGHT 0x0020
2607#define NCBOXGRAD_BOTTOM 0x0040
2608#define NCBOXGRAD_LEFT 0x0080
2609#define NCBOXCORNER_MASK 0x0300
2610#define NCBOXCORNER_SHIFT 8u
2611
2612// Draw a box with its upper-left corner at the current cursor position, and its
2613// lower-right corner at 'ystop'x'xstop'. The 6 cells provided are used to draw the
2614// upper-left, ur, ll, and lr corners, then the horizontal and vertical lines.
2615// 'ctlword' is defined in the least significant byte, where bits [7, 4] are a
2616// gradient mask, and [3, 0] are a border mask:
2617// * 7, 3: top
2618// * 6, 2: right
2619// * 5, 1: bottom
2620// * 4, 0: left
2621// If the gradient bit is not set, the styling from the hl/vl cells is used for
2622// the horizontal and vertical lines, respectively. If the gradient bit is set,
2623// the color is linearly interpolated between the two relevant corner cells.
2624//
2625// By default, vertexes are drawn whether their connecting edges are drawn or
2626// not. The value of the bits corresponding to NCBOXCORNER_MASK control this,
2627// and are interpreted as the number of connecting edges necessary to draw a
2628// given corner. At 0 (the default), corners are always drawn. At 3, corners
2629// are never drawn (since at most 2 edges can touch a box's corner).
2630API int ncplane_box(struct ncplane* n, const nccell* ul, const nccell* ur,
2631 const nccell* ll, const nccell* lr, const nccell* hline,
2632 const nccell* vline, unsigned ystop, unsigned xstop,
2633 unsigned ctlword);
2634
2635// Draw a box with its upper-left corner at the current cursor position, having
2636// dimensions 'ylen'x'xlen'. See ncplane_box() for more information. The
2637// minimum box size is 2x2, and it cannot be drawn off-plane.
2638static inline int
2639ncplane_box_sized(struct ncplane* n, const nccell* ul, const nccell* ur,
2640 const nccell* ll, const nccell* lr, const nccell* hline,
2641 const nccell* vline, unsigned ystop, unsigned xstop,
2642 unsigned ctlword){
2643 unsigned y, x;
2644 ncplane_cursor_yx(n, &y, &x);
2645 return ncplane_box(n, ul, ur, ll, lr, hline, vline, y + ystop - 1,
2646 x + xstop - 1, ctlword);
2647}
2648
2649static inline int
2650ncplane_perimeter(struct ncplane* n, const nccell* ul, const nccell* ur,
2651 const nccell* ll, const nccell* lr, const nccell* hline,
2652 const nccell* vline, unsigned ctlword){
2653 if(ncplane_cursor_move_yx(n, 0, 0)){
2654 return -1;
2655 }
2656 unsigned dimy, dimx;
2657 ncplane_dim_yx(n, &dimy, &dimx);
2658 return ncplane_box_sized(n, ul, ur, ll, lr, hline, vline, dimy, dimx, ctlword);
2659}
2660
2661// Starting at the specified coordinate, if its glyph is different from that of
2662// 'c', 'c' is copied into it, and the original glyph is considered the fill
2663// target. We do the same to all cardinally-connected cells having this same
2664// fill target. Returns the number of cells polyfilled. An invalid initial y, x
2665// is an error. Returns the number of cells filled, or -1 on error. Does
2666// not update cursor position.
2667API int ncplane_polyfill_yx(struct ncplane* n, int y, int x, const nccell* c)
2668 __attribute__ ((nonnull (1, 4)));
2669
2670// Draw a gradient with its upper-left corner at the position specified by 'y'/'x',
2671// where -1 means the current cursor position in that dimension. The area is
2672// specified by 'ylen'/'xlen', where 0 means "everything remaining below or
2673// to the right, respectively." The glyph composed of 'egc' and 'styles' is
2674// used for all cells. The channels specified by 'ul', 'ur', 'll', and 'lr'
2675// are composed into foreground and background gradients. To do a vertical
2676// gradient, 'ul' ought equal 'ur' and 'll' ought equal 'lr'. To do a
2677// horizontal gradient, 'ul' ought equal 'll' and 'ur' ought equal 'ul'. To
2678// color everything the same, all four channels should be equivalent. The
2679// resulting alpha values are equal to incoming alpha values. Returns the
2680// number of cells filled on success, or -1 on failure.
2681// Palette-indexed color is not supported. Does not update cursor position.
2682//
2683// Preconditions for gradient operations (error otherwise):
2684//
2685// all: only RGB colors, unless all four channels match as default
2686// all: all alpha values must be the same
2687// 1x1: all four colors must be the same
2688// 1xN: both top and both bottom colors must be the same (vertical gradient)
2689// Nx1: both left and both right colors must be the same (horizontal gradient)
2690API int ncplane_gradient(struct ncplane* n, int y, int x, unsigned ylen,
2691 unsigned xlen, const char* egc, uint16_t styles,
2692 uint64_t ul, uint64_t ur, uint64_t ll, uint64_t lr)
2693 __attribute__ ((nonnull (1, 6)));
2694
2695// Do a high-resolution gradient using upper blocks and synced backgrounds.
2696// This doubles the number of vertical gradations, but restricts you to
2697// half blocks (appearing to be full blocks). Returns the number of cells
2698// filled on success, or -1 on error. Does not update cursor position.
2699API int ncplane_gradient2x1(struct ncplane* n, int y, int x, unsigned ylen,
2700 unsigned xlen, uint32_t ul, uint32_t ur,
2701 uint32_t ll, uint32_t lr)
2702 __attribute__ ((nonnull (1)));
2703
2704// Set the given style throughout the specified region, keeping content and
2705// channels unchanged. The upper left corner is at 'y', 'x', and -1 may be
2706// specified to indicate the cursor's position in that dimension. The area
2707// is specified by 'ylen', 'xlen', and 0 may be specified to indicate everything
2708// remaining to the right and below, respectively. It is an error for any
2709// coordinate to be outside the plane. Returns the number of cells set,
2710// or -1 on failure. Does not update the cursor position.
2711API int ncplane_format(struct ncplane* n, int y, int x, unsigned ylen,
2712 unsigned xlen, uint16_t stylemask)
2713 __attribute__ ((nonnull (1)));
2714
2715// Set the given channels throughout the specified region, keeping content and
2716// channels unchanged. The upper left corner is at 'y', 'x', and -1 may be
2717// specified to indicate the cursor's position in that dimension. The area
2718// is specified by 'ylen', 'xlen', and 0 may be specified to indicate everything
2719// remaining to the right and below, respectively. It is an error for any
2720// coordinate to be outside the plane. Returns the number of cells set,
2721// or -1 on failure. Does not update the cursor position.
2722API int ncplane_stain(struct ncplane* n, int y, int x, unsigned ylen,
2723 unsigned xlen, uint64_t ul, uint64_t ur,
2724 uint64_t ll, uint64_t lr)
2725 __attribute__ ((nonnull (1)));
2726
2727// Merge the entirety of 'src' down onto the ncplane 'dst'. If 'src' does not
2728// intersect with 'dst', 'dst' will not be changed, but it is not an error.
2730 struct ncplane* RESTRICT dst)
2731 __attribute__ ((nonnull (1, 2)));
2732
2733// Merge the ncplane 'src' down onto the ncplane 'dst'. This is most rigorously
2734// defined as "write to 'dst' the frame that would be rendered were the entire
2735// stack made up only of the specified subregion of 'src' and, below it, the
2736// subregion of 'dst' having the specified origin. Supply -1 to indicate the
2737// current cursor position in the relevant dimension. Merging is independent of
2738// the position of 'src' viz 'dst' on the z-axis. It is an error to define a
2739// subregion that is not entirely contained within 'src'. It is an error to
2740// define a target origin such that the projected subregion is not entirely
2741// contained within 'dst'. Behavior is undefined if 'src' and 'dst' are
2742// equivalent. 'dst' is modified, but 'src' remains unchanged. Neither 'src'
2743// nor 'dst' may have sprixels. Lengths of 0 mean "everything left".
2745 struct ncplane* RESTRICT dst,
2746 int begsrcy, int begsrcx,
2747 unsigned leny, unsigned lenx,
2748 int dsty, int dstx)
2749 __attribute__ ((nonnull (1, 2)));
2750
2751// Erase every cell in the ncplane (each cell is initialized to the null glyph
2752// and the default channels/styles). All cells associated with this ncplane are
2753// invalidated, and must not be used after the call, *excluding* the base cell.
2754// The cursor is homed. The plane's active attributes are unaffected.
2755API void ncplane_erase(struct ncplane* n)
2756 __attribute__ ((nonnull (1)));
2757
2758// Erase every cell in the region starting at {ystart, xstart} and having size
2759// {|ylen|x|xlen|} for non-zero lengths. If ystart and/or xstart are -1, the current
2760// cursor position along that axis is used; other negative values are an error. A
2761// negative ylen means to move up from the origin, and a negative xlen means to move
2762// left from the origin. A positive ylen moves down, and a positive xlen moves right.
2763// A value of 0 for the length erases everything along that dimension. It is an error
2764// if the starting coordinate is not in the plane, but the ending coordinate may be
2765// outside the plane.
2766//
2767// For example, on a plane of 20 rows and 10 columns, with the cursor at row 10 and
2768// column 5, the following would hold:
2769//
2770// (-1, -1, 0, 1): clears the column to the right of the cursor (column 6)
2771// (-1, -1, 0, -1): clears the column to the left of the cursor (column 4)
2772// (-1, -1, INT_MAX, 0): clears all rows with or below the cursor (rows 10--19)
2773// (-1, -1, -INT_MAX, 0): clears all rows with or above the cursor (rows 0--10)
2774// (-1, 4, 3, 3): clears from row 5, column 4 through row 7, column 6
2775// (-1, 4, -3, -3): clears from row 5, column 4 through row 3, column 2
2776// (4, -1, 0, 3): clears columns 5, 6, and 7
2777// (-1, -1, 0, 0): clears the plane *if the cursor is in a legal position*
2778// (0, 0, 0, 0): clears the plane in all cases
2779API int ncplane_erase_region(struct ncplane* n, int ystart, int xstart,
2780 int ylen, int xlen)
2781 __attribute__ ((nonnull (1)));
2782
2783// Extract 24 bits of foreground RGB from 'cl', shifted to LSBs.
2784static inline uint32_t
2785nccell_fg_rgb(const nccell* cl){
2786 return ncchannels_fg_rgb(cl->channels);
2787}
2788
2789// Extract 24 bits of background RGB from 'cl', shifted to LSBs.
2790static inline uint32_t
2791nccell_bg_rgb(const nccell* cl){
2792 return ncchannels_bg_rgb(cl->channels);
2793}
2794
2795// Extract 2 bits of foreground alpha from 'cl', shifted to LSBs.
2796static inline uint32_t
2797nccell_fg_alpha(const nccell* cl){
2798 return ncchannels_fg_alpha(cl->channels);
2799}
2800
2801// Extract 2 bits of background alpha from 'cl', shifted to LSBs.
2802static inline uint32_t
2803nccell_bg_alpha(const nccell* cl){
2804 return ncchannels_bg_alpha(cl->channels);
2805}
2806
2807// Extract 24 bits of foreground RGB from 'cl', split into components.
2808static inline uint32_t
2809nccell_fg_rgb8(const nccell* cl, unsigned* r, unsigned* g, unsigned* b){
2810 return ncchannels_fg_rgb8(cl->channels, r, g, b);
2811}
2812
2813// Extract 24 bits of background RGB from 'cl', split into components.
2814static inline uint32_t
2815nccell_bg_rgb8(const nccell* cl, unsigned* r, unsigned* g, unsigned* b){
2816 return ncchannels_bg_rgb8(cl->channels, r, g, b);
2817}
2818
2819// Set the r, g, and b cell for the foreground component of this 64-bit
2820// 'cl' variable, and mark it as not using the default color.
2821static inline int
2822nccell_set_fg_rgb8(nccell* cl, unsigned r, unsigned g, unsigned b){
2823 return ncchannels_set_fg_rgb8(&cl->channels, r, g, b);
2824}
2825
2826// Same, but clipped to [0..255].
2827static inline void
2828nccell_set_fg_rgb8_clipped(nccell* cl, int r, int g, int b){
2829 ncchannels_set_fg_rgb8_clipped(&cl->channels, r, g, b);
2830}
2831
2832// Same, but with an assembled 24-bit RGB value.
2833static inline int
2834nccell_set_fg_rgb(nccell* c, uint32_t channel){
2835 return ncchannels_set_fg_rgb(&c->channels, channel);
2836}
2837
2838// Set the cell's foreground palette index, set the foreground palette index
2839// bit, set it foreground-opaque, and clear the foreground default color bit.
2840static inline int
2841nccell_set_fg_palindex(nccell* cl, unsigned idx){
2842 return ncchannels_set_fg_palindex(&cl->channels, idx);
2843}
2844
2845static inline uint32_t
2846nccell_fg_palindex(const nccell* cl){
2847 return ncchannels_fg_palindex(cl->channels);
2848}
2849
2850// Set the r, g, and b cell for the background component of this 64-bit
2851// 'cl' variable, and mark it as not using the default color.
2852static inline int
2853nccell_set_bg_rgb8(nccell* cl, unsigned r, unsigned g, unsigned b){
2854 return ncchannels_set_bg_rgb8(&cl->channels, r, g, b);
2855}
2856
2857// Same, but clipped to [0..255].
2858static inline void
2859nccell_set_bg_rgb8_clipped(nccell* cl, int r, int g, int b){
2860 ncchannels_set_bg_rgb8_clipped(&cl->channels, r, g, b);
2861}
2862
2863// Same, but with an assembled 24-bit RGB value. A value over 0xffffff
2864// will be rejected, with a non-zero return value.
2865static inline int
2866nccell_set_bg_rgb(nccell* c, uint32_t channel){
2867 return ncchannels_set_bg_rgb(&c->channels, channel);
2868}
2869
2870// Set the cell's background palette index, set the background palette index
2871// bit, set it background-opaque, and clear the background default color bit.
2872static inline int
2873nccell_set_bg_palindex(nccell* cl, unsigned idx){
2874 return ncchannels_set_bg_palindex(&cl->channels, idx);
2875}
2876
2877static inline uint32_t
2878nccell_bg_palindex(const nccell* cl){
2879 return ncchannels_bg_palindex(cl->channels);
2880}
2881
2882// Is the foreground using the "default foreground color"?
2883static inline bool
2884nccell_fg_default_p(const nccell* cl){
2885 return ncchannels_fg_default_p(cl->channels);
2886}
2887
2888static inline bool
2889nccell_fg_palindex_p(const nccell* cl){
2890 return ncchannels_fg_palindex_p(cl->channels);
2891}
2892
2893// Is the background using the "default background color"? The "default
2894// background color" must generally be used to take advantage of
2895// terminal-effected transparency.
2896static inline bool
2897nccell_bg_default_p(const nccell* cl){
2898 return ncchannels_bg_default_p(cl->channels);
2899}
2900
2901static inline bool
2902nccell_bg_palindex_p(const nccell* cl){
2903 return ncchannels_bg_palindex_p(cl->channels);
2904}
2905
2906// Extract the background alpha and coloring bits from a 64-bit channel
2907// pair as a single 32-bit value.
2908static inline uint32_t
2909ncplane_bchannel(const struct ncplane* n){
2910 return ncchannels_bchannel(ncplane_channels(n));
2911}
2912
2913// Extract the foreground alpha and coloring bits from a 64-bit channel
2914// pair as a single 32-bit value.
2915static inline uint32_t
2916ncplane_fchannel(const struct ncplane* n){
2917 return ncchannels_fchannel(ncplane_channels(n));
2918}
2919
2920// Set the alpha and coloring bits of the plane's current channels from a
2921// 64-bit pair of channels.
2922API void ncplane_set_channels(struct ncplane* n, uint64_t channels)
2923 __attribute__ ((nonnull (1)));
2924
2925// Set the background alpha and coloring bits of the plane's current
2926// channels from a single 32-bit value.
2927API uint64_t ncplane_set_bchannel(struct ncplane* n, uint32_t channel)
2928 __attribute__ ((nonnull (1)));
2929
2930// Set the foreground alpha and coloring bits of the plane's current
2931// channels from a single 32-bit value.
2932API uint64_t ncplane_set_fchannel(struct ncplane* n, uint32_t channel)
2933 __attribute__ ((nonnull (1)));
2934
2935// Set the specified style bits for the ncplane 'n', whether they're actively
2936// supported or not.
2937API void ncplane_set_styles(struct ncplane* n, unsigned stylebits)
2938 __attribute__ ((nonnull (1)));
2939
2940// Add the specified styles to the ncplane's existing spec.
2941API void ncplane_on_styles(struct ncplane* n, unsigned stylebits)
2942 __attribute__ ((nonnull (1)));
2943
2944// Remove the specified styles from the ncplane's existing spec.
2945API void ncplane_off_styles(struct ncplane* n, unsigned stylebits)
2946 __attribute__ ((nonnull (1)));
2947
2948// Extract 24 bits of working foreground RGB from an ncplane, shifted to LSBs.
2949static inline uint32_t
2950ncplane_fg_rgb(const struct ncplane* n){
2951 return ncchannels_fg_rgb(ncplane_channels(n));
2952}
2953
2954// Extract 24 bits of working background RGB from an ncplane, shifted to LSBs.
2955static inline uint32_t
2956ncplane_bg_rgb(const struct ncplane* n){
2957 return ncchannels_bg_rgb(ncplane_channels(n));
2958}
2959
2960// Extract 2 bits of foreground alpha from 'struct ncplane', shifted to LSBs.
2961static inline uint32_t
2962ncplane_fg_alpha(const struct ncplane* n){
2963 return ncchannels_fg_alpha(ncplane_channels(n));
2964}
2965
2966// Is the plane's foreground using the "default foreground color"?
2967static inline bool
2968ncplane_fg_default_p(const struct ncplane* n){
2969 return ncchannels_fg_default_p(ncplane_channels(n));
2970}
2971
2972// Extract 2 bits of background alpha from 'struct ncplane', shifted to LSBs.
2973static inline uint32_t
2974ncplane_bg_alpha(const struct ncplane* n){
2975 return ncchannels_bg_alpha(ncplane_channels(n));
2976}
2977
2978// Is the plane's background using the "default background color"?
2979static inline bool
2980ncplane_bg_default_p(const struct ncplane* n){
2981 return ncchannels_bg_default_p(ncplane_channels(n));
2982}
2983
2984// Extract 24 bits of foreground RGB from 'n', split into components.
2985static inline uint32_t
2986ncplane_fg_rgb8(const struct ncplane* n, unsigned* r, unsigned* g, unsigned* b){
2987 return ncchannels_fg_rgb8(ncplane_channels(n), r, g, b);
2988}
2989
2990// Extract 24 bits of background RGB from 'n', split into components.
2991static inline uint32_t
2992ncplane_bg_rgb8(const struct ncplane* n, unsigned* r, unsigned* g, unsigned* b){
2993 return ncchannels_bg_rgb8(ncplane_channels(n), r, g, b);
2994}
2995
2996// Set the current fore/background color using RGB specifications. If the
2997// terminal does not support directly-specified 3x8b cells (24-bit "TrueColor",
2998// indicated by the "RGB" terminfo capability), the provided values will be
2999// interpreted in some lossy fashion. None of r, g, or b may exceed 255.
3000// "HP-like" terminals require setting foreground and background at the same
3001// time using "color pairs"; Notcurses will manage color pairs transparently.
3002API int ncplane_set_fg_rgb8(struct ncplane* n, unsigned r, unsigned g, unsigned b);
3003API int ncplane_set_bg_rgb8(struct ncplane* n, unsigned r, unsigned g, unsigned b);
3004
3005// Same, but clipped to [0..255].
3006API void ncplane_set_bg_rgb8_clipped(struct ncplane* n, int r, int g, int b);
3007API void ncplane_set_fg_rgb8_clipped(struct ncplane* n, int r, int g, int b);
3008
3009// Same, but with rgb assembled into a channel (i.e. lower 24 bits).
3010API int ncplane_set_fg_rgb(struct ncplane* n, uint32_t channel);
3011API int ncplane_set_bg_rgb(struct ncplane* n, uint32_t channel);
3012
3013// Use the default color for the foreground/background.
3014API void ncplane_set_fg_default(struct ncplane* n);
3015API void ncplane_set_bg_default(struct ncplane* n);
3016
3017// Set the ncplane's foreground palette index, set the foreground palette index
3018// bit, set it foreground-opaque, and clear the foreground default color bit.
3019API int ncplane_set_fg_palindex(struct ncplane* n, unsigned idx);
3020API int ncplane_set_bg_palindex(struct ncplane* n, unsigned idx);
3021
3022// Set the alpha parameters for ncplane 'n'.
3023API int ncplane_set_fg_alpha(struct ncplane* n, int alpha);
3024API int ncplane_set_bg_alpha(struct ncplane* n, int alpha);
3025
3026// Called for each fade iteration on 'ncp'. If anything but 0 is returned,
3027// the fading operation ceases immediately, and that value is propagated out.
3028// The recommended absolute display time target is passed in 'tspec'.
3029typedef int (*fadecb)(struct notcurses* nc, struct ncplane* n,
3030 const struct timespec*, void* curry);
3031
3032// Fade the ncplane out over the provided time, calling 'fader' at each
3033// iteration. Requires a terminal which supports truecolor, or at least palette
3034// modification (if the terminal uses a palette, our ability to fade planes is
3035// limited, and affected by the complexity of the rest of the screen).
3036API int ncplane_fadeout(struct ncplane* n, const struct timespec* ts,
3037 fadecb fader, void* curry)
3038 __attribute__ ((nonnull (1)));
3039
3040// Fade the ncplane in over the specified time. Load the ncplane with the
3041// target cells without rendering, then call this function. When it's done, the
3042// ncplane will have reached the target levels, starting from zeroes.
3043API int ncplane_fadein(struct ncplane* n, const struct timespec* ts,
3044 fadecb fader, void* curry)
3045 __attribute__ ((nonnull (1)));
3046
3047// Rather than the simple ncplane_fade{in/out}(), ncfadectx_setup() can be
3048// paired with a loop over ncplane_fade{in/out}_iteration() + ncfadectx_free().
3049API ALLOC struct ncfadectx* ncfadectx_setup(struct ncplane* n)
3050 __attribute__ ((nonnull (1)));
3051
3052// Return the number of iterations through which 'nctx' will fade.
3053API int ncfadectx_iterations(const struct ncfadectx* nctx)
3054 __attribute__ ((nonnull (1)));
3055
3056// Fade out through 'iter' iterations, where
3057// 'iter' < 'ncfadectx_iterations(nctx)'.
3059 int iter, fadecb fader, void* curry)
3060 __attribute__ ((nonnull (1, 2)));
3061
3062// Fade in through 'iter' iterations, where
3063// 'iter' < 'ncfadectx_iterations(nctx)'.
3065 int iter, fadecb fader, void* curry)
3066 __attribute__ ((nonnull (1, 2)));
3067
3068// Pulse the plane in and out until the callback returns non-zero, relying on
3069// the callback 'fader' to initiate rendering. 'ts' defines the half-period
3070// (i.e. the transition from black to full brightness, or back again). Proper
3071// use involves preparing (but not rendering) an ncplane, then calling
3072// ncplane_pulse(), which will fade in from black to the specified colors.
3073API int ncplane_pulse(struct ncplane* n, const struct timespec* ts, fadecb fader, void* curry)
3074 __attribute__ ((nonnull (1)));
3075
3076// Release the resources associated with 'nctx'.
3077API void ncfadectx_free(struct ncfadectx* nctx);
3078
3079// load up six cells with the EGCs necessary to draw a box. returns 0 on
3080// success, -1 on error. on error, any cells this function might
3081// have loaded before the error are nccell_release()d. There must be at least
3082// six EGCs in gcluster.
3083static inline int
3084nccells_load_box(struct ncplane* n, uint16_t styles, uint64_t channels,
3086 nccell* hl, nccell* vl, const char* gclusters){
3087 int ulen;
3088 if((ulen = nccell_prime(n, ul, gclusters, styles, channels)) > 0){
3089 if((ulen = nccell_prime(n, ur, gclusters += ulen, styles, channels)) > 0){
3090 if((ulen = nccell_prime(n, ll, gclusters += ulen, styles, channels)) > 0){
3091 if((ulen = nccell_prime(n, lr, gclusters += ulen, styles, channels)) > 0){
3092 if((ulen = nccell_prime(n, hl, gclusters += ulen, styles, channels)) > 0){
3093 if(nccell_prime(n, vl, gclusters + ulen, styles, channels) > 0){
3094 return 0;
3095 }
3096 nccell_release(n, hl);
3097 }
3099 }
3101 }
3103 }
3105 }
3106 return -1;
3107}
3108
3109static inline int
3110nccells_ascii_box(struct ncplane* n, uint16_t attr, uint64_t channels,
3111 nccell* ul, nccell* ur, nccell* ll, nccell* lr, nccell* hl, nccell* vl){
3112 return nccells_load_box(n, attr, channels, ul, ur, ll, lr, hl, vl, NCBOXASCII);
3113}
3114
3115static inline int
3116nccells_double_box(struct ncplane* n, uint16_t attr, uint64_t channels,
3117 nccell* ul, nccell* ur, nccell* ll, nccell* lr, nccell* hl, nccell* vl){
3118 if(notcurses_canutf8(ncplane_notcurses(n))){
3119 return nccells_load_box(n, attr, channels, ul, ur, ll, lr, hl, vl, NCBOXDOUBLE);
3120 }
3121 return nccells_ascii_box(n, attr, channels, ul, ur, ll, lr, hl, vl);
3122}
3123
3124static inline int
3125nccells_rounded_box(struct ncplane* n, uint16_t attr, uint64_t channels,
3126 nccell* ul, nccell* ur, nccell* ll, nccell* lr, nccell* hl, nccell* vl){
3127 if(notcurses_canutf8(ncplane_notcurses(n))){
3128 return nccells_load_box(n, attr, channels, ul, ur, ll, lr, hl, vl, NCBOXROUND);
3129 }
3130 return nccells_ascii_box(n, attr, channels, ul, ur, ll, lr, hl, vl);
3131}
3132
3133static inline int
3134nccells_light_box(struct ncplane* n, uint16_t attr, uint64_t channels,
3135 nccell* ul, nccell* ur, nccell* ll, nccell* lr, nccell* hl, nccell* vl){
3136 if(notcurses_canutf8(ncplane_notcurses(n))){
3137 return nccells_load_box(n, attr, channels, ul, ur, ll, lr, hl, vl, NCBOXLIGHT);
3138 }
3139 return nccells_ascii_box(n, attr, channels, ul, ur, ll, lr, hl, vl);
3140}
3141
3142static inline int
3143nccells_heavy_box(struct ncplane* n, uint16_t attr, uint64_t channels,
3144 nccell* ul, nccell* ur, nccell* ll, nccell* lr, nccell* hl, nccell* vl){
3145 if(notcurses_canutf8(ncplane_notcurses(n))){
3146 return nccells_load_box(n, attr, channels, ul, ur, ll, lr, hl, vl, NCBOXHEAVY);
3147 }
3148 return nccells_ascii_box(n, attr, channels, ul, ur, ll, lr, hl, vl);
3149}
3150
3151static inline int
3152ncplane_rounded_box(struct ncplane* n, uint16_t styles, uint64_t channels,
3153 unsigned ystop, unsigned xstop, unsigned ctlword){
3154 int ret = 0;
3158 if((ret = nccells_rounded_box(n, styles, channels, &ul, &ur, &ll, &lr, &hl, &vl)) == 0){
3159 ret = ncplane_box(n, &ul, &ur, &ll, &lr, &hl, &vl, ystop, xstop, ctlword);
3160 }
3163 nccell_release(n, &hl); nccell_release(n, &vl);
3164 return ret;
3165}
3166
3167static inline int
3168ncplane_perimeter_rounded(struct ncplane* n, uint16_t stylemask,
3169 uint64_t channels, unsigned ctlword){
3170 if(ncplane_cursor_move_yx(n, 0, 0)){
3171 return -1;
3172 }
3173 unsigned dimy, dimx;
3174 ncplane_dim_yx(n, &dimy, &dimx);
3181 if(nccells_rounded_box(n, stylemask, channels, &ul, &ur, &ll, &lr, &hl, &vl)){
3182 return -1;
3183 }
3184 int r = ncplane_box_sized(n, &ul, &ur, &ll, &lr, &hl, &vl, dimy, dimx, ctlword);
3187 nccell_release(n, &hl); nccell_release(n, &vl);
3188 return r;
3189}
3190
3191static inline int
3192ncplane_rounded_box_sized(struct ncplane* n, uint16_t styles, uint64_t channels,
3193 unsigned ylen, unsigned xlen, unsigned ctlword){
3194 unsigned y, x;
3195 ncplane_cursor_yx(n, &y, &x);
3196 return ncplane_rounded_box(n, styles, channels, y + ylen - 1,
3197 x + xlen - 1, ctlword);
3198}
3199
3200static inline int
3201ncplane_double_box(struct ncplane* n, uint16_t styles, uint64_t channels,
3202 unsigned ylen, unsigned xlen, unsigned ctlword){
3203 int ret = 0;
3207 if((ret = nccells_double_box(n, styles, channels, &ul, &ur, &ll, &lr, &hl, &vl)) == 0){
3208 ret = ncplane_box(n, &ul, &ur, &ll, &lr, &hl, &vl, ylen, xlen, ctlword);
3209 }
3212 nccell_release(n, &hl); nccell_release(n, &vl);
3213 return ret;
3214}
3215
3216static inline int
3217ncplane_ascii_box(struct ncplane* n, uint16_t styles, uint64_t channels,
3218 unsigned ylen, unsigned xlen, unsigned ctlword){
3219 int ret = 0;
3223 if((ret = nccells_ascii_box(n, styles, channels, &ul, &ur, &ll, &lr, &hl, &vl)) == 0){
3224 ret = ncplane_box(n, &ul, &ur, &ll, &lr, &hl, &vl, ylen, xlen, ctlword);
3225 }
3228 nccell_release(n, &hl); nccell_release(n, &vl);
3229 return ret;
3230}
3231
3232static inline int
3233ncplane_perimeter_double(struct ncplane* n, uint16_t stylemask,
3234 uint64_t channels, unsigned ctlword){
3235 if(ncplane_cursor_move_yx(n, 0, 0)){
3236 return -1;
3237 }
3238 unsigned dimy, dimx;
3239 ncplane_dim_yx(n, &dimy, &dimx);
3246 if(nccells_double_box(n, stylemask, channels, &ul, &ur, &ll, &lr, &hl, &vl)){
3247 return -1;
3248 }
3249 int r = ncplane_box_sized(n, &ul, &ur, &ll, &lr, &hl, &vl, dimy, dimx, ctlword);
3252 nccell_release(n, &hl); nccell_release(n, &vl);
3253 return r;
3254}
3255
3256static inline int
3257ncplane_double_box_sized(struct ncplane* n, uint16_t styles, uint64_t channels,
3258 unsigned ylen, unsigned xlen, unsigned ctlword){
3259 unsigned y, x;
3260 ncplane_cursor_yx(n, &y, &x);
3261 return ncplane_double_box(n, styles, channels, y + ylen - 1,
3262 x + xlen - 1, ctlword);
3263}
3264
3265// Open a visual at 'file', extract a codec and parameters, decode the first
3266// image to memory.
3267API ALLOC struct ncvisual* ncvisual_from_file(const char* file)
3268 __attribute__ ((nonnull (1)));
3269
3270// Prepare an ncvisual, and its underlying plane, based off RGBA content in
3271// memory at 'rgba'. 'rgba' is laid out as 'rows' lines, each of which is
3272// 'rowstride' bytes in length. Each line has 'cols' 32-bit 8bpc RGBA pixels
3273// followed by possible padding (there will be 'rowstride' - 'cols' * 4 bytes
3274// of padding). The total size of 'rgba' is thus ('rows' * 'rowstride') bytes,
3275// of which ('rows' * 'cols' * 4) bytes are actual non-padding data. It is an
3276// error if any argument is not positive, if 'rowstride' is not a multiple of
3277// 4, or if 'rowstride' is less than 'cols' * 4.
3278API ALLOC struct ncvisual* ncvisual_from_rgba(const void* rgba, int rows,
3279 int rowstride, int cols)
3280 __attribute__ ((nonnull (1)));
3281
3282// ncvisual_from_rgba(), but the pixels are 3-byte RGB. A is filled in
3283// throughout using 'alpha'. It is an error if 'rows', 'rowstride', or 'cols'
3284// is not positive, if 'rowstride' is not a multiple of 3, or if 'rowstride'
3285// is less than 'cols' * 3.
3286API ALLOC struct ncvisual* ncvisual_from_rgb_packed(const void* rgba, int rows,
3287 int rowstride, int cols,
3288 int alpha)
3289 __attribute__ ((nonnull (1)));
3290
3291// ncvisual_from_rgba(), but the pixels are 4-byte RGBx. A is filled in
3292// throughout using 'alpha'. It is an error if 'rows', 'cols', or 'rowstride'
3293// are not positive, if 'rowstride' is not a multiple of 4, or if 'rowstride'
3294// is less than 'cols' * 4.
3295API ALLOC struct ncvisual* ncvisual_from_rgb_loose(const void* rgba, int rows,
3296 int rowstride, int cols,
3297 int alpha)
3298 __attribute__ ((nonnull (1)));
3299
3300// ncvisual_from_rgba(), but 'bgra' is arranged as BGRA. note that this is a
3301// byte-oriented layout, despite being bunched in 32-bit pixels; the lowest
3302// memory address ought be B, and A is reached by adding 3 to that address.
3303// It is an error if 'rows', 'cols', or 'rowstride' are not positive, if
3304// 'rowstride' is not a multiple of 4, or if 'rowstride' is less than 'cols' * 4.
3305API ALLOC struct ncvisual* ncvisual_from_bgra(const void* bgra, int rows,
3306 int rowstride, int cols)
3307 __attribute__ ((nonnull (1)));
3308
3309// ncvisual_from_rgba(), but 'data' is 'pstride'-byte palette-indexed pixels,
3310// arranged in 'rows' lines of 'rowstride' bytes each, composed of 'cols'
3311// pixels. 'palette' is an array of at least 'palsize' ncchannels.
3312// It is an error if 'rows', 'cols', 'rowstride', or 'pstride' are not
3313// positive, if 'rowstride' is not a multiple of 'pstride', or if 'rowstride'
3314// is less than 'cols' * 'pstride'.
3315API ALLOC struct ncvisual* ncvisual_from_palidx(const void* data, int rows,
3316 int rowstride, int cols,
3317 int palsize, int pstride,
3318 const uint32_t* palette)
3319 __attribute__ ((nonnull (1, 7)));
3320
3321// Promote an ncplane 'n' to an ncvisual. The plane may contain only spaces,
3322// half blocks, and full blocks. The latter will be checked, and any other
3323// glyph will result in a NULL being returned. This function exists so that
3324// planes can be subjected to ncvisual transformations. If possible, it's
3325// better to create the ncvisual from memory using ncvisual_from_rgba().
3326// Lengths of 0 are interpreted to mean "all available remaining area".
3328 ncblitter_e blit,
3329 int begy, int begx,
3330 unsigned leny, unsigned lenx)
3331 __attribute__ ((nonnull (1)));
3332
3333// Construct an ncvisual from a nul-terminated Sixel control sequence.
3334API ALLOC struct ncvisual* ncvisual_from_sixel(const char* s, unsigned leny, unsigned lenx)
3335 __attribute__ ((nonnull (1)));
3336
3337#define NCVISUAL_OPTION_NODEGRADE 0x0001ull // fail rather than degrade
3338#define NCVISUAL_OPTION_BLEND 0x0002ull // use NCALPHA_BLEND with visual
3339#define NCVISUAL_OPTION_HORALIGNED 0x0004ull // x is an alignment, not absolute
3340#define NCVISUAL_OPTION_VERALIGNED 0x0008ull // y is an alignment, not absolute
3341#define NCVISUAL_OPTION_ADDALPHA 0x0010ull // transcolor is in effect
3342#define NCVISUAL_OPTION_CHILDPLANE 0x0020ull // interpret n as parent
3343#define NCVISUAL_OPTION_NOINTERPOLATE 0x0040ull // non-interpolative scaling
3344
3346 // if no ncplane is provided, one will be created using the exact size
3347 // necessary to render the source with perfect fidelity (this might be
3348 // smaller or larger than the rendering area). if NCVISUAL_OPTION_CHILDPLANE
3349 // is provided, this must be non-NULL, and will be interpreted as the parent.
3350 struct ncplane* n;
3351 // the scaling is ignored if no ncplane is provided (it ought be NCSCALE_NONE
3352 // in this case). otherwise, the source is stretched/scaled relative to the
3353 // provided ncplane.
3355 // if an ncplane is provided, y and x specify where the visual will be
3356 // rendered on that plane. otherwise, they specify where the created ncplane
3357 // will be placed relative to the standard plane's origin. x is an ncalign_e
3358 // value if NCVISUAL_OPTION_HORALIGNED is provided. y is an ncalign_e if
3359 // NCVISUAL_OPTION_VERALIGNED is provided.
3360 int y, x;
3361 // the region of the visual that ought be rendered. for the entire visual,
3362 // pass an origin of 0, 0 and a size of 0, 0 (or the true height and width).
3363 // these numbers are all in terms of ncvisual pixels. negative values are
3364 // prohibited.
3365 unsigned begy, begx; // origin of rendered region in pixels
3366 unsigned leny, lenx; // size of rendered region in pixels
3367 // use NCBLIT_DEFAULT if you don't care, an appropriate blitter will be
3368 // chosen for your terminal, given your scaling. NCBLIT_PIXEL is never
3369 // chosen for NCBLIT_DEFAULT.
3370 ncblitter_e blitter; // glyph set to use (maps input to output cells)
3371 uint64_t flags; // bitmask over NCVISUAL_OPTION_*
3372 uint32_t transcolor; // treat this color as transparent under NCVISUAL_OPTION_ADDALPHA
3373 // pixel offsets within the cell. if NCBLIT_PIXEL is used, the bitmap will
3374 // be drawn offset from the upper-left cell's origin by these amounts. it is
3375 // an error if either number exceeds the cell-pixel geometry in its
3376 // dimension. if NCBLIT_PIXEL is not used, these fields are ignored.
3377 // this functionality can be used for smooth bitmap movement.
3378 unsigned pxoffy, pxoffx;
3379};
3380
3381// describes all geometries of an ncvisual: those which are inherent, and those
3382// dependent upon a given rendering regime. pixy and pixx are the true internal
3383// pixel geometry, taken directly from the load (and updated by
3384// ncvisual_resize()). cdimy/cdimx are the cell-pixel geometry *at the time
3385// of this call* (it can change with a font change, in which case all values
3386// other than pixy/pixx are invalidated). rpixy/rpixx are the pixel geometry as
3387// handed to the blitter, following any scaling. scaley/scalex are the number
3388// of input pixels drawn to a single cell; when using NCBLIT_PIXEL, they are
3389// equivalent to cdimy/cdimx. rcelly/rcellx are the cell geometry as written by
3390// the blitter, following any padding (there is padding whenever rpix{y, x} is
3391// not evenly divided by scale{y, x}, and also sometimes for Sixel).
3392// maxpixely/maxpixelx are defined only when NCBLIT_PIXEL is used, and specify
3393// the largest bitmap that the terminal is willing to accept. blitter is the
3394// blitter which will be used, a function of the requested blitter and the
3395// blitters actually supported by this environment. if no ncvisual was
3396// supplied, only cdimy/cdimx are filled in.
3397typedef struct ncvgeom {
3398 unsigned pixy, pixx; // true pixel geometry of ncvisual data
3399 unsigned cdimy, cdimx; // terminal cell geometry when this was calculated
3400 unsigned rpixy, rpixx; // rendered pixel geometry (per visual_options)
3401 unsigned rcelly, rcellx; // rendered cell geometry (per visual_options)
3402 unsigned scaley, scalex; // source pixels per filled cell
3403 unsigned begy, begx; // upper-left corner of used region
3404 unsigned leny, lenx; // geometry of used region
3405 unsigned maxpixely, maxpixelx; // only defined for NCBLIT_PIXEL
3406 ncblitter_e blitter; // blitter that will be used
3408
3409// all-purpose ncvisual geometry solver. one or both of 'nc' and 'n' must be
3410// non-NULL. if 'nc' is NULL, only pixy/pixx will be filled in, with the true
3411// pixel geometry of 'n'. if 'n' is NULL, only cdimy/cdimx, blitter,
3412// scaley/scalex, and maxpixely/maxpixelx are filled in. cdimy/cdimx and
3413// maxpixely/maxpixelx are only ever filled in if we know them.
3414API int ncvisual_geom(const struct notcurses* nc, const struct ncvisual* n,
3415 const struct ncvisual_options* vopts, ncvgeom* geom)
3416 __attribute__ ((nonnull (4)));
3417
3418// Destroy an ncvisual. Rendered elements will not be disrupted, but the visual
3419// can be neither decoded nor rendered any further.
3420API void ncvisual_destroy(struct ncvisual* ncv);
3421
3422// extract the next frame from an ncvisual. returns 1 on end of file, 0 on
3423// success, and -1 on failure.
3424API int ncvisual_decode(struct ncvisual* nc)
3425 __attribute__ ((nonnull (1)));
3426
3427// decode the next frame ala ncvisual_decode(), but if we have reached the end,
3428// rewind to the first frame of the ncvisual. a subsequent 'ncvisual_blit()'
3429// will render the first frame, as if the ncvisual had been closed and reopened.
3430// the return values remain the same as those of ncvisual_decode().
3431API int ncvisual_decode_loop(struct ncvisual* nc)
3432 __attribute__ ((nonnull (1)));
3433
3434// Rotate the visual 'rads' radians. Only M_PI/2 and -M_PI/2 are supported at
3435// the moment, but this might change in the future.
3436API int ncvisual_rotate(struct ncvisual* n, double rads)
3437 __attribute__ ((nonnull (1)));
3438
3439// Scale the visual to 'rows' X 'columns' pixels, using the best scheme
3440// available. This is a lossy transformation, unless the size is unchanged.
3441API int ncvisual_resize(struct ncvisual* n, int rows, int cols)
3442 __attribute__ ((nonnull (1)));
3443
3444// Scale the visual to 'rows' X 'columns' pixels, using non-interpolative
3445// (naive) scaling. No new colors will be introduced as a result.
3446API int ncvisual_resize_noninterpolative(struct ncvisual* n, int rows, int cols)
3447 __attribute__ ((nonnull (1)));
3448
3449// Polyfill at the specified location within the ncvisual 'n', using 'rgba'.
3450API int ncvisual_polyfill_yx(struct ncvisual* n, unsigned y, unsigned x, uint32_t rgba)
3451 __attribute__ ((nonnull (1)));
3452
3453// Get the specified pixel from the specified ncvisual.
3454API int ncvisual_at_yx(const struct ncvisual* n, unsigned y, unsigned x,
3455 uint32_t* pixel)
3456 __attribute__ ((nonnull (1, 4)));
3457
3458// Set the specified pixel in the specified ncvisual.
3459API int ncvisual_set_yx(const struct ncvisual* n, unsigned y, unsigned x,
3460 uint32_t pixel)
3461 __attribute__ ((nonnull (1)));
3462
3463// Render the decoded frame according to the provided options (which may be
3464// NULL). The plane used for rendering depends on vopts->n and vopts->flags.
3465// If NCVISUAL_OPTION_CHILDPLANE is set, vopts->n must not be NULL, and the
3466// plane will always be created as a child of vopts->n. If this flag is not
3467// set, and vopts->n is NULL, a new plane is created as root of a new pile.
3468// If the flag is not set and vopts->n is not NULL, we render to vopts->n.
3469// A subregion of the visual can be rendered using 'begx', 'begy', 'lenx', and
3470// 'leny'. Negative values for any of these are an error. It is an error to
3471// specify any region beyond the boundaries of the frame. Returns the (possibly
3472// newly-created) plane to which we drew. Pixels may not be blitted to the
3473// standard plane.
3474API struct ncplane* ncvisual_blit(struct notcurses* nc, struct ncvisual* ncv,
3475 const struct ncvisual_options* vopts)
3476 __attribute__ ((nonnull (2)));
3477
3478// Create a new plane as prescribed in opts, either as a child of 'vopts->n',
3479// or the root of a new pile if 'vopts->n' is NULL (or 'vopts' itself is NULL).
3480// Blit 'ncv' to the created plane according to 'vopts'. If 'vopts->n' is
3481// non-NULL, NCVISUAL_OPTION_CHILDPLANE must be supplied.
3482__attribute__ ((nonnull (1, 2, 3))) static inline struct ncplane*
3483ncvisualplane_create(struct notcurses* nc, const struct ncplane_options* opts,
3485 struct ncplane* newn;
3486 if(vopts && vopts->n){
3488 return NULL; // the whole point is to create a new plane
3489 }
3491 }else{
3492 newn = ncpile_create(nc, opts);
3493 }
3494 if(newn == NULL){
3495 return NULL;
3496 }
3498 if(!vopts){
3499 vopts = &v;
3500 memset(vopts, 0, sizeof(*vopts));
3501 }
3505 vopts->n = NULL;
3506 return NULL;
3507 }
3508 return newn;
3509}
3510
3511// If a subtitle ought be displayed at this time, return a new plane (bound
3512// to 'parent' containing the subtitle, which might be text or graphics
3513// (depending on the input format).
3515 const struct ncvisual* ncv)
3516 __attribute__ ((nonnull (1, 2)));
3517
3518// Get the default *media* (not plot) blitter for this environment when using
3519// the specified scaling method. Currently, this means:
3520// - if lacking UTF-8, NCBLIT_1x1
3521// - otherwise, if not NCSCALE_STRETCH, NCBLIT_2x1
3522// - otherwise, if octants are known to be good, NCBLIT_4x2
3523// - otherwise, if sextants are not known to be good, NCBLIT_2x2
3524// - otherwise NCBLIT_3x2
3525// NCBLIT_2x2 and NCBLIT_3x2 both distort the original aspect ratio, thus
3526// NCBLIT_2x1 is used outside of NCSCALE_STRETCH.
3528 __attribute__ ((nonnull (1)));
3529
3530// Called for each frame rendered from 'ncv'. If anything but 0 is returned,
3531// the streaming operation ceases immediately, and that value is propagated out.
3532// The recommended absolute display time target is passed in 'tspec'.
3533typedef int (*ncstreamcb)(struct ncvisual*, struct ncvisual_options*,
3534 const struct timespec*, void*);
3535
3536// Shut up and display my frames! Provide as an argument to ncvisual_stream().
3537// If you'd like subtitles to be decoded, provide an ncplane as the curry. If the
3538// curry is NULL, subtitles will not be displayed.
3540 const struct timespec* tspec, void* curry)
3541 __attribute__ ((nonnull (1)));
3542
3543// Stream the entirety of the media, according to its own timing. Blocking,
3544// obviously. streamer may be NULL; it is otherwise called for each frame, and
3545// its return value handled as outlined for streamcb. If streamer() returns
3546// non-zero, the stream is aborted, and that value is returned. By convention,
3547// return a positive number to indicate intentional abort from within
3548// streamer(). 'timescale' allows the frame duration time to be scaled. For a
3549// visual naturally running at 30FPS, a 'timescale' of 0.1 will result in
3550// 300FPS, and a 'timescale' of 10 will result in 3FPS. It is an error to
3551// supply 'timescale' less than or equal to 0.
3552API int ncvisual_stream(struct notcurses* nc, struct ncvisual* ncv,
3553 float timescale, ncstreamcb streamer,
3554 const struct ncvisual_options* vopts, void* curry)
3555 __attribute__ ((nonnull (1, 2)));
3556
3557// Blit a flat array 'data' of RGBA 32-bit values to the ncplane 'vopts->n',
3558// which mustn't be NULL. the blit begins at 'vopts->y' and 'vopts->x' relative
3559// to the specified plane. Each source row ought occupy 'linesize' bytes (this
3560// might be greater than 'vopts->lenx' * 4 due to padding or partial blits). A
3561// subregion of the input can be specified with the 'begy'x'begx' and
3562// 'leny'x'lenx' fields from 'vopts'. Returns the number of pixels blitted, or
3563// -1 on error.
3564API int ncblit_rgba(const void* data, int linesize,
3565 const struct ncvisual_options* vopts)
3566 __attribute__ ((nonnull (1)));
3567
3568// Same as ncblit_rgba(), but for BGRx.
3569API int ncblit_bgrx(const void* data, int linesize,
3570 const struct ncvisual_options* vopts)
3571 __attribute__ ((nonnull (1)));
3572
3573// Supply an alpha value [0..255] to be applied throughout.
3574API int ncblit_rgb_packed(const void* data, int linesize,
3575 const struct ncvisual_options* vopts, int alpha)
3576 __attribute__ ((nonnull (1)));
3577
3578// Supply an alpha value [0..255] to be applied throughout. linesize must be
3579// a multiple of 4 for this RGBx data.
3580API int ncblit_rgb_loose(const void* data, int linesize,
3581 const struct ncvisual_options* vopts, int alpha)
3582 __attribute__ ((nonnull (1)));
3583
3584// The ncpixel API facilitates direct management of the pixels within an
3585// ncvisual (ncvisuals keep a backing store of 32-bit RGBA pixels, and render
3586// them down to terminal graphics in ncvisual_blit()).
3587//
3588// Per libav, we "store as BGRA on little-endian, and ARGB on big-endian".
3589// This is an RGBA *byte-order* scheme. libav emits bytes, not words. Those
3590// bytes are R-G-B-A. When read as words, on little endian this will be ABGR,
3591// and on big-endian this will be RGBA. force everything to LE ABGR, a no-op
3592// on (and thus favoring) little-endian. Take that, big-endian mafia!
3593
3594// Extract the 8-bit alpha component from a pixel
3595static inline unsigned
3596ncpixel_a(uint32_t pixel){
3597 return (htole(pixel) & 0xff000000u) >> 24u;
3598}
3599
3600// Extract the 8-bit red component from an ABGR pixel
3601static inline unsigned
3602ncpixel_r(uint32_t pixel){
3603 return (htole(pixel) & 0x000000ffu);
3604}
3605
3606// Extract the 8-bit green component from an ABGR pixel
3607static inline unsigned
3608ncpixel_g(uint32_t pixel){
3609 return (htole(pixel) & 0x0000ff00u) >> 8u;
3610}
3611
3612// Extract the 8-bit blue component from an ABGR pixel
3613static inline unsigned
3614ncpixel_b(uint32_t pixel){
3615 return (htole(pixel) & 0x00ff0000u) >> 16u;
3616}
3617
3618// Set the 8-bit alpha component of an ABGR pixel
3619static inline int
3620ncpixel_set_a(uint32_t* pixel, unsigned a){
3621 if(a > 255){
3622 return -1;
3623 }
3624 *pixel = htole((htole(*pixel) & 0x00ffffffu) | (a << 24u));
3625 return 0;
3626}
3627
3628// Set the 8-bit red component of an ABGR pixel
3629static inline int
3630ncpixel_set_r(uint32_t* pixel, unsigned r){
3631 if(r > 255){
3632 return -1;
3633 }
3634 *pixel = htole((htole(*pixel) & 0xffffff00u) | r);
3635 return 0;
3636}
3637
3638// Set the 8-bit green component of an ABGR pixel
3639static inline int
3640ncpixel_set_g(uint32_t* pixel, unsigned g){
3641 if(g > 255){
3642 return -1;
3643 }
3644 *pixel = htole((htole(*pixel) & 0xffff00ffu) | (g << 8u));
3645 return 0;
3646}
3647
3648// Set the 8-bit blue component of an ABGR pixel
3649static inline int
3650ncpixel_set_b(uint32_t* pixel, unsigned b){
3651 if(b > 255){
3652 return -1;
3653 }
3654 *pixel = htole((htole(*pixel) & 0xff00ffffu) | (b << 16u));
3655 return 0;
3656}
3657
3658// Construct a libav-compatible ABGR pixel, clipping at [0, 255).
3659static inline uint32_t
3660ncpixel(unsigned r, unsigned g, unsigned b){
3661 uint32_t pixel = 0;
3662 ncpixel_set_a(&pixel, 0xff);
3663 if(r > 255) r = 255;
3664 ncpixel_set_r(&pixel, r);
3665 if(g > 255) g = 255;
3666 ncpixel_set_g(&pixel, g);
3667 if(b > 255) b = 255;
3668 ncpixel_set_b(&pixel, b);
3669 return pixel;
3670}
3671
3672// set the RGB values of an RGB pixel
3673static inline int
3674ncpixel_set_rgb8(uint32_t* pixel, unsigned r, unsigned g, unsigned b){
3675 if(ncpixel_set_r(pixel, r) || ncpixel_set_g(pixel, g) || ncpixel_set_b(pixel, b)){
3676 return -1;
3677 }
3678 return 0;
3679}
3680
3681// An ncreel is a Notcurses region devoted to displaying zero or more
3682// line-oriented, contained tablets between which the user may navigate. If at
3683// least one tablets exists, there is a "focused tablet". As much of the focused
3684// tablet as is possible is always displayed. If there is space left over, other
3685// tablets are included in the display. Tablets can come and go at any time, and
3686// can grow or shrink at any time.
3687//
3688// This structure is amenable to line- and page-based navigation via keystrokes,
3689// scrolling gestures, trackballs, scrollwheels, touchpads, and verbal commands.
3690
3691// is scrolling infinite (can one move down or up forever, or is an end
3692// reached?). if true, 'circular' specifies how to handle the special case of
3693// an incompletely-filled reel.
3694#define NCREEL_OPTION_INFINITESCROLL 0x0001ull
3695// is navigation circular (does moving down from the last tablet move to the
3696// first, and vice versa)? only meaningful when infinitescroll is true. if
3697// infinitescroll is false, this must be false.
3698#define NCREEL_OPTION_CIRCULAR 0x0002ull
3699
3700typedef struct ncreel_options {
3701 // Notcurses can draw a border around the ncreel, and also around the
3702 // component tablets. inhibit borders by setting all valid bits in the masks.
3703 // partially inhibit borders by setting individual bits in the masks. the
3704 // appropriate attr and pair values will be used to style the borders.
3705 // focused and non-focused tablets can have different styles. you can instead
3706 // draw your own borders, or forgo borders entirely.
3707 unsigned bordermask; // bitfield; 1s will not be drawn (see bordermaskbits)
3708 uint64_t borderchan; // attributes used for ncreel border
3709 unsigned tabletmask; // bitfield; same as bordermask but for tablet borders
3710 uint64_t tabletchan; // tablet border styling channel
3711 uint64_t focusedchan;// focused tablet border styling channel
3712 uint64_t flags; // bitfield over NCREEL_OPTION_*
3714
3715// Take over the ncplane 'nc' and use it to draw a reel according to 'popts'.
3716// The plane will be destroyed by ncreel_destroy(); this transfers ownership.
3717API ALLOC struct ncreel* ncreel_create(struct ncplane* n, const ncreel_options* popts)
3718 __attribute__ ((nonnull (1)));
3719
3720// Returns the ncplane on which this ncreel lives.
3721API struct ncplane* ncreel_plane(struct ncreel* nr)
3722 __attribute__ ((nonnull (1)));
3723
3724// Tablet draw callback, provided a tablet (from which the ncplane and userptr
3725// may be extracted), and a bool indicating whether output ought be drawn from
3726// the top (true) or bottom (false). Returns non-negative count of output lines,
3727// which must be less than or equal to ncplane_dim_y(nctablet_plane(t)).
3728typedef int (*tabletcb)(struct nctablet* t, bool drawfromtop);
3729
3730// Add a new nctablet to the provided ncreel 'nr', having the callback object
3731// 'opaque'. Neither, either, or both of 'after' and 'before' may be specified.
3732// If neither is specified, the new tablet can be added anywhere on the reel.
3733// If one or the other is specified, the tablet will be added before or after
3734// the specified tablet. If both are specified, the tablet will be added to the
3735// resulting location, assuming it is valid (after->next == before->prev); if
3736// it is not valid, or there is any other error, NULL will be returned.
3737API ALLOC struct nctablet* ncreel_add(struct ncreel* nr, struct nctablet* after,
3738 struct nctablet* before, tabletcb cb,
3739 void* opaque)
3740 __attribute__ ((nonnull (1)));
3741
3742// Return the number of nctablets in the ncreel 'nr'.
3743API int ncreel_tabletcount(const struct ncreel* nr)
3744 __attribute__ ((nonnull (1)));
3745
3746// Delete the tablet specified by t from the ncreel 'nr'. Returns -1 if the
3747// tablet cannot be found.
3748API int ncreel_del(struct ncreel* nr, struct nctablet* t)
3749 __attribute__ ((nonnull (1)));
3750
3751// Redraw the ncreel 'nr' in its entirety. The reel will be cleared, and
3752// tablets will be lain out, using the focused tablet as a fulcrum. Tablet
3753// drawing callbacks will be invoked for each visible tablet.
3754API int ncreel_redraw(struct ncreel* nr)
3755 __attribute__ ((nonnull (1)));
3756
3757// Offer input 'ni' to the ncreel 'nr'. If it's relevant, this function returns
3758// true, and the input ought not be processed further. If it's irrelevant to
3759// the reel, false is returned. Relevant inputs include:
3760// * a mouse click on a tablet (focuses tablet)
3761// * a mouse scrollwheel event (rolls reel)
3762// * up, down, pgup, or pgdown (navigates among items)
3763API bool ncreel_offer_input(struct ncreel* nr, const ncinput* ni)
3764 __attribute__ ((nonnull (1, 2)));
3765
3766// Return the focused tablet, if any tablets are present. This is not a copy;
3767// be careful to use it only for the duration of a critical section.
3768API struct nctablet* ncreel_focused(struct ncreel* nr)
3769 __attribute__ ((nonnull (1)));
3770
3771// Change focus to the next tablet, if one exists
3772API struct nctablet* ncreel_next(struct ncreel* nr)
3773 __attribute__ ((nonnull (1)));
3774
3775// Change focus to the previous tablet, if one exists
3776API struct nctablet* ncreel_prev(struct ncreel* nr)
3777 __attribute__ ((nonnull (1)));
3778
3779// Destroy an ncreel allocated with ncreel_create().
3780API void ncreel_destroy(struct ncreel* nr);
3781
3782// Returns a pointer to a user pointer associated with this nctablet.
3783API void* nctablet_userptr(struct nctablet* t);
3784
3785// Access the ncplane associated with nctablet 't', if one exists.
3786API struct ncplane* nctablet_plane(struct nctablet* t);
3787
3788// Takes an arbitrarily large number, and prints it into a fixed-size buffer by
3789// adding the necessary SI suffix. Usually, pass a |NC[IB]?PREFIXSTRLEN+1|-sized
3790// buffer to generate up to |NC[IB]?PREFIXCOLUMNS| columns' worth of EGCs. The
3791// characteristic can occupy up through |mult-1| characters (3 for 1000, 4 for
3792// 1024). The mantissa can occupy either zero or two characters.
3793
3794// snprintf(3) is used internally, with 's' as its size bound. If the output
3795// requires more size than is available, NULL will be returned.
3796//
3797// Floating-point is never used, because an IEEE758 double can only losslessly
3798// represent integers through 2^53-1.
3799//
3800// 2^64-1 is 18446744073709551615, 18.45E(xa). KMGTPEZY thus suffice to handle
3801// an 89-bit uintmax_t. Beyond Z(etta) and Y(otta) lie lands unspecified by SI.
3802// 2^-63 is 0.000000000000000000108, 1.08a(tto).
3803// val: value to print
3804// s: maximum output size; see snprintf(3)
3805// decimal: scaling. '1' if none has taken place.
3806// buf: buffer in which string will be generated
3807// omitdec: inhibit printing of all-0 decimal portions
3808// mult: base of suffix system (almost always 1000 or 1024)
3809// uprefix: character to print following suffix ('i' for kibibytes basically).
3810// only printed if suffix is actually printed (input >= mult).
3811//
3812// You are encouraged to consult notcurses_metric(3).
3813API const char* ncnmetric(uintmax_t val, size_t s, uintmax_t decimal,
3814 char* buf, int omitdec, uintmax_t mult, int uprefix)
3815 __attribute__ ((nonnull (4)));
3816
3817// The number of columns is one fewer, as the STRLEN expressions must leave
3818// an extra byte open in case 'µ' (U+00B5, 0xC2 0xB5) shows up. NCPREFIXCOLUMNS
3819// is the maximum number of columns used by a mult == 1000 (standard)
3820// ncnmetric() call. NCIPREFIXCOLUMNS is the maximum number of columns used by a
3821// mult == 1024 (digital information) ncnmetric(). NCBPREFIXSTRLEN is the maximum
3822// number of columns used by a mult == 1024 call making use of the 'i' suffix.
3823// This is the true number of columns; to set up a printf()-style maximum
3824// field width, you should use NC[IB]PREFIXFMT (see below).
3825#define NCPREFIXCOLUMNS 7
3826#define NCIPREFIXCOLUMNS 8
3827#define NCBPREFIXCOLUMNS 9
3828#define NCPREFIXSTRLEN (NCPREFIXCOLUMNS + 1) // Does not include a '\0' (xxx.xxU)
3829#define NCIPREFIXSTRLEN (NCIPREFIXCOLUMNS + 1) // Does not include a '\0' (xxxx.xxU)
3830#define NCBPREFIXSTRLEN (NCBPREFIXCOLUMNS + 1) // Does not include a '\0' (xxxx.xxUi), i == prefix
3831// Used as arguments to a variable field width (i.e. "%*s" -- these are the *).
3832// We need this convoluted grotesquery to properly handle 'µ'.
3833#define NCMETRICFWIDTH(x, cols) \
3834 ((int)(strlen(x) - ncstrwidth(x, NULL, NULL) + (cols)))
3835#define NCPREFIXFMT(x) NCMETRICFWIDTH((x), NCPREFIXCOLUMNS), (x)
3836#define NCIPREFIXFMT(x) NCMETRICFWIDTH((x), NCIPREFIXCOLUMNS), (x)
3837#define NCBPREFIXFMT(x) NCMETRICFWIDTH((x), NCBPREFIXCOLUMNS), (x)
3838
3839// Mega, kilo, gigafoo. Use PREFIXSTRLEN + 1 and PREFIXCOLUMNS.
3840static inline const char*
3841ncqprefix(uintmax_t val, uintmax_t decimal, char* buf, int omitdec){
3842 return ncnmetric(val, NCPREFIXSTRLEN + 1, decimal, buf, omitdec, 1000, '\0');
3843}
3844
3845// Mibi, kebi, gibibytes sans 'i' suffix. Use IPREFIXSTRLEN + 1.
3846static inline const char*
3847nciprefix(uintmax_t val, uintmax_t decimal, char* buf, int omitdec){
3848 return ncnmetric(val, NCIPREFIXSTRLEN + 1, decimal, buf, omitdec, 1024, '\0');
3849}
3850
3851// Mibi, kebi, gibibytes. Use BPREFIXSTRLEN + 1 and BPREFIXCOLUMNS.
3852static inline const char*
3853ncbprefix(uintmax_t val, uintmax_t decimal, char* buf, int omitdec){
3854 return ncnmetric(val, NCBPREFIXSTRLEN + 1, decimal, buf, omitdec, 1024, 'i');
3855}
3856
3857// Get the default foreground color, if it is known. Returns -1 on error
3858// (unknown foreground). On success, returns 0, writing the RGB value to
3859// 'fg' (if non-NULL)
3860API int notcurses_default_foreground(const struct notcurses* nc, uint32_t* fg)
3861 __attribute__ ((nonnull (1)));
3862
3863// Get the default background color, if it is known. Returns -1 on error
3864// (unknown background). On success, returns 0, writing the RGB value to
3865// 'bg' (if non-NULL) and setting 'bgtrans' high iff the background color
3866// is treated as transparent.
3867API int notcurses_default_background(const struct notcurses* nc, uint32_t* bg)
3868 __attribute__ ((nonnull (1)));
3869
3870// Enable or disable the terminal's cursor, if supported, placing it at
3871// 'y', 'x'. Immediate effect (no need for a call to notcurses_render()).
3872// It is an error if 'y', 'x' lies outside the standard plane. Can be
3873// called while already visible to move the cursor.
3874API int notcurses_cursor_enable(struct notcurses* nc, int y, int x)
3875 __attribute__ ((nonnull (1)));
3876
3877// Disable the hardware cursor. It is an error to call this while the
3878// cursor is already disabled.
3880 __attribute__ ((nonnull (1)));
3881
3882// Get the current location of the terminal's cursor, whether visible or not.
3883API int notcurses_cursor_yx(const struct notcurses* nc, int* y, int* x)
3884 __attribute__ ((nonnull (1)));
3885
3886// Convert the plane's content to greyscale.
3887API void ncplane_greyscale(struct ncplane* n)
3888 __attribute__ ((nonnull (1)));
3889
3890// ╭──────────────────────────╮
3891// │This is the primary header│
3892// ╭──────────────────────this is the secondary header──────╮
3893// │ ↑ │
3894// │ option1 Long text #1 │
3895// │ option2 Long text #2 │
3896// │ option3 Long text #3 │
3897// │ option4 Long text #4 │
3898// │ option5 Long text #5 │
3899// │ option6 Long text #6 │
3900// │ ↓ │
3901// ╰────────────────────────────────────here's the footer───╯
3902
3903// selection widget -- an ncplane with a title header and a body section. the
3904// body section supports infinite scrolling up and down.
3905//
3906// At all times, exactly one item is selected.
3908 const char* option;
3909 const char* desc;
3910};
3911
3912typedef struct ncselector_options {
3913 const char* title; // title may be NULL, inhibiting riser, saving two rows.
3914 const char* secondary; // secondary may be NULL
3915 const char* footer; // footer may be NULL
3916 const struct ncselector_item* items; // initial items and descriptions
3917 // default item (selected at start), must be < itemcount unless itemcount is
3918 // 0, in which case 'defidx' must also be 0
3919 unsigned defidx;
3920 // maximum number of options to display at once, 0 to use all available space
3921 unsigned maxdisplay;
3922 // exhaustive styling options
3923 uint64_t opchannels; // option channels
3924 uint64_t descchannels; // description channels
3925 uint64_t titlechannels;// title channels
3926 uint64_t footchannels; // secondary and footer channels
3927 uint64_t boxchannels; // border channels
3928 uint64_t flags; // bitfield of NCSELECTOR_OPTION_*, currently unused
3930
3932 __attribute__ ((nonnull (1)));
3933
3934// Dynamically add or delete items. It is usually sufficient to supply a static
3935// list of items via ncselector_options->items.
3936API int ncselector_additem(struct ncselector* n, const struct ncselector_item* item);
3937API int ncselector_delitem(struct ncselector* n, const char* item);
3938
3939// Return reference to the selected option, or NULL if there are no items.
3940API const char* ncselector_selected(const struct ncselector* n)
3941 __attribute__ ((nonnull (1)));
3942
3943// Return a reference to the ncselector's underlying ncplane.
3944API struct ncplane* ncselector_plane(struct ncselector* n)
3945 __attribute__ ((nonnull (1)));
3946
3947// Move up or down in the list. A reference to the newly-selected item is
3948// returned, or NULL if there are no items in the list.
3949API const char* ncselector_previtem(struct ncselector* n)
3950 __attribute__ ((nonnull (1)));
3951API const char* ncselector_nextitem(struct ncselector* n)
3952 __attribute__ ((nonnull (1)));
3953
3954// Offer the input to the ncselector. If it's relevant, this function returns
3955// true, and the input ought not be processed further. If it's irrelevant to
3956// the selector, false is returned. Relevant inputs include:
3957// * a mouse click on an item
3958// * a mouse scrollwheel event
3959// * a mouse click on the scrolling arrows
3960// * up, down, pgup, or pgdown on an unrolled menu (navigates among items)
3962 __attribute__ ((nonnull (1, 2)));
3963
3964// Destroy the ncselector.
3965API void ncselector_destroy(struct ncselector* n, char** item);
3966
3968 const char* option;
3969 const char* desc;
3971};
3972
3973// ╭───────────────────╮
3974// │ short round title │
3975//╭now this secondary is also very, very, very outlandishly long, you see┤
3976//│ ↑ │
3977//│ ☐ Pa231 Protactinium-231 (162kg) │
3978//│ ☐ U233 Uranium-233 (15kg) │
3979//│ ☐ U235 Uranium-235 (50kg) │
3980//│ ☐ Np236 Neptunium-236 (7kg) │
3981//│ ☐ Np237 Neptunium-237 (60kg) │
3982//│ ☐ Pu238 Plutonium-238 (10kg) │
3983//│ ☐ Pu239 Plutonium-239 (10kg) │
3984//│ ☐ Pu240 Plutonium-240 (40kg) │
3985//│ ☐ Pu241 Plutonium-241 (13kg) │
3986//│ ☐ Am241 Americium-241 (100kg) │
3987//│ ↓ │
3988//╰────────────────────────press q to exit (there is sartrev("no exit"))─╯
3989
3990// multiselection widget -- a selector supporting multiple selections.
3991//
3992// Unlike the selector widget, zero to all of the items can be selected, but
3993// also the widget does not support adding or removing items at runtime.
3995 const char* title; // title may be NULL, inhibiting riser, saving two rows.
3996 const char* secondary; // secondary may be NULL
3997 const char* footer; // footer may be NULL
3998 const struct ncmselector_item* items; // initial items, descriptions, and statuses
3999 // maximum number of options to display at once, 0 to use all available space
4000 unsigned maxdisplay;
4001 // exhaustive styling options
4002 uint64_t opchannels; // option channels
4003 uint64_t descchannels; // description channels
4004 uint64_t titlechannels;// title channels
4005 uint64_t footchannels; // secondary and footer channels
4006 uint64_t boxchannels; // border channels
4007 uint64_t flags; // bitfield of NCMULTISELECTOR_OPTION_*, currently unused
4009
4011 __attribute__ ((nonnull (1)));
4012
4013// Return selected vector. An array of bools must be provided, along with its
4014// length. If that length doesn't match the itemcount, it is an error.
4015API int ncmultiselector_selected(struct ncmultiselector* n, bool* selected, unsigned count);
4016
4017// Return a reference to the ncmultiselector's underlying ncplane.
4019
4020// Offer the input to the ncmultiselector. If it's relevant, this function
4021// returns true, and the input ought not be processed further. If it's
4022// irrelevant to the multiselector, false is returned. Relevant inputs include:
4023// * a mouse click on an item
4024// * a mouse scrollwheel event
4025// * a mouse click on the scrolling arrows
4026// * up, down, pgup, or pgdown on an unrolled menu (navigates among items)
4028 __attribute__ ((nonnull (1, 2)));
4029
4030// Destroy the ncmultiselector.
4032
4033// nctree widget -- a vertical browser supporting line-based hierarchies.
4034//
4035// each item can have subitems, and has a curry. there is one callback for the
4036// entirety of the nctree. visible items have the callback invoked upon their
4037// curry and an ncplane. the ncplane can be reused across multiple invocations
4038// of the callback.
4039
4040// each item has a curry, and zero or more subitems.
4042 void* curry;
4044 unsigned subcount;
4045};
4046
4047typedef struct nctree_options {
4048 const struct nctree_item* items; // top-level nctree_item array
4049 unsigned count; // size of |items|
4050 int (*nctreecb)(struct ncplane*, void*, int); // item callback function
4051 int indentcols; // columns to indent per level of hierarchy
4052 uint64_t flags; // bitfield of NCTREE_OPTION_*
4054
4055// |opts| may *not* be NULL, since it is necessary to define a callback
4056// function.
4058 __attribute__ ((nonnull (1, 2)));
4059
4060// Returns the ncplane on which this nctree lives.
4061API struct ncplane* nctree_plane(struct nctree* n)
4062 __attribute__ ((nonnull (1)));
4063
4064// Redraw the nctree 'n' in its entirety. The tree will be cleared, and items
4065// will be lain out, using the focused item as a fulcrum. Item-drawing
4066// callbacks will be invoked for each visible item.
4067API int nctree_redraw(struct nctree* n)
4068 __attribute__ ((nonnull (1)));
4069
4070// Offer input 'ni' to the nctree 'n'. If it's relevant, this function returns
4071// true, and the input ought not be processed further. If it's irrelevant to
4072// the tree, false is returned. Relevant inputs include:
4073// * a mouse click on an item (focuses item)
4074// * a mouse scrollwheel event (srolls tree)
4075// * up, down, pgup, or pgdown (navigates among items)
4076API bool nctree_offer_input(struct nctree* n, const ncinput* ni)
4077 __attribute__ ((nonnull (1, 2)));
4078
4079// Return the focused item, if any items are present. This is not a copy;
4080// be careful to use it only for the duration of a critical section.
4081API void* nctree_focused(struct nctree* n) __attribute__ ((nonnull (1)));
4082
4083// Change focus to the next item.
4084API void* nctree_next(struct nctree* n) __attribute__ ((nonnull (1)));
4085
4086// Change focus to the previous item.
4087API void* nctree_prev(struct nctree* n) __attribute__ ((nonnull (1)));
4088
4089// Go to the item specified by the array |spec| (a spec is a series of unsigned
4090// values, each identifying a subelement in the hierarchy thus far, terminated
4091// by UINT_MAX). If the spec is invalid, NULL is returned, and the depth of the
4092// first invalid spec is written to *|failspec|. Otherwise, the true depth is
4093// written to *|failspec|, and the curry is returned (|failspec| is necessary
4094// because the curry could itself be NULL).
4095API void* nctree_goto(struct nctree* n, const unsigned* spec, int* failspec);
4096
4097// Insert |add| into the nctree |n| at |spec|. The path up to the last element
4098// must already exist. If an item already exists at the path, it will be moved
4099// to make room for |add|.
4100API int nctree_add(struct nctree* n, const unsigned* spec, const struct nctree_item* add)
4101 __attribute__ ((nonnull (1, 2, 3)));
4102
4103// Delete the item at |spec|, including any subitems.
4104API int nctree_del(struct nctree* n, const unsigned* spec)
4105 __attribute__ ((nonnull (1, 2)));
4106
4107// Destroy the nctree.
4108API void nctree_destroy(struct nctree* n);
4109
4110// Menus. Horizontal menu bars are supported, on the top and/or bottom rows.
4111// If the menu bar is longer than the screen, it will be only partially
4112// visible. Menus may be either visible or invisible by default. In the event of
4113// a plane resize, menus will be automatically moved/resized. Elements can be
4114// dynamically enabled or disabled at all levels (menu, section, and item),
4116 const char* desc; // utf-8 menu item, NULL for horizontal separator
4117 ncinput shortcut; // shortcut, all should be distinct
4118};
4119
4121 const char* name; // utf-8 c string
4124 ncinput shortcut; // shortcut, will be underlined if present in name
4125};
4126
4127#define NCMENU_OPTION_BOTTOM 0x0001ull // bottom row (as opposed to top row)
4128#define NCMENU_OPTION_HIDING 0x0002ull // hide the menu when not unrolled
4129
4130typedef struct ncmenu_options {
4131 struct ncmenu_section* sections; // array of 'sectioncount' menu_sections
4132 int sectioncount; // must be positive
4133 uint64_t headerchannels; // styling for header
4134 uint64_t sectionchannels; // styling for sections
4135 uint64_t flags; // flag word of NCMENU_OPTION_*
4137
4138// Create a menu with the specified options, bound to the specified plane.
4139API ALLOC struct ncmenu* ncmenu_create(struct ncplane* n, const ncmenu_options* opts)
4140 __attribute__ ((nonnull (1)));
4141
4142// Unroll the specified menu section, making the menu visible if it was
4143// invisible, and rolling up any menu section that is already unrolled.
4144API int ncmenu_unroll(struct ncmenu* n, int sectionidx);
4145
4146// Roll up any unrolled menu section, and hide the menu if using hiding.
4147API int ncmenu_rollup(struct ncmenu* n) __attribute__ ((nonnull (1)));
4148
4149// Unroll the previous/next section (relative to current unrolled). If no
4150// section is unrolled, the first section will be unrolled.
4151API int ncmenu_nextsection(struct ncmenu* n) __attribute__ ((nonnull (1)));
4152API int ncmenu_prevsection(struct ncmenu* n) __attribute__ ((nonnull (1)));
4153
4154// Move to the previous/next item within the currently unrolled section. If no
4155// section is unrolled, the first section will be unrolled.
4156API int ncmenu_nextitem(struct ncmenu* n) __attribute__ ((nonnull (1)));
4157API int ncmenu_previtem(struct ncmenu* n) __attribute__ ((nonnull (1)));
4158
4159// Disable or enable a menu item. Returns 0 if the item was found.
4160API int ncmenu_item_set_status(struct ncmenu* n, const char* section,
4161 const char* item, bool enabled);
4162
4163// Return the selected item description, or NULL if no section is unrolled. If
4164// 'ni' is not NULL, and the selected item has a shortcut, 'ni' will be filled
4165// in with that shortcut--this can allow faster matching.
4166API const char* ncmenu_selected(const struct ncmenu* n, ncinput* ni);
4167
4168// Return the item description corresponding to the mouse click 'click'. The
4169// item must be on an actively unrolled section, and the click must be in the
4170// area of a valid item. If 'ni' is not NULL, and the selected item has a
4171// shortcut, 'ni' will be filled in with the shortcut.
4172API const char* ncmenu_mouse_selected(const struct ncmenu* n,
4173 const ncinput* click, ncinput* ni);
4174
4175// Return the ncplane backing this ncmenu.
4176API struct ncplane* ncmenu_plane(struct ncmenu* n);
4177
4178// Offer the input to the ncmenu. If it's relevant, this function returns true,
4179// and the input ought not be processed further. If it's irrelevant to the
4180// menu, false is returned. Relevant inputs include:
4181// * mouse movement over a hidden menu
4182// * a mouse click on a menu section (the section is unrolled)
4183// * a mouse click outside of an unrolled menu (the menu is rolled up)
4184// * left or right on an unrolled menu (navigates among sections)
4185// * up or down on an unrolled menu (navigates among items)
4186// * escape on an unrolled menu (the menu is rolled up)
4187API bool ncmenu_offer_input(struct ncmenu* n, const ncinput* nc)
4188 __attribute__ ((nonnull (1, 2)));
4189
4190// Destroy a menu created with ncmenu_create().
4191API void ncmenu_destroy(struct ncmenu* n);
4192
4193// Progress bars. They proceed linearly in any of four directions. The entirety
4194// of the plane will be used -- any border should be provided by the caller on
4195// another plane. The plane will not be erased; text preloaded into the plane
4196// will be consumed by the progress indicator. The bar is redrawn for each
4197// provided progress report (a double between 0 and 1), and can regress with
4198// lower values. The procession will take place along the longer dimension (at
4199// the time of each redraw), with the horizontal length scaled by 2 for
4200// purposes of comparison. I.e. for a plane of 20 rows and 50 columns, the
4201// progress will be to the right (50 > 40) or left with OPTION_RETROGRADE.
4202
4203#define NCPROGBAR_OPTION_RETROGRADE 0x0001u // proceed left/down
4204
4205typedef struct ncprogbar_options {
4206 uint32_t ulchannel; // upper-left channel. in the context of a progress bar,
4207 uint32_t urchannel; // "up" is the direction we are progressing towards, and
4208 uint32_t blchannel; // "bottom" is the direction of origin. for monochromatic
4209 uint32_t brchannel; // bar, all four channels ought be the same.
4210 uint64_t flags;
4212
4213// Takes ownership of the ncplane 'n', which will be destroyed by
4214// ncprogbar_destroy(). The progress bar is initially at 0%.
4216 __attribute__ ((nonnull (1)));
4217
4218// Return a reference to the ncprogbar's underlying ncplane.
4219API struct ncplane* ncprogbar_plane(struct ncprogbar* n)
4220 __attribute__ ((nonnull (1)));
4221
4222// Set the progress bar's completion, a double 0 <= 'p' <= 1.
4223API int ncprogbar_set_progress(struct ncprogbar* n, double p)
4224 __attribute__ ((nonnull (1)));
4225
4226// Get the progress bar's completion, a double on [0, 1].
4227API double ncprogbar_progress(const struct ncprogbar* n)
4228 __attribute__ ((nonnull (1)));
4229
4230// Destroy the progress bar and its underlying ncplane.
4231API void ncprogbar_destroy(struct ncprogbar* n);
4232
4233// Tabbed widgets. The tab list is displayed at the top or at the bottom of the
4234// plane, and only one tab is visible at a time.
4235
4236// Display the tab list at the bottom instead of at the top of the plane
4237#define NCTABBED_OPTION_BOTTOM 0x0001ull
4238
4239typedef struct nctabbed_options {
4240 uint64_t selchan; // channel for the selected tab header
4241 uint64_t hdrchan; // channel for unselected tab headers
4242 uint64_t sepchan; // channel for the tab separator
4243 const char* separator; // separator string (copied by nctabbed_create())
4244 uint64_t flags; // bitmask of NCTABBED_OPTION_*
4246
4247// Tab content drawing callback. Takes the tab it was associated to, the ncplane
4248// on which tab content is to be drawn, and the user pointer of the tab.
4249// It is called during nctabbed_redraw().
4250typedef void (*tabcb)(struct nctab* t, struct ncplane* ncp, void* curry);
4251
4252// Creates a new nctabbed widget, associated with the given ncplane 'n', and with
4253// additional options given in 'opts'. When 'opts' is NULL, it acts as if it were
4254// called with an all-zero opts. The widget takes ownership of 'n', and destroys
4255// it when the widget is destroyed. Returns the newly created widget. Returns
4256// NULL on failure, also destroying 'n'.
4258 __attribute ((nonnull (1)));
4259
4260// Destroy an nctabbed widget. All memory belonging to 'nt' is deallocated,
4261// including all tabs and their names. The plane associated with 'nt' is also
4262// destroyed. Calling this with NULL does nothing.
4263API void nctabbed_destroy(struct nctabbed* nt);
4264
4265// Redraw the widget. This calls the tab callback of the currently selected tab
4266// to draw tab contents, and draws tab headers. The tab content plane is not
4267// modified by this function, apart from resizing the plane is necessary.
4268API void nctabbed_redraw(struct nctabbed* nt)
4269 __attribute__ ((nonnull (1)));
4270
4271// Make sure the tab header of the currently selected tab is at least partially
4272// visible. (by rotating tabs until at least one column is displayed)
4273// Does nothing if there are no tabs.
4275 __attribute__ ((nonnull (1)));
4276
4277// Returns the currently selected tab, or NULL if there are no tabs.
4278API struct nctab* nctabbed_selected(struct nctabbed* nt)
4279 __attribute__ ((nonnull (1)));
4280
4281// Returns the leftmost tab, or NULL if there are no tabs.
4282API struct nctab* nctabbed_leftmost(struct nctabbed* nt)
4283 __attribute__ ((nonnull (1)));
4284
4285// Returns the number of tabs in the widget.
4286API int nctabbed_tabcount(struct nctabbed* nt)
4287 __attribute__ ((nonnull (1)));
4288
4289// Returns the plane associated to 'nt'.
4290API struct ncplane* nctabbed_plane(struct nctabbed* nt)
4291 __attribute__ ((nonnull (1)));
4292
4293// Returns the tab content plane.
4294API struct ncplane* nctabbed_content_plane(struct nctabbed* nt)
4295 __attribute__ ((nonnull (1)));
4296
4297// Returns the tab callback.
4298API tabcb nctab_cb(struct nctab* t)
4299 __attribute__ ((nonnull (1)));
4300
4301// Returns the tab name. This is not a copy and it should not be stored.
4302API const char* nctab_name(struct nctab* t)
4303 __attribute__ ((nonnull (1)));
4304
4305// Returns the width (in columns) of the tab's name.
4306API int nctab_name_width(struct nctab* t)
4307 __attribute__ ((nonnull (1)));
4308
4309// Returns the tab's user pointer.
4310API void* nctab_userptr(struct nctab* t)
4311 __attribute__ ((nonnull (1)));
4312
4313// Returns the tab to the right of 't'. This does not change which tab is selected.
4314API struct nctab* nctab_next(struct nctab* t)
4315 __attribute__ ((nonnull (1)));
4316
4317// Returns the tab to the left of 't'. This does not change which tab is selected.
4318API struct nctab* nctab_prev(struct nctab* t)
4319 __attribute__ ((nonnull (1)));
4320
4321// Add a new tab to 'nt' with the given tab callback, name, and user pointer.
4322// If both 'before' and 'after' are NULL, the tab is inserted after the selected
4323// tab. Otherwise, it gets put after 'after' (if not NULL) and before 'before'
4324// (if not NULL). If both 'after' and 'before' are given, they must be two
4325// neighboring tabs (the tab list is circular, so the last tab is immediately
4326// before the leftmost tab), otherwise the function returns NULL. If 'name' is
4327// NULL or a string containing illegal characters, the function returns NULL.
4328// On all other failures the function also returns NULL. If it returns NULL,
4329// none of the arguments are modified, and the widget state is not altered.
4330API ALLOC struct nctab* nctabbed_add(struct nctabbed* nt, struct nctab* after,
4331 struct nctab* before, tabcb tcb,
4332 const char* name, void* opaque)
4333 __attribute__ ((nonnull (1, 5)));
4334
4335// Remove a tab 't' from 'nt'. Its neighboring tabs become neighbors to each
4336// other. If 't' if the selected tab, the tab after 't' becomes selected.
4337// Likewise if 't' is the leftmost tab, the tab after 't' becomes leftmost.
4338// If 't' is the only tab, there will no more be a selected or leftmost tab,
4339// until a new tab is added. Returns -1 if 't' is NULL, and 0 otherwise.
4340API int nctabbed_del(struct nctabbed* nt, struct nctab* t)
4341 __attribute__ ((nonnull (1)));
4342
4343// Move 't' after 'after' (if not NULL) and before 'before' (if not NULL).
4344// If both 'after' and 'before' are NULL, the function returns -1, otherwise
4345// it returns 0.
4346API int nctab_move(struct nctabbed* nt, struct nctab* t, struct nctab* after,
4347 struct nctab* before)
4348 __attribute__ ((nonnull (1, 2)));
4349
4350// Move 't' to the right by one tab, looping around to become leftmost if needed.
4351API void nctab_move_right(struct nctabbed* nt, struct nctab* t)
4352 __attribute__ ((nonnull (1, 2)));
4353
4354// Move 't' to the right by one tab, looping around to become the last tab if needed.
4355API void nctab_move_left(struct nctabbed* nt, struct nctab* t)
4356 __attribute__ ((nonnull (1, 2)));
4357
4358// Rotate the tabs of 'nt' right by 'amt' tabs, or '-amt' tabs left if 'amt' is
4359// negative. Tabs are rotated only by changing the leftmost tab; the selected tab
4360// stays the same. If there are no tabs, nothing happens.
4361API void nctabbed_rotate(struct nctabbed* nt, int amt)
4362 __attribute__ ((nonnull (1)));
4363
4364// Select the tab after the currently selected tab, and return the newly selected
4365// tab. Returns NULL if there are no tabs.
4366API struct nctab* nctabbed_next(struct nctabbed* nt)
4367 __attribute__ ((nonnull (1)));
4368
4369// Select the tab before the currently selected tab, and return the newly selected
4370// tab. Returns NULL if there are no tabs.
4371API struct nctab* nctabbed_prev(struct nctabbed* nt)
4372 __attribute__ ((nonnull (1)));
4373
4374// Change the selected tab to be 't'. Returns the previously selected tab.
4375API struct nctab* nctabbed_select(struct nctabbed* nt, struct nctab* t)
4376 __attribute__ ((nonnull (1, 2)));
4377
4378// Write the channels for tab headers, the selected tab header, and the separator
4379// to '*hdrchan', '*selchan', and '*sepchan' respectively.
4380API void nctabbed_channels(struct nctabbed* nt, uint64_t* RESTRICT hdrchan,
4381 uint64_t* RESTRICT selchan, uint64_t* RESTRICT sepchan)
4382 __attribute__ ((nonnull (1)));
4383
4384static inline uint64_t
4385nctabbed_hdrchan(struct nctabbed* nt){
4386 uint64_t ch;
4387 nctabbed_channels(nt, &ch, NULL, NULL);
4388 return ch;
4389}
4390
4391static inline uint64_t
4392nctabbed_selchan(struct nctabbed* nt){
4393 uint64_t ch;
4394 nctabbed_channels(nt, NULL, &ch, NULL);
4395 return ch;
4396}
4397
4398static inline uint64_t
4399nctabbed_sepchan(struct nctabbed* nt){
4400 uint64_t ch;
4401 nctabbed_channels(nt, NULL, NULL, &ch);
4402 return ch;
4403}
4404
4405// Returns the tab separator. This is not a copy and it should not be stored.
4406// This can be NULL, if the separator was set to NULL in ncatbbed_create() or
4407// nctabbed_set_separator().
4408API const char* nctabbed_separator(struct nctabbed* nt)
4409 __attribute__ ((nonnull (1)));
4410
4411// Returns the tab separator width, or zero if there is no separator.
4413 __attribute__ ((nonnull (1)));
4414
4415// Set the tab headers channel for 'nt'.
4416API void nctabbed_set_hdrchan(struct nctabbed* nt, uint64_t chan)
4417 __attribute__ ((nonnull (1)));
4418
4419// Set the selected tab header channel for 'nt'.
4420API void nctabbed_set_selchan(struct nctabbed* nt, uint64_t chan)
4421 __attribute__ ((nonnull (1)));
4422
4423// Set the tab separator channel for 'nt'.
4424API void nctabbed_set_sepchan(struct nctabbed* nt, uint64_t chan)
4425 __attribute__ ((nonnull (1)));
4426
4427// Set the tab callback function for 't'. Returns the previous tab callback.
4428API tabcb nctab_set_cb(struct nctab* t, tabcb newcb)
4429 __attribute__ ((nonnull (1)));
4430
4431// Change the name of 't'. Returns -1 if 'newname' is NULL, and 0 otherwise.
4432API int nctab_set_name(struct nctab* t, const char* newname)
4433 __attribute__ ((nonnull (1, 2)));
4434
4435// Set the user pointer of 't'. Returns the previous user pointer.
4436API void* nctab_set_userptr(struct nctab* t, void* newopaque)
4437 __attribute__ ((nonnull (1)));
4438
4439// Change the tab separator for 'nt'. Returns -1 if 'separator' is not NULL and
4440// is not a valid string, and 0 otherwise.
4441API int nctabbed_set_separator(struct nctabbed* nt, const char* separator)
4442 __attribute__ ((nonnull (1, 2)));
4443
4444// Plots. Given a rectilinear area, an ncplot can graph samples along some axis.
4445// There is some underlying independent variable--this could be e.g. measurement
4446// sequence number, or measurement time. Samples are tagged with this variable, which
4447// should never fall, but may grow non-monotonically. The desired range in terms
4448// of the underlying independent variable is provided at creation time. The
4449// desired domain can be specified, or can be autosolved. Granularity of the
4450// dependent variable depends on glyph selection.
4451//
4452// For instance, perhaps we're sampling load as a time series. We want to
4453// display an hour's worth of samples in 40 columns and 5 rows. We define the
4454// x-axis to be the independent variable, time. We'll stamp at second
4455// granularity. In this case, there are 60 * 60 == 3600 total elements in the
4456// range. Each column will thus cover a 90s span. Using vertical blocks (the
4457// most granular glyph), we have 8 * 5 == 40 levels of domain. If we report the
4458// following samples, starting at 0, using autosolving, we will observe:
4459//
4460// 60 -- 1% |domain: 1--1, 0: 20 levels
4461// 120 -- 50% |domain: 1--50, 0: 0 levels, 1: 40 levels
4462// 180 -- 50% |domain: 1--50, 0: 0 levels, 1: 40 levels, 2: 40 levels
4463// 240 -- 100% |domain: 1--75, 0: 1, 1: 27, 2: 40
4464// 271 -- 100% |domain: 1--100, 0: 0, 1: 20, 2: 30, 3: 40
4465// 300 -- 25% |domain: 1--75, 0: 0, 1: 27, 2: 40, 3: 33
4466//
4467// At the end, we have data in 4 90s spans: [0--89], [90--179], [180--269], and
4468// [270--359]. The first two spans have one sample each, while the second two
4469// have two samples each. Samples within a span are averaged (FIXME we could
4470// probably do better), so the results are 0, 50, 75, and 62.5. Scaling each of
4471// these out of 90 and multiplying by 40 gets our resulting levels. The final
4472// domain is 75 rather than 100 due to the averaging of 100+25/2->62.5 in the
4473// third span, at which point the maximum span value is once again 75.
4474//
4475// The 20 levels at first is a special case. When the domain is only 1 unit,
4476// and autoscaling is in play, assign 50%.
4477//
4478// This options structure works for both the ncuplot (uint64_t) and ncdplot
4479// (double) types.
4480#define NCPLOT_OPTION_LABELTICKSD 0x0001u // show labels for dependent axis
4481#define NCPLOT_OPTION_EXPONENTIALD 0x0002u // exponential dependent axis
4482#define NCPLOT_OPTION_VERTICALI 0x0004u // independent axis is vertical
4483#define NCPLOT_OPTION_NODEGRADE 0x0008u // fail rather than degrade blitter
4484#define NCPLOT_OPTION_DETECTMAXONLY 0x0010u // use domain detection only for max
4485#define NCPLOT_OPTION_PRINTSAMPLE 0x0020u // print the most recent sample
4486
4487typedef struct ncplot_options {
4488 // channels for the maximum and minimum levels. linear or exponential
4489 // interpolation will be applied across the domain between these two.
4490 uint64_t maxchannels;
4491 uint64_t minchannels;
4492 // styling used for the legend, if NCPLOT_OPTION_LABELTICKSD is set
4493 uint16_t legendstyle;
4494 // if you don't care, pass NCBLIT_DEFAULT and get NCBLIT_8x1 (assuming
4495 // UTF8) or NCBLIT_1x1 (in an ASCII environment)
4496 ncblitter_e gridtype; // number of "pixels" per row x column
4497 // independent variable can either be a contiguous range, or a finite set
4498 // of keys. for a time range, say the previous hour sampled with second
4499 // resolution, the independent variable would be the range [0..3600): 3600.
4500 // if rangex is 0, it is dynamically set to the number of columns.
4502 const char* title; // optional, printed by the labels
4503 uint64_t flags; // bitfield over NCPLOT_OPTION_*
4505
4506// Use the provided plane 'n' for plotting according to the options 'opts'. The
4507// plot will make free use of the entirety of the plane. For domain
4508// autodiscovery, set miny == maxy == 0. ncuplot holds uint64_ts, while
4509// ncdplot holds doubles.
4510API ALLOC struct ncuplot* ncuplot_create(struct ncplane* n, const ncplot_options* opts,
4511 uint64_t miny, uint64_t maxy)
4512 __attribute__ ((nonnull (1)));
4513
4514API ALLOC struct ncdplot* ncdplot_create(struct ncplane* n, const ncplot_options* opts,
4515 double miny, double maxy)
4516 __attribute__ ((nonnull (1)));
4517
4518// Return a reference to the ncplot's underlying ncplane.
4519API struct ncplane* ncuplot_plane(struct ncuplot* n)
4520 __attribute__ ((nonnull (1)));
4521
4522API struct ncplane* ncdplot_plane(struct ncdplot* n)
4523 __attribute__ ((nonnull (1)));
4524
4525// Add to or set the value corresponding to this x. If x is beyond the current
4526// x window, the x window is advanced to include x, and values passing beyond
4527// the window are lost. The first call will place the initial window. The plot
4528// will be redrawn, but notcurses_render() is not called.
4529API int ncuplot_add_sample(struct ncuplot* n, uint64_t x, uint64_t y)
4530 __attribute__ ((nonnull (1)));
4531API int ncdplot_add_sample(struct ncdplot* n, uint64_t x, double y)
4532 __attribute__ ((nonnull (1)));
4533API int ncuplot_set_sample(struct ncuplot* n, uint64_t x, uint64_t y)
4534 __attribute__ ((nonnull (1)));
4535API int ncdplot_set_sample(struct ncdplot* n, uint64_t x, double y)
4536 __attribute__ ((nonnull (1)));
4537
4538API int ncuplot_sample(const struct ncuplot* n, uint64_t x, uint64_t* y)
4539 __attribute__ ((nonnull (1)));
4540API int ncdplot_sample(const struct ncdplot* n, uint64_t x, double* y)
4541 __attribute__ ((nonnull (1)));
4542
4543API void ncuplot_destroy(struct ncuplot* n);
4544API void ncdplot_destroy(struct ncdplot* n);
4545
4546typedef int(*ncfdplane_callback)(struct ncfdplane* n, const void* buf, size_t s, void* curry);
4547typedef int(*ncfdplane_done_cb)(struct ncfdplane* n, int fderrno, void* curry);
4548
4549// read from an fd until EOF (or beyond, if follow is set), invoking the user's
4550// callback each time. runs in its own context. on EOF or error, the finalizer
4551// callback will be invoked, and the user ought destroy the ncfdplane. the
4552// data is *not* guaranteed to be nul-terminated, and may contain arbitrary
4553// zeroes.
4554typedef struct ncfdplane_options {
4555 void* curry; // parameter provided to callbacks
4556 bool follow; // keep reading after hitting end? (think tail -f)
4557 uint64_t flags; // bitfield over NCOPTION_FDPLANE_*
4559
4560// Create an ncfdplane around the fd 'fd'. Consider this function to take
4561// ownership of the file descriptor, which will be closed in ncfdplane_destroy().
4563 int fd, ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn)
4564 __attribute__ ((nonnull (1)));
4565
4566API struct ncplane* ncfdplane_plane(struct ncfdplane* n)
4567 __attribute__ ((nonnull (1)));
4568
4569API int ncfdplane_destroy(struct ncfdplane* n);
4570
4571typedef struct ncsubproc_options {
4572 void* curry;
4573 uint64_t restart_period; // restart this many seconds after an exit (watch)
4574 uint64_t flags; // bitfield over NCOPTION_SUBPROC_*
4576
4577// see exec(2). p-types use $PATH. e-type passes environment vars.
4579 const char* bin, const char* const arg[],
4580 ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn)
4581 __attribute__ ((nonnull (1)));
4582
4584 const char* bin, const char* const arg[],
4585 ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn)
4586 __attribute__ ((nonnull (1)));
4587
4589 const char* bin, const char* const arg[],
4590 const char* const env[],
4591 ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn)
4592 __attribute__ ((nonnull (1)));
4593
4594API struct ncplane* ncsubproc_plane(struct ncsubproc* n)
4595 __attribute__ ((nonnull (1)));
4596
4597API int ncsubproc_destroy(struct ncsubproc* n);
4598
4599// Draw a QR code at the current position on the plane. If there is insufficient
4600// room to draw the code here, or there is any other error, non-zero will be
4601// returned. Otherwise, the QR code "version" (size) is returned. The QR code
4602// is (version * 4 + 17) columns wide, and ⌈version * 4 + 17⌉ rows tall (the
4603// properly-scaled values are written back to '*ymax' and '*xmax').
4604// NCBLIT_2x1 is always used, and the call will fail if it is not available,
4605// as only this blitter can generate a proper aspect ratio.
4606API int ncplane_qrcode(struct ncplane* n, unsigned* ymax, unsigned* xmax,
4607 const void* data, size_t len)
4608 __attribute__ ((nonnull (1, 4)));
4609
4610// Enable horizontal scrolling. Virtual lines can then grow arbitrarily long.
4611#define NCREADER_OPTION_HORSCROLL 0x0001ull
4612// Enable vertical scrolling. You can then use arbitrarily many virtual lines.
4613#define NCREADER_OPTION_VERSCROLL 0x0002ull
4614// Disable all editing shortcuts. By default, emacs-style keys are available.
4615#define NCREADER_OPTION_NOCMDKEYS 0x0004ull
4616// Make the terminal cursor visible across the lifetime of the ncreader, and
4617// have the ncreader manage the cursor's placement.
4618#define NCREADER_OPTION_CURSOR 0x0008ull
4619
4620typedef struct ncreader_options {
4621 uint64_t tchannels; // channels used for input
4622 uint32_t tattrword; // attributes used for input
4623 uint64_t flags; // bitfield of NCREADER_OPTION_*
4625
4626// ncreaders provide freeform input in a (possibly multiline) region, supporting
4627// optional readline keybindings. takes ownership of 'n', destroying it on any
4628// error (ncreader_destroy() otherwise destroys the ncplane).
4630 __attribute__ ((nonnull (1)));
4631
4632// empty the ncreader of any user input, and home the cursor.
4633API int ncreader_clear(struct ncreader* n)
4634 __attribute__ ((nonnull (1)));
4635
4636API struct ncplane* ncreader_plane(struct ncreader* n)
4637 __attribute__ ((nonnull (1)));
4638
4639// Offer the input to the ncreader. If it's relevant, this function returns
4640// true, and the input ought not be processed further. Almost all inputs
4641// are relevant to an ncreader, save synthesized ones.
4643 __attribute__ ((nonnull (1, 2)));
4644
4645// Atttempt to move in the specified direction. Returns 0 if a move was
4646// successfully executed, -1 otherwise. Scrolling is taken into account.
4647API int ncreader_move_left(struct ncreader* n)
4648 __attribute__ ((nonnull (1)));
4649API int ncreader_move_right(struct ncreader* n)
4650 __attribute__ ((nonnull (1)));
4651API int ncreader_move_up(struct ncreader* n)
4652 __attribute__ ((nonnull (1)));
4653API int ncreader_move_down(struct ncreader* n)
4654 __attribute__ ((nonnull (1)));
4655
4656// Destructively write the provided EGC to the current cursor location. Move
4657// the cursor as necessary, scrolling if applicable.
4658API int ncreader_write_egc(struct ncreader* n, const char* egc)
4659 __attribute__ ((nonnull (1, 2)));
4660
4661// return a heap-allocated copy of the current (UTF-8) contents.
4662API char* ncreader_contents(const struct ncreader* n)
4663 __attribute__ ((nonnull (1)));
4664
4665// destroy the reader and its bound plane. if 'contents' is not NULL, the
4666// UTF-8 input will be heap-duplicated and written to 'contents'.
4667API void ncreader_destroy(struct ncreader* n, char** contents);
4668
4669// Returns a heap-allocated copy of the user name under which we are running.
4670API ALLOC char* notcurses_accountname(void);
4671
4672// Returns a heap-allocated copy of the local host name.
4673API ALLOC char* notcurses_hostname(void);
4674
4675// Returns a heap-allocated copy of human-readable OS name and version.
4676API ALLOC char* notcurses_osversion(void);
4677
4678// Dump selected Notcurses state to the supplied 'debugfp'. Output is freeform,
4679// newline-delimited, and subject to change. It includes geometry of all
4680// planes, from all piles. No line has more than 80 columns' worth of output.
4681API void notcurses_debug(const struct notcurses* nc, FILE* debugfp)
4682 __attribute__ ((nonnull (1, 2)));
4683
4684#undef API
4685#undef ALLOC
4686
4687#ifdef __cplusplus
4688} // extern "C"
4689#endif
4690
4691#endif
API int API int API int uint64_t uint64_t uint64_t uint64_t lr
Definition direct.h:216
API int API int API int uint64_t uint64_t uint64_t uint64_t unsigned unsigned unsigned ctlword
Definition direct.h:217
API int API int API int uint64_t uint64_t uint64_t ll
Definition direct.h:216
API int API int API int uint64_t uint64_t uint64_t uint64_t unsigned unsigned xlen
Definition direct.h:217
API int API int API int uint64_t uint64_t uint64_t uint64_t unsigned ylen
Definition direct.h:217
API int API int API int uint64_t ul
Definition direct.h:215
API int API int API int uint64_t uint64_t ur
Definition direct.h:215
const char * egc
Definition egcpool.h:173
const char size_t ulen
Definition egcpool.h:173
uint32_t idx
Definition egcpool.h:298
free(duplicated)
va_end(va)
const char va_start(va, fmt)
int r
Definition fbuf.h:226
#define NCKEY_MOD_META
Definition nckeys.h:224
#define NCKEY_MOD_NUMLOCK
Definition nckeys.h:226
#define NCKEY_MOD_SHIFT
Definition nckeys.h:219
#define NCKEY_MOD_CTRL
Definition nckeys.h:221
#define NCKEY_BUTTON11
Definition nckeys.h:176
#define NCKEY_MOD_CAPSLOCK
Definition nckeys.h:225
#define NCKEY_MOD_HYPER
Definition nckeys.h:223
#define NCKEY_MOD_ALT
Definition nckeys.h:220
#define NCKEY_MOD_SUPER
Definition nckeys.h:222
#define NCKEY_MOTION
Definition nckeys.h:165
#define htole(x)
Definition ncport.h:36
#define NCBOXROUND
Definition ncseqs.h:122
#define NCBOXLIGHT
Definition ncseqs.h:120
#define NCBOXASCII
Definition ncseqs.h:124
#define NCBOXHEAVY
Definition ncseqs.h:121
#define NCBOXDOUBLE
Definition ncseqs.h:123
const char * nccell_extended_gcluster(const ncplane *n, const nccell *c)
Definition notcurses.c:1573
#define NCVISUAL_OPTION_CHILDPLANE
Definition notcurses.h:3342
API int notcurses_default_foreground(const struct notcurses *nc, uint32_t *fg) __attribute__((nonnull(1)))
Definition render.c:1712
API int notcurses_refresh(struct notcurses *n, unsigned *RESTRICT y, unsigned *RESTRICT x) __attribute__((nonnull(1)))
API ALLOC struct nctabbed * nctabbed_create(struct ncplane *n, const nctabbed_options *opts) __attribute((nonnull(1)))
Definition tabbed.c:148
API int API int API void nctree_destroy(struct nctree *n)
Definition tree.c:294
API ALLOC struct nctablet * ncreel_add(struct ncreel *nr, struct nctablet *after, struct nctablet *before, tabletcb cb, void *opaque) __attribute__((nonnull(1)))
Definition reel.c:838
API int ncplane_polyfill_yx(struct ncplane *n, int y, int x, const nccell *c) __attribute__((nonnull(1
API void ncplane_set_styles(struct ncplane *n, unsigned stylebits) __attribute__((nonnull(1)))
Definition notcurses.c:2071
ncscale_e
Definition notcurses.h:96
@ NCSCALE_SCALE_HIRES
Definition notcurses.h:101
@ NCSCALE_STRETCH
Definition notcurses.h:99
@ NCSCALE_SCALE
Definition notcurses.h:98
@ NCSCALE_NONE
Definition notcurses.h:97
@ NCSCALE_NONE_HIRES
Definition notcurses.h:100
API int ncvisual_polyfill_yx(struct ncvisual *n, unsigned y, unsigned x, uint32_t rgba) __attribute__((nonnull(1)))
Definition visual.c:1344
API uint64_t ncplane_channels(const struct ncplane *n) __attribute__((nonnull(1)))
API int ncreader_move_up(struct ncreader *n) __attribute__((nonnull(1)))
Definition reader.c:187
API struct ncplane * ncmultiselector_plane(struct ncmultiselector *n)
Definition selector.c:586
API struct nctab * nctabbed_prev(struct nctabbed *nt) __attribute__((nonnull(1)))
Definition tabbed.c:376
API int ncplane_move_above(struct ncplane *RESTRICT n, struct ncplane *RESTRICT above) __attribute__((nonnull(1)))
API void ncprogbar_destroy(struct ncprogbar *n)
Definition progbar.c:190
API __attribute__((returns_nonnull)) const char *nccell_extended_gcluster(const struct ncplane *n
int y
Definition notcurses.h:1905
API void nctabbed_set_sepchan(struct nctabbed *nt, uint64_t chan) __attribute__((nonnull(1)))
Definition tabbed.c:444
API char * ncplane_at_cursor(const struct ncplane *n, uint16_t *stylemask, uint64_t *channels) __attribute__((nonnull(1)))
API void ncvisual_destroy(struct ncvisual *ncv)
Definition visual.c:1225
API void nctabbed_redraw(struct nctabbed *nt) __attribute__((nonnull(1)))
Definition tabbed.c:23
API int ncmenu_nextsection(struct ncmenu *n) __attribute__((nonnull(1)))
Definition menu.c:563
API int ncplane_base(struct ncplane *n, nccell *c)
Definition notcurses.c:1569
API const char * nctabbed_separator(struct nctabbed *nt) __attribute__((nonnull(1)))
Definition tabbed.c:403
API struct ncplane * ncplane_reparent(struct ncplane *n, struct ncplane *newparent) __attribute__((nonnull(1
API int ncplane_resize(struct ncplane *n, int keepy, int keepx, unsigned keepleny, unsigned keeplenx, int yoff, int xoff, unsigned ylen, unsigned xlen)
Definition notcurses.c:1006
API struct ncplane * ncreel_plane(struct ncreel *nr) __attribute__((nonnull(1)))
Definition reel.c:803
return newn
Definition notcurses.h:3508
API const char * nctab_name(struct nctab *t) __attribute__((nonnull(1)))
Definition tabbed.c:128
API ALLOC struct ncvisual * ncvisual_from_sixel(const char *s, unsigned leny, unsigned lenx) __attribute__((nonnull(1)))
Definition visual.c:806
API int ncplane_mergedown_simple(struct ncplane *RESTRICT src, struct ncplane *RESTRICT dst) __attribute__((nonnull(1
API int API int ncplane_mergedown(struct ncplane *RESTRICT src, struct ncplane *RESTRICT dst, int begsrcy, int begsrcx, unsigned leny, unsigned lenx, int dsty, int dstx) __attribute__((nonnull(1
API int ncplane_putwegc_stained(struct ncplane *n, const wchar_t *gclust, size_t *sbytes) __attribute__((nonnull(1
API int ncvisual_simple_streamer(struct ncvisual *ncv, struct ncvisual_options *vopts, const struct timespec *tspec, void *curry) __attribute__((nonnull(1)))
Definition visual.c:1238
API ALLOC struct ncselector * ncselector_create(struct ncplane *n, const ncselector_options *opts) __attribute__((nonnull(1)))
Definition selector.c:280
API bool API int ncreader_move_left(struct ncreader *n) __attribute__((nonnull(1)))
Definition reader.c:115
API int ncplane_set_bg_palindex(struct ncplane *n, unsigned idx)
Definition notcurses.c:1554
API uint32_t notcurses_get(struct notcurses *n, const struct timespec *ts, ncinput *ni) __attribute__((nonnull(1)))
Definition in.c:2751
API ALLOC struct ncplane * ncplane_create(struct ncplane *n, const ncplane_options *nopts) __attribute__((nonnull(1
API int API void nctab_move_right(struct nctabbed *nt, struct nctab *t) __attribute__((nonnull(1
API ALLOC char * notcurses_accountname(void)
Definition util.c:35
API int ncplane_set_bg_rgb(struct ncplane *n, uint32_t channel)
API struct ncplane * ncmenu_plane(struct ncmenu *n)
Definition menu.c:821
API void ncplane_dim_yx(const struct ncplane *n, unsigned *RESTRICT y, unsigned *RESTRICT x) __attribute__((nonnull(1)))
API int ncpile_render(struct ncplane *n) __attribute__((nonnull(1)))
Definition render.c:1569
API int notcurses_enter_alternate_screen(struct notcurses *nc) __attribute__((nonnull(1)))
Definition notcurses.c:31
#define ALLOC
Definition notcurses.h:36
API bool notcurses_canopen_videos(const struct notcurses *nc) __attribute__((pure))
API ALLOC struct ncprogbar * ncprogbar_create(struct ncplane *n, const ncprogbar_options *opts) __attribute__((nonnull(1)))
Definition progbar.c:4
API struct ncplane * ncselector_plane(struct ncselector *n) __attribute__((nonnull(1)))
Definition selector.c:470
#define WCHAR_MAX_UTF8BYTES
Definition notcurses.h:594
API int ncplane_fadeout_iteration(struct ncplane *n, struct ncfadectx *nctx, int iter, fadecb fader, void *curry) __attribute__((nonnull(1
const struct ncplane_options struct ncvisual * ncv
Definition notcurses.h:3484
API int ncmenu_previtem(struct ncmenu *n) __attribute__((nonnull(1)))
Definition menu.c:614
API int ncreader_move_right(struct ncreader *n) __attribute__((nonnull(1)))
Definition reader.c:152
API int ncplane_set_bg_rgb8(struct ncplane *n, unsigned r, unsigned g, unsigned b)
Definition notcurses.c:1514
API struct ncplane * ncfdplane_plane(struct ncfdplane *n) __attribute__((nonnull(1)))
Definition fd.c:132
void(* tabcb)(struct nctab *t, struct ncplane *ncp, void *curry)
Definition notcurses.h:4250
API int nctabbed_tabcount(struct nctabbed *nt) __attribute__((nonnull(1)))
Definition tabbed.c:112
#define NCIPREFIXSTRLEN
Definition notcurses.h:3829
#define NCALPHA_OPAQUE
Definition notcurses.h:108
API int ncvisual_resize(struct ncvisual *n, int rows, int cols) __attribute__((nonnull(1)))
Definition visual.c:982
API int notcurses_stop(struct notcurses *nc)
Definition notcurses.c:1446
API int notcurses_cursor_yx(const struct notcurses *nc, int *y, int *x) __attribute__((nonnull(1)))
API const char * ncselector_selected(const struct ncselector *n) __attribute__((nonnull(1)))
API int ncplane_cursor_move_yx(struct ncplane *n, int y, int x) __attribute__((nonnull(1)))
Definition notcurses.c:720
#define NC_BG_PALETTE
Definition notcurses.h:123
API struct ncplane * nctabbed_plane(struct nctabbed *nt) __attribute__((nonnull(1)))
Definition tabbed.c:116
API struct ncplane * ncvisual_blit(struct notcurses *nc, struct ncvisual *ncv, const struct ncvisual_options *vopts) __attribute__((nonnull(2)))
Definition visual.c:1136
API int ncplane_set_base(struct ncplane *n, const char *egc, uint16_t stylemask, uint64_t channels)
Definition notcurses.c:1565
API int ncstrwidth(const char *egcs, int *validbytes, int *validwidth) __attribute__((nonnull(1)))
Definition notcurses.c:3309
#define NCSTYLE_MASK
Definition notcurses.h:769
API struct notcurses * ncplane_notcurses(const struct ncplane *n) __attribute__((nonnull(1)))
int(* fadecb)(struct notcurses *nc, struct ncplane *n, const struct timespec *, void *curry)
Definition notcurses.h:3029
API int notcurses_getvec(struct notcurses *n, const struct timespec *ts, ncinput *ni, int vcount) __attribute__((nonnull(1
API struct ncplane * notcurses_stdplane(struct notcurses *nc) __attribute__((nonnull(1)))
Definition notcurses.c:699
const struct ncplane_options struct ncvisual struct ncvisual_options * vopts
Definition notcurses.h:3484
API bool ncplane_translate_abs(const struct ncplane *n, int *RESTRICT y, int *RESTRICT x) __attribute__((nonnull(1)))
API void ncplane_abs_yx(const struct ncplane *n, int *RESTRICT y, int *RESTRICT x) __attribute__((nonnull(1)))
API const char * ncmenu_selected(const struct ncmenu *n, ncinput *ni)
API int notcurses_ucs32_to_utf8(const uint32_t *ucs32, unsigned ucs32count, unsigned char *resultbuf, size_t buflen) __attribute__((nonnull(1
API struct nctab * nctabbed_select(struct nctabbed *nt, struct nctab *t) __attribute__((nonnull(1
API bool ncplane_scrolling_p(const struct ncplane *n) __attribute__((nonnull(1)))
API bool ncreel_offer_input(struct ncreel *nr, const ncinput *ni) __attribute__((nonnull(1
API int notcurses_cursor_enable(struct notcurses *nc, int y, int x) __attribute__((nonnull(1)))
Definition render.c:1738
API ALLOC struct notcurses * notcurses_init(const notcurses_options *opts, FILE *fp)
API int notcurses_cursor_disable(struct notcurses *nc) __attribute__((nonnull(1)))
Definition render.c:1772
API int API int ncvisual_set_yx(const struct ncvisual *n, unsigned y, unsigned x, uint32_t pixel) __attribute__((nonnull(1)))
Definition visual.c:1259
API int API void API void nctab_move_left(struct nctabbed *nt, struct nctab *t) __attribute__((nonnull(1
API ALLOC struct ncplane API ALLOC struct ncplane * ncpile_create(struct notcurses *nc, const ncplane_options *nopts) __attribute__((nonnull(1
API void API void notcurses_stats_reset(struct notcurses *nc, ncstats *stats) __attribute__((nonnull(1)))
Definition stats.c:100
API int notcurses_leave_alternate_screen(struct notcurses *nc) __attribute__((nonnull(1)))
Definition notcurses.c:42
API int ncplane_putchar_stained(struct ncplane *n, char c) __attribute__((nonnull(1)))
Definition notcurses.c:2008
API int ncpile_rasterize(struct ncplane *n) __attribute__((nonnull(1)))
Definition render.c:1517
API struct ncplane * nctabbed_content_plane(struct nctabbed *nt) __attribute__((nonnull(1)))
Definition tabbed.c:120
API int ncplane_at_cursor_cell(struct ncplane *n, nccell *c) __attribute__((nonnull(1
#define NCMICE_NO_EVENTS
Definition notcurses.h:1340
#define NCINPUT_MAX_EFF_TEXT_CODEPOINTS
Definition notcurses.h:1203
#define NC_BGDEFAULT_MASK
Definition notcurses.h:118
const struct ncplane_options * opts
Definition notcurses.h:3483
API int nctab_set_name(struct nctab *t, const char *newname) __attribute__((nonnull(1
API int ncplane_x(const struct ncplane *n) __attribute__((pure))
API struct ncplane * ncpile_top(struct ncplane *n) __attribute__((nonnull(1)))
Definition notcurses.c:2540
ncalign_e
Definition notcurses.h:80
@ NCALIGN_LEFT
Definition notcurses.h:82
@ NCALIGN_UNALIGNED
Definition notcurses.h:81
@ NCALIGN_CENTER
Definition notcurses.h:83
@ NCALIGN_RIGHT
Definition notcurses.h:84
#define NCALIGN_TOP
Definition notcurses.h:87
API ALLOC char * notcurses_hostname(void)
Definition util.c:62
API void ncreader_destroy(struct ncreader *n, char **contents)
Definition reader.c:17
API uint64_t ncplane_set_fchannel(struct ncplane *n, uint32_t channel) __attribute__((nonnull(1)))
Definition notcurses.c:1534
API int ncplane_set_fg_alpha(struct ncplane *n, int alpha)
Definition notcurses.c:1542
int(* tabletcb)(struct nctablet *t, bool drawfromtop)
Definition notcurses.h:3728
API struct nctab * nctab_next(struct nctab *t) __attribute__((nonnull(1)))
Definition tabbed.c:140
API ALLOC struct ncvisual * ncvisual_from_rgb_loose(const void *rgba, int rows, int rowstride, int cols, int alpha) __attribute__((nonnull(1)))
Definition visual.c:858
#define NC_NOBACKGROUND_MASK
Definition notcurses.h:116
API int ncreader_move_down(struct ncreader *n) __attribute__((nonnull(1)))
Definition reader.c:202
API uint16_t ncplane_styles(const struct ncplane *n) __attribute__((nonnull(1)))
API int API int API void notcurses_drop_planes(struct notcurses *nc) __attribute__((nonnull(1)))
Definition notcurses.c:1434
API ALLOC struct ncfadectx * ncfadectx_setup(struct ncplane *n) __attribute__((nonnull(1)))
Definition fade.c:249
API int ncplane_putegc_stained(struct ncplane *n, const char *gclust, size_t *sbytes) __attribute__((nonnull(1
API void notcurses_stats(struct notcurses *nc, ncstats *stats) __attribute__((nonnull(1
API char * notcurses_at_yx(struct notcurses *nc, unsigned yoff, unsigned xoff, uint16_t *stylemask, uint64_t *channels) __attribute__((nonnull(1)))
Definition render.c:1625
API void ncplane_yx(const struct ncplane *n, int *RESTRICT y, int *RESTRICT x) __attribute__((nonnull(1)))
API void nctabbed_set_hdrchan(struct nctabbed *nt, uint64_t chan) __attribute__((nonnull(1)))
Definition tabbed.c:436
API int ncplane_puttext(struct ncplane *n, int y, ncalign_e align, const char *text, size_t *bytes) __attribute__((nonnull(1
API struct nctab * nctabbed_selected(struct nctabbed *nt) __attribute__((nonnull(1)))
Definition tabbed.c:104
API void ncplane_set_bg_default(struct ncplane *n)
Definition notcurses.c:1506
API bool ncmultiselector_offer_input(struct ncmultiselector *n, const ncinput *nc) __attribute__((nonnull(1
API bool API void ncmultiselector_destroy(struct ncmultiselector *n)
Definition selector.c:985
API void ncpalette_free(ncpalette *p)
Definition notcurses.c:2586
API int ncplane_erase_region(struct ncplane *n, int ystart, int xstart, int ylen, int xlen) __attribute__((nonnull(1)))
Definition notcurses.c:2479
API void notcurses_debug(const struct notcurses *nc, FILE *debugfp) __attribute__((nonnull(1
API int ncplane_rotate_ccw(struct ncplane *n) __attribute__((nonnull(1)))
Definition fill.c:515
API int ncvisual_geom(const struct notcurses *nc, const struct ncvisual *n, const struct ncvisual_options *vopts, ncvgeom *geom) __attribute__((nonnull(4)))
API int ncvisual_decode_loop(struct ncvisual *nc) __attribute__((nonnull(1)))
Definition visual.c:46
API int ncvisual_resize_noninterpolative(struct ncvisual *n, int rows, int cols) __attribute__((nonnull(1)))
Definition visual.c:992
#define NC_BG_ALPHA_MASK
Definition notcurses.h:125
API int nctree_add(struct nctree *n, const unsigned *spec, const struct nctree_item *add) __attribute__((nonnull(1
API uint64_t ncplane_set_bchannel(struct ncplane *n, uint32_t channel) __attribute__((nonnull(1)))
Definition notcurses.c:1530
API int ncplane_scrollup(struct ncplane *n, int r) __attribute__((nonnull(1)))
Definition notcurses.c:1792
API int ncplane_resize_placewithin(struct ncplane *n)
Definition notcurses.c:2681
API ALLOC struct ncvisual * ncvisual_from_rgba(const void *rgba, int rows, int rowstride, int cols) __attribute__((nonnull(1)))
Definition visual.c:776
API struct nctab * nctabbed_next(struct nctabbed *nt) __attribute__((nonnull(1)))
Definition tabbed.c:368
API ALLOC struct ncsubproc * ncsubproc_createvp(struct ncplane *n, const ncsubproc_options *opts, const char *bin, const char *const arg[], ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn) __attribute__((nonnull(1)))
Definition fd.c:389
API struct nctab API void nctabbed_channels(struct nctabbed *nt, uint64_t *RESTRICT hdrchan, uint64_t *RESTRICT selchan, uint64_t *RESTRICT sepchan) __attribute__((nonnull(1)))
Definition tabbed.c:390
API struct ncplane API struct ncplane * ncplane_reparent_family(struct ncplane *n, struct ncplane *newparent) __attribute__((nonnull(1
API void ncplane_translate(const struct ncplane *src, const struct ncplane *dst, int *RESTRICT y, int *RESTRICT x) __attribute__((nonnull(1)))
API ALLOC struct ncdplot * ncdplot_create(struct ncplane *n, const ncplot_options *opts, double miny, double maxy) __attribute__((nonnull(1)))
Definition plot.c:690
API unsigned notcurses_palette_size(const struct notcurses *nc) __attribute__((nonnull(1))) __attribute__((pure))
API int ncplane_putegc_yx(struct ncplane *n, int y, int x, const char *gclust, size_t *sbytes) __attribute__((nonnull(1
API uint16_t notcurses_supported_styles(const struct notcurses *nc) __attribute__((nonnull(1))) __attribute__((pure))
API int ncplane_putnstr_aligned(struct ncplane *n, int y, ncalign_e align, size_t s, const char *str) __attribute__((nonnull(1
API int API int API int ncplane_gradient2x1(struct ncplane *n, int y, int x, unsigned ylen, unsigned xlen, uint32_t ul, uint32_t ur, uint32_t ll, uint32_t lr) __attribute__((nonnull(1)))
Definition fill.c:179
API int API int ncblit_rgba(const void *data, int linesize, const struct ncvisual_options *vopts) __attribute__((nonnull(1)))
Definition blit.c:1454
API const char * ncselector_previtem(struct ncselector *n) __attribute__((nonnull(1)))
Definition selector.c:481
API int nctree_redraw(struct nctree *n) __attribute__((nonnull(1)))
Definition tree.c:568
API void ncuplot_destroy(struct ncuplot *n)
Definition plot.c:681
API bool ncmenu_offer_input(struct ncmenu *n, const ncinput *nc) __attribute__((nonnull(1
API int ncblit_rgb_packed(const void *data, int linesize, const struct ncvisual_options *vopts, int alpha) __attribute__((nonnull(1)))
Definition blit.c:1440
API int ncmultiselector_selected(struct ncmultiselector *n, bool *selected, unsigned count)
Definition selector.c:1002
API int ncvisual_rotate(struct ncvisual *n, double rads) __attribute__((nonnull(1)))
Definition visual.c:704
API void nctabbed_ensure_selected_header_visible(struct nctabbed *nt) __attribute__((nonnull(1)))
Definition tabbed.c:69
API bool ncselector_offer_input(struct ncselector *n, const ncinput *nc) __attribute__((nonnull(1
API void * nctree_prev(struct nctree *n) __attribute__((nonnull(1)))
Definition tree.c:349
API const struct ncplane * ncplane_parent_const(const struct ncplane *n) __attribute__((nonnull(1)))
API void ncplane_set_fg_default(struct ncplane *n)
Definition notcurses.c:1502
ncintype_e
Definition notcurses.h:1194
@ NCTYPE_REPEAT
Definition notcurses.h:1197
@ NCTYPE_RELEASE
Definition notcurses.h:1198
@ NCTYPE_PRESS
Definition notcurses.h:1196
@ NCTYPE_UNKNOWN
Definition notcurses.h:1195
API int ncmenu_rollup(struct ncmenu *n) __attribute__((nonnull(1)))
Definition menu.c:554
API void nccell_release(struct ncplane *n, nccell *c)
Definition render.c:128
API void * nctab_userptr(struct nctab *t) __attribute__((nonnull(1)))
Definition tabbed.c:136
API ncpixelimpl_e notcurses_check_pixel_support(const struct notcurses *nc) __attribute__((nonnull(1))) __attribute__((pure))
API int ncvisual_stream(struct notcurses *nc, struct ncvisual *ncv, float timescale, ncstreamcb streamer, const struct ncvisual_options *vopts, void *curry) __attribute__((nonnull(1
API struct ncplane * ncuplot_plane(struct ncuplot *n) __attribute__((nonnull(1)))
Definition plot.c:662
API void * nctablet_userptr(struct nctablet *t)
Definition reel.c:893
API int(*)(struct ncplane *) ncplane_resizecb(const struct ncplane *n)
Definition notcurses.h:1513
API ALLOC struct notcurses * notcurses_core_init(const notcurses_options *opts, FILE *fp)
Definition notcurses.c:1242
API int notcurses_default_background(const struct notcurses *nc, uint32_t *bg) __attribute__((nonnull(1)))
Definition render.c:1722
API int ncplane_qrcode(struct ncplane *n, unsigned *ymax, unsigned *xmax, const void *data, size_t len) __attribute__((nonnull(1
API int ncreader_clear(struct ncreader *n) __attribute__((nonnull(1)))
Definition reader.c:73
API int ncplane_at_yx_cell(struct ncplane *n, int y, int x, nccell *c) __attribute__((nonnull(1
API struct ncplane * ncsubproc_plane(struct ncsubproc *n) __attribute__((nonnull(1)))
Definition fd.c:449
API int notcurses_lex_scalemode(const char *op, ncscale_e *scalemode) __attribute__((nonnull(1)))
Definition notcurses.c:3035
API const nccell * c
Definition notcurses.h:861
API int API char * ncplane_at_yx(const struct ncplane *n, int y, int x, uint16_t *stylemask, uint64_t *channels) __attribute__((nonnull(1)))
API int ncplane_putc_yx(struct ncplane *n, int y, int x, const nccell *c) __attribute__((nonnull(1
API struct nctablet * ncreel_prev(struct ncreel *nr) __attribute__((nonnull(1)))
Definition reel.c:915
ncblitter_e
Definition notcurses.h:65
@ NCBLIT_PIXEL
Definition notcurses.h:73
@ NCBLIT_4x2
Definition notcurses.h:71
@ NCBLIT_DEFAULT
Definition notcurses.h:66
@ NCBLIT_4x1
Definition notcurses.h:75
@ NCBLIT_2x2
Definition notcurses.h:69
@ NCBLIT_3x2
Definition notcurses.h:70
@ NCBLIT_1x1
Definition notcurses.h:67
@ NCBLIT_BRAILLE
Definition notcurses.h:72
@ NCBLIT_2x1
Definition notcurses.h:68
@ NCBLIT_8x1
Definition notcurses.h:76
API int ncreel_redraw(struct ncreel *nr) __attribute__((nonnull(1)))
Definition reel.c:677
API void ncplane_center_abs(const struct ncplane *n, int *RESTRICT y, int *RESTRICT x) __attribute__((nonnull(1)))
API int ncplane_scrollup_child(struct ncplane *n, const struct ncplane *child) __attribute__((nonnull(1
API void nctabbed_destroy(struct nctabbed *nt)
Definition tabbed.c:411
API bool API struct nctablet * ncreel_focused(struct ncreel *nr) __attribute__((nonnull(1)))
Definition reel.c:901
API int ncplane_vline_interp(struct ncplane *n, const nccell *c, unsigned len, uint64_t c1, uint64_t c2) __attribute__((nonnull(1
API int ncfadectx_iterations(const struct ncfadectx *nctx) __attribute__((nonnull(1)))
#define NCBPREFIXSTRLEN
Definition notcurses.h:3830
API int notcurses_mice_enable(struct notcurses *n, unsigned eventmask) __attribute__((nonnull(1)))
Definition notcurses.c:2556
API int ncmenu_unroll(struct ncmenu *n, int sectionidx)
Definition menu.c:452
API int API void API void API void nctabbed_rotate(struct nctabbed *nt, int amt) __attribute__((nonnull(1)))
Definition tabbed.c:356
API ALLOC struct nctab API int nctabbed_del(struct nctabbed *nt, struct nctab *t) __attribute__((nonnull(1)))
Definition tabbed.c:280
API struct ncplane * ncprogbar_plane(struct ncprogbar *n) __attribute__((nonnull(1)))
Definition progbar.c:32
API int API int ncpile_render_to_file(struct ncplane *p, FILE *fp) __attribute__((nonnull(1
API int API int notcurses_inputready_fd(struct notcurses *n) __attribute__((nonnull(1)))
Definition notcurses.c:3091
API int nctab_name_width(struct nctab *t) __attribute__((nonnull(1)))
Definition tabbed.c:132
API int ncprogbar_set_progress(struct ncprogbar *n, double p) __attribute__((nonnull(1)))
Definition progbar.c:176
API int ncreader_write_egc(struct ncreader *n, const char *egc) __attribute__((nonnull(1
API struct nctablet * ncreel_next(struct ncreel *nr) __attribute__((nonnull(1)))
Definition reel.c:905
vopts n
Definition notcurses.h:3502
API const char * notcurses_str_scalemode(ncscale_e scalemode)
Definition notcurses.c:3052
API ALLOC struct ncsubproc * ncsubproc_createvpe(struct ncplane *n, const ncsubproc_options *opts, const char *bin, const char *const arg[], const char *const env[], ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn) __attribute__((nonnull(1)))
Definition fd.c:395
API int API int nctree_del(struct nctree *n, const unsigned *spec) __attribute__((nonnull(1
API int ncplane_stain(struct ncplane *n, int y, int x, unsigned ylen, unsigned xlen, uint64_t ul, uint64_t ur, uint64_t ll, uint64_t lr) __attribute__((nonnull(1)))
Definition fill.c:272
API int nccell_load(struct ncplane *n, nccell *c, const char *gcluster)
Definition notcurses.c:1833
API struct ncplane * ncplane_parent(struct ncplane *n) __attribute__((nonnull(1)))
Definition notcurses.c:2651
API int notcurses_linesigs_enable(struct notcurses *n) __attribute__((nonnull(1)))
Definition in.c:2892
API int ncplane_move_family_below(struct ncplane *n, struct ncplane *targ) __attribute__((nonnull(1)))
API int ncmenu_nextitem(struct ncmenu *n) __attribute__((nonnull(1)))
Definition menu.c:593
API int ncvisual_decode(struct ncvisual *nc) __attribute__((nonnull(1)))
Definition visual.c:39
API ALLOC struct nctree * nctree_create(struct ncplane *n, const nctree_options *opts) __attribute__((nonnull(1
API struct nctab * nctab_prev(struct nctab *t) __attribute__((nonnull(1)))
Definition tabbed.c:144
API int ncuplot_add_sample(struct ncuplot *n, uint64_t x, uint64_t y) __attribute__((nonnull(1)))
Definition plot.c:666
#define NCPREFIXSTRLEN
Definition notcurses.h:3828
API int ncreel_del(struct ncreel *nr, struct nctablet *t) __attribute__((nonnull(1)))
Definition reel.c:285
API int API int API int ncplane_pulse(struct ncplane *n, const struct timespec *ts, fadecb fader, void *curry) __attribute__((nonnull(1)))
Definition fade.c:301
API struct ncplane * ncpile_bottom(struct ncplane *n) __attribute__((nonnull(1)))
Definition notcurses.c:2544
ALLOC API char * notcurses_detected_terminal(const struct notcurses *nc) __attribute__((nonnull(1)))
API int ncvisual_at_yx(const struct ncvisual *n, unsigned y, unsigned x, uint32_t *pixel) __attribute__((nonnull(1
API void ncreel_destroy(struct ncreel *nr)
Definition reel.c:880
API struct ncplane * ncdplot_plane(struct ncdplot *n) __attribute__((nonnull(1)))
Definition plot.c:705
API ALLOC struct ncmultiselector * ncmultiselector_create(struct ncplane *n, const ncmultiselector_options *opts) __attribute__((nonnull(1)))
Definition selector.c:885
API bool API void * nctree_focused(struct nctree *n) __attribute__((nonnull(1)))
Definition tree.c:606
API void ncplane_set_channels(struct ncplane *n, uint64_t channels) __attribute__((nonnull(1)))
Definition notcurses.c:1494
API int ncselector_delitem(struct ncselector *n, const char *item)
Definition selector.c:427
API void ncplane_set_resizecb(struct ncplane *n, int(*resizecb)(struct ncplane *))
API int ncplane_set_fg_rgb8(struct ncplane *n, unsigned r, unsigned g, unsigned b)
Definition notcurses.c:1522
API bool ncplane_set_scrolling(struct ncplane *n, unsigned scrollp) __attribute__((nonnull(1)))
Definition notcurses.c:2993
API struct ncplane * ncplane_below(struct ncplane *n) __attribute__((nonnull(1)))
Definition notcurses.c:2548
API struct ncplane * ncplane_above(struct ncplane *n) __attribute__((nonnull(1)))
Definition notcurses.c:2552
API int ncplane_vprintf_stained(struct ncplane *n, const char *format, va_list ap) __attribute__((nonnull(1
API ALLOC struct nctree API struct ncplane * nctree_plane(struct nctree *n) __attribute__((nonnull(1)))
Definition tree.c:303
#define RESTRICT
Definition notcurses.h:24
API ALLOC struct ncuplot * ncuplot_create(struct ncplane *n, const ncplot_options *opts, uint64_t miny, uint64_t maxy) __attribute__((nonnull(1)))
Definition plot.c:647
API ALLOC struct ncvisual API ALLOC struct ncvisual * ncvisual_from_plane(const struct ncplane *n, ncblitter_e blit, int begy, int begx, unsigned leny, unsigned lenx) __attribute__((nonnull(1)))
API int ncpalette_use(struct notcurses *nc, const ncpalette *p) __attribute__((nonnull(1
API int ncdplot_sample(const struct ncdplot *n, uint64_t x, double *y) __attribute__((nonnull(1)))
#define NCPALETTESIZE
Definition notcurses.h:111
API const char * notcurses_str_blitter(ncblitter_e blitter)
Definition blit.c:1394
API bool API void ncselector_destroy(struct ncselector *n, char **item)
Definition selector.c:270
API ALLOC ncstats * notcurses_stats_alloc(const struct notcurses *nc __attribute__((unused))) __attribute__((nonnull(1)))
API int ncdplot_add_sample(struct ncdplot *n, uint64_t x, double y) __attribute__((nonnull(1)))
Definition plot.c:709
API void ncplane_set_bg_rgb8_clipped(struct ncplane *n, int r, int g, int b)
Definition notcurses.c:1510
API struct ncplane * nctablet_plane(struct nctablet *t)
Definition reel.c:799
API void ncplane_home(struct ncplane *n) __attribute__((nonnull(1)))
Definition notcurses.c:715
API tabcb nctab_set_cb(struct nctab *t, tabcb newcb) __attribute__((nonnull(1)))
Definition tabbed.c:448
API int ncplane_set_base_cell(struct ncplane *n, const nccell *c)
Definition notcurses.c:1558
API ALLOC struct ncreel * ncreel_create(struct ncplane *n, const ncreel_options *popts) __attribute__((nonnull(1)))
Definition reel.c:807
API void ncfadectx_free(struct ncfadectx *nctx)
Definition fade.c:253
API ALLOC struct ncplane API ncblitter_e ncvisual_media_defblitter(const struct notcurses *nc, ncscale_e scale) __attribute__((nonnull(1)))
API ALLOC struct ncplane API ALLOC struct ncplane API int ncplane_resize_maximize(struct ncplane *n)
Definition notcurses.c:2753
#define NCALIGN_BOTTOM
Definition notcurses.h:88
API void ncplane_pixel_geom(const struct ncplane *n, unsigned *RESTRICT pxy, unsigned *RESTRICT pxx, unsigned *RESTRICT celldimy, unsigned *RESTRICT celldimx, unsigned *RESTRICT maxbmapy, unsigned *RESTRICT maxbmapx) __attribute__((nonnull(1)))
API void ncplane_cursor_yx(const struct ncplane *n, unsigned *RESTRICT y, unsigned *RESTRICT x) __attribute__((nonnull(1)))
API bool ncplane_set_autogrow(struct ncplane *n, unsigned growp) __attribute__((nonnull(1)))
Definition notcurses.c:3003
API ALLOC struct ncvisual * ncvisual_from_bgra(const void *bgra, int rows, int rowstride, int cols) __attribute__((nonnull(1)))
Definition visual.c:891
int(* ncfdplane_done_cb)(struct ncfdplane *n, int fderrno, void *curry)
Definition notcurses.h:4547
API ALLOC char * notcurses_osversion(void)
Definition util.c:82
API int ncplane_cursor_move_rel(struct ncplane *n, int y, int x) __attribute__((nonnull(1)))
Definition notcurses.c:750
ncloglevel_e
Definition notcurses.h:968
@ NCLOGLEVEL_WARNING
Definition notcurses.h:973
@ NCLOGLEVEL_VERBOSE
Definition notcurses.h:975
@ NCLOGLEVEL_DEBUG
Definition notcurses.h:976
@ NCLOGLEVEL_INFO
Definition notcurses.h:974
@ NCLOGLEVEL_ERROR
Definition notcurses.h:972
@ NCLOGLEVEL_PANIC
Definition notcurses.h:970
@ NCLOGLEVEL_FATAL
Definition notcurses.h:971
@ NCLOGLEVEL_SILENT
Definition notcurses.h:969
@ NCLOGLEVEL_TRACE
Definition notcurses.h:977
API int ncplane_vprintf_aligned(struct ncplane *n, int y, ncalign_e align, const char *format, va_list ap) __attribute__((nonnull(1
API ALLOC struct ncvisual * ncvisual_from_file(const char *file) __attribute__((nonnull(1)))
Definition visual.c:53
API struct ncplane API struct ncplane API ALLOC struct ncplane * ncplane_dup(const struct ncplane *n, void *opaque) __attribute__((nonnull(1)))
API ALLOC ncpalette * ncpalette_new(struct notcurses *nc) __attribute__((nonnull(1)))
Definition notcurses.c:2563
int int x
Definition notcurses.h:1905
#define NCCELL_TRIVIAL_INITIALIZER
Definition notcurses.h:737
API int API int ncplane_rotate_cw(struct ncplane *n) __attribute__((nonnull(1)))
Definition fill.c:484
API int ncblit_rgb_loose(const void *data, int linesize, const struct ncvisual_options *vopts, int alpha) __attribute__((nonnull(1)))
Definition blit.c:1426
API ALLOC struct ncvisual * ncvisual_from_palidx(const void *data, int rows, int rowstride, int cols, int palsize, int pstride, const uint32_t *palette) __attribute__((nonnull(1
#define NCCELL_INITIALIZER(c, s, chan)
Definition notcurses.h:731
API ALLOC char * ncplane_name(const struct ncplane *n) __attribute__((nonnull(1)))
API void * ncplane_userptr(struct ncplane *n) __attribute__((nonnull(1)))
Definition notcurses.c:192
API void ncdplot_destroy(struct ncdplot *n)
Definition plot.c:732
API int notcurses_lex_blitter(const char *op, ncblitter_e *blitter) __attribute__((nonnull(1)))
Definition blit.c:1378
API int ncplane_abs_y(const struct ncplane *n) __attribute__((pure))
API ALLOC struct ncvisual * ncvisual_from_rgb_packed(const void *rgba, int rows, int rowstride, int cols, int alpha) __attribute__((nonnull(1)))
Definition visual.c:817
API int nccell_duplicate(struct ncplane *n, nccell *targ, const nccell *c)
Definition render.c:133
struct ncvisual_options v
Definition notcurses.h:3497
API void ncplane_greyscale(struct ncplane *n) __attribute__((nonnull(1)))
Definition fill.c:3
API int ncuplot_sample(const struct ncuplot *n, uint64_t x, uint64_t *y) __attribute__((nonnull(1)))
API int ncfdplane_destroy(struct ncfdplane *n)
Definition fd.c:136
API int ncplane_set_fg_rgb(struct ncplane *n, uint32_t channel)
ncpixelimpl_e
Definition notcurses.h:1672
@ NCPIXEL_KITTY_STATIC
Definition notcurses.h:1680
@ NCPIXEL_NONE
Definition notcurses.h:1673
@ NCPIXEL_ITERM2
Definition notcurses.h:1676
@ NCPIXEL_KITTY_SELFREF
Definition notcurses.h:1689
@ NCPIXEL_KITTY_ANIMATED
Definition notcurses.h:1685
@ NCPIXEL_SIXEL
Definition notcurses.h:1674
@ NCPIXEL_LINUXFB
Definition notcurses.h:1675
API const struct ncplane * notcurses_stdplane_const(const struct notcurses *nc) __attribute__((nonnull(1)))
API const char * ncnmetric(uintmax_t val, size_t s, uintmax_t decimal, char *buf, int omitdec, uintmax_t mult, int uprefix) __attribute__((nonnull(4)))
Definition metric.c:28
API bool notcurses_canopen_images(const struct notcurses *nc) __attribute__((pure))
API void ncplane_set_fg_rgb8_clipped(struct ncplane *n, int r, int g, int b)
Definition notcurses.c:1518
API int ncplane_resize_marginalized(struct ncplane *n)
Definition notcurses.c:2723
API int ncmenu_item_set_status(struct ncmenu *n, const char *section, const char *item, bool enabled)
Definition menu.c:784
API int nctab_move(struct nctabbed *nt, struct nctab *t, struct nctab *after, struct nctab *before) __attribute__((nonnull(1
API int API int ncplane_hline_interp(struct ncplane *n, const nccell *c, unsigned len, uint64_t c1, uint64_t c2) __attribute__((nonnull(1
API int API char * ncplane_contents(struct ncplane *n, int begy, int begx, unsigned leny, unsigned lenx) __attribute__((nonnull(1)))
Definition notcurses.c:3228
API int ncplane_putwstr_stained(struct ncplane *n, const wchar_t *gclustarr) __attribute__((nonnull(1
API int API void * nctab_set_userptr(struct nctab *t, void *newopaque) __attribute__((nonnull(1)))
Definition tabbed.c:471
API int nctabbed_separator_width(struct nctabbed *nt) __attribute__((nonnull(1)))
Definition tabbed.c:407
API const char * ncselector_nextitem(struct ncselector *n) __attribute__((nonnull(1)))
Definition selector.c:500
API int API char * ncreader_contents(const struct ncreader *n) __attribute__((nonnull(1)))
#define API
Definition notcurses.h:32
int(* ncfdplane_callback)(struct ncfdplane *n, const void *buf, size_t s, void *curry)
Definition notcurses.h:4546
API int ncsubproc_destroy(struct ncsubproc *n)
Definition fd.c:402
API int ncplane_set_name(struct ncplane *n, const char *name) __attribute__((nonnull(1)))
Definition notcurses.c:2659
API ALLOC struct ncplane * ncvisual_subtitle_plane(struct ncplane *parent, const struct ncvisual *ncv) __attribute__((nonnull(1
API void ncplane_on_styles(struct ncplane *n, unsigned stylebits) __attribute__((nonnull(1)))
Definition notcurses.c:2076
API void * nctree_goto(struct nctree *n, const unsigned *spec, int *failspec)
Definition tree.c:610
API int ncreel_tabletcount(const struct ncreel *nr) __attribute__((nonnull(1)))
API int notcurses_lex_margins(const char *op, notcurses_options *opts) __attribute__((nonnull(1)))
Definition notcurses.c:3067
int(* ncstreamcb)(struct ncvisual *, struct ncvisual_options *, const struct timespec *, void *)
Definition notcurses.h:3533
API int ncplane_move_below(struct ncplane *RESTRICT n, struct ncplane *RESTRICT below) __attribute__((nonnull(1)))
API int ncplane_move_family_above(struct ncplane *n, struct ncplane *targ) __attribute__((nonnull(1)))
API int ncdplot_set_sample(struct ncdplot *n, uint64_t x, double y) __attribute__((nonnull(1)))
Definition plot.c:713
API int ncplane_vprintf_yx(struct ncplane *n, int y, int x, const char *format, va_list ap) __attribute__((nonnull(1
API int ncpile_render_to_buffer(struct ncplane *p, char **buf, size_t *buflen) __attribute__((nonnull(1
API const struct notcurses * ncplane_notcurses_const(const struct ncplane *n) __attribute__((nonnull(1)))
API const char * ncmenu_mouse_selected(const struct ncmenu *n, const ncinput *click, ncinput *ni)
#define NCALPHA_HIGHCONTRAST
Definition notcurses.h:105
API int API int API void ncplane_erase(struct ncplane *n) __attribute__((nonnull(1)))
Definition notcurses.c:2458
API struct ncplane * ncreader_plane(struct ncreader *n) __attribute__((nonnull(1)))
Definition reader.c:80
API void notcurses_version_components(int *major, int *minor, int *patch, int *tweak)
Definition notcurses.c:24
API const char * notcurses_version(void)
Definition notcurses.c:182
API int ncplane_fadeout(struct ncplane *n, const struct timespec *ts, fadecb fader, void *curry) __attribute__((nonnull(1)))
Definition fade.c:260
API int ncplane_box(struct ncplane *n, const nccell *ul, const nccell *ur, const nccell *ll, const nccell *lr, const nccell *hline, const nccell *vline, unsigned ystop, unsigned xstop, unsigned ctlword)
Definition notcurses.c:2271
API int API int const nccell unsigned len
Definition notcurses.h:2588
API int ncplane_format(struct ncplane *n, int y, int x, unsigned ylen, unsigned xlen, uint16_t stylemask) __attribute__((nonnull(1)))
Definition fill.c:296
API ALLOC struct ncfdplane * ncfdplane_create(struct ncplane *n, const ncfdplane_options *opts, int fd, ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn) __attribute__((nonnull(1)))
Definition fd.c:120
API ALLOC uint32_t * ncplane_as_rgba(const struct ncplane *n, ncblitter_e blit, int begy, int begx, unsigned leny, unsigned lenx, unsigned *pxdimy, unsigned *pxdimx) __attribute__((nonnull(1)))
API ALLOC struct ncreader * ncreader_create(struct ncplane *n, const ncreader_options *opts) __attribute__((nonnull(1)))
Definition reader.c:26
API void nctabbed_set_selchan(struct nctabbed *nt, uint64_t chan) __attribute__((nonnull(1)))
Definition tabbed.c:440
API int ncplane_move_yx(struct ncplane *n, int y, int x)
Definition notcurses.c:2411
API double ncprogbar_progress(const struct ncprogbar *n) __attribute__((nonnull(1)))
API int ncplane_destroy(struct ncplane *n)
Definition notcurses.c:1018
API void * nctree_next(struct nctree *n) __attribute__((nonnull(1)))
Definition tree.c:396
API ALLOC struct nctab * nctabbed_add(struct nctabbed *nt, struct nctab *after, struct nctab *before, tabcb tcb, const char *name, void *opaque) __attribute__((nonnull(1
API bool ncreader_offer_input(struct ncreader *n, const ncinput *ni) __attribute__((nonnull(1
API int API int ncplane_gradient(struct ncplane *n, int y, int x, unsigned ylen, unsigned xlen, const char *egc, uint16_t styles, uint64_t ul, uint64_t ur, uint64_t ll, uint64_t lr) __attribute__((nonnull(1
API int ncplane_set_fg_palindex(struct ncplane *n, unsigned idx)
Definition notcurses.c:1550
API void * ncplane_set_userptr(struct ncplane *n, void *opaque) __attribute__((nonnull(1)))
Definition notcurses.c:186
API bool ncplane_autogrow_p(const struct ncplane *n) __attribute__((nonnull(1)))
API void ncplane_off_styles(struct ncplane *n, unsigned stylebits) __attribute__((nonnull(1)))
Definition notcurses.c:2081
API ALLOC struct ncsubproc * ncsubproc_createv(struct ncplane *n, const ncsubproc_options *opts, const char *bin, const char *const arg[], ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn) __attribute__((nonnull(1)))
Definition fd.c:383
API struct nctab * nctabbed_leftmost(struct nctabbed *nt) __attribute__((nonnull(1)))
Definition tabbed.c:108
API int nctabbed_set_separator(struct nctabbed *nt, const char *separator) __attribute__((nonnull(1
#define NC_BG_RGB_MASK
Definition notcurses.h:120
API int ncplane_set_bg_alpha(struct ncplane *n, int alpha)
Definition notcurses.c:1546
API int notcurses_linesigs_disable(struct notcurses *n) __attribute__((nonnull(1)))
Definition in.c:2850
API tabcb nctab_cb(struct nctab *t) __attribute__((nonnull(1)))
Definition tabbed.c:124
API int ncmenu_prevsection(struct ncmenu *n) __attribute__((nonnull(1)))
Definition menu.c:578
API const nccapabilities * notcurses_capabilities(const struct notcurses *n) __attribute__((nonnull(1)))
API int ncblit_bgrx(const void *data, int linesize, const struct ncvisual_options *vopts) __attribute__((nonnull(1)))
Definition blit.c:1408
API bool API void ncmenu_destroy(struct ncmenu *n)
Definition menu.c:825
API int ncplane_resize_realign(struct ncplane *n)
Definition notcurses.c:2764
API int ncuplot_set_sample(struct ncuplot *n, uint64_t x, uint64_t y) __attribute__((nonnull(1)))
Definition plot.c:670
API int ncselector_additem(struct ncselector *n, const struct ncselector_item *item)
Definition selector.c:392
API int ncplane_fadein(struct ncplane *n, const struct timespec *ts, fadecb fader, void *curry) __attribute__((nonnull(1)))
Definition fade.c:284
API int ncplane_abs_x(const struct ncplane *n) __attribute__((pure))
API int API int ncplane_fadein_iteration(struct ncplane *n, struct ncfadectx *nctx, int iter, fadecb fader, void *curry) __attribute__((nonnull(1
API bool nctree_offer_input(struct nctree *n, const ncinput *ni) __attribute__((nonnull(1
API ALLOC struct ncmenu * ncmenu_create(struct ncplane *n, const ncmenu_options *opts) __attribute__((nonnull(1)))
Definition menu.c:377
API int ncplane_y(const struct ncplane *n) __attribute__((pure))
unsigned colors
Definition notcurses.h:1637
bool can_change_colors
Definition notcurses.h:1640
uint8_t width
Definition notcurses.h:702
uint8_t gcluster_backstop
Definition notcurses.h:694
uint64_t channels
Definition notcurses.h:723
uint16_t stylemask
Definition notcurses.h:703
uint32_t gcluster
Definition notcurses.h:693
uint64_t channels
Definition internal.h:254
uint64_t * channels
Definition fade.c:13
void * curry
Definition internal.h:196
ncintype_e evtype
Definition notcurses.h:1218
uint32_t eff_text[NCINPUT_MAX_EFF_TEXT_CODEPOINTS]
Definition notcurses.h:1221
bool alt
Definition notcurses.h:1214
bool ctrl
Definition notcurses.h:1216
uint32_t id
Definition notcurses.h:1210
bool shift
Definition notcurses.h:1215
char utf8[5]
Definition notcurses.h:1212
unsigned modifiers
Definition notcurses.h:1219
ncinput shortcut
Definition notcurses.h:4117
const char * desc
Definition notcurses.h:4116
uint64_t sectionchannels
Definition notcurses.h:4134
uint64_t flags
Definition notcurses.h:4135
struct ncmenu_section * sections
Definition notcurses.h:4131
uint64_t headerchannels
Definition notcurses.h:4133
struct ncmenu_item * items
Definition notcurses.h:4123
ncinput shortcut
Definition notcurses.h:4124
const char * name
Definition notcurses.h:4121
Definition menu.c:25
const char * option
Definition notcurses.h:3968
const char * desc
Definition notcurses.h:3969
const struct ncmselector_item * items
Definition notcurses.h:3998
uint32_t chans[NCPALETTESIZE]
Definition notcurses.h:1585
unsigned margin_r
Definition notcurses.h:1473
const char * name
Definition notcurses.h:1470
int(* resizecb)(struct ncplane *)
Definition notcurses.h:1471
unsigned margin_b
Definition notcurses.h:1473
struct ncplane * below
Definition internal.h:94
unsigned lenx
Definition internal.h:86
struct ncplane * above
Definition internal.h:93
char * name
Definition internal.h:111
uint64_t channels
Definition internal.h:88
unsigned leny
Definition internal.h:86
uint16_t stylemask
Definition internal.h:114
int(* resizecb)(struct ncplane *)
Definition internal.h:109
uint16_t legendstyle
Definition notcurses.h:4493
const char * title
Definition notcurses.h:4502
uint64_t maxchannels
Definition notcurses.h:4490
uint64_t flags
Definition notcurses.h:4503
ncblitter_e gridtype
Definition notcurses.h:4496
uint64_t minchannels
Definition notcurses.h:4491
uint64_t tchannels
Definition notcurses.h:4621
uint32_t tattrword
Definition notcurses.h:4622
unsigned bordermask
Definition notcurses.h:3707
uint64_t borderchan
Definition notcurses.h:3708
uint64_t tabletchan
Definition notcurses.h:3710
uint64_t flags
Definition notcurses.h:3712
unsigned tabletmask
Definition notcurses.h:3709
uint64_t focusedchan
Definition notcurses.h:3711
const char * option
Definition notcurses.h:3908
const char * desc
Definition notcurses.h:3909
uint64_t footchannels
Definition notcurses.h:3926
uint64_t descchannels
Definition notcurses.h:3924
uint64_t titlechannels
Definition notcurses.h:3925
const char * title
Definition notcurses.h:3913
const char * secondary
Definition notcurses.h:3914
const struct ncselector_item * items
Definition notcurses.h:3916
const char * footer
Definition notcurses.h:3915
uint64_t failed_writeouts
Definition notcurses.h:1786
uint64_t raster_ns
Definition notcurses.h:1793
uint64_t cellemissions
Definition notcurses.h:1800
int64_t render_min_ns
Definition notcurses.h:1792
uint64_t failed_renders
Definition notcurses.h:1785
uint64_t refreshes
Definition notcurses.h:1807
uint64_t defaultelisions
Definition notcurses.h:1805
uint64_t appsync_updates
Definition notcurses.h:1811
uint64_t cell_geo_changes
Definition notcurses.h:1815
uint64_t cellelisions
Definition notcurses.h:1799
uint64_t bgemissions
Definition notcurses.h:1804
uint64_t fgemissions
Definition notcurses.h:1802
uint64_t hpa_gratuitous
Definition notcurses.h:1814
int64_t writeout_min_ns
Definition notcurses.h:1798
uint64_t defaultemissions
Definition notcurses.h:1806
uint64_t sprixelemissions
Definition notcurses.h:1808
uint64_t writeout_ns
Definition notcurses.h:1796
uint64_t sprixelelisions
Definition notcurses.h:1809
uint64_t render_ns
Definition notcurses.h:1790
uint64_t renders
Definition notcurses.h:1783
uint64_t input_errors
Definition notcurses.h:1812
uint64_t raster_bytes
Definition notcurses.h:1787
int64_t raster_min_ns
Definition notcurses.h:1795
uint64_t pixel_geo_changes
Definition notcurses.h:1816
int64_t raster_max_bytes
Definition notcurses.h:1788
uint64_t fgelisions
Definition notcurses.h:1801
int64_t render_max_ns
Definition notcurses.h:1791
uint64_t input_events
Definition notcurses.h:1813
uint64_t bgelisions
Definition notcurses.h:1803
uint64_t sprixelbytes
Definition notcurses.h:1810
unsigned planes
Definition notcurses.h:1820
int64_t writeout_max_ns
Definition notcurses.h:1797
uint64_t writeouts
Definition notcurses.h:1784
uint64_t fbbytes
Definition notcurses.h:1819
int64_t raster_max_ns
Definition notcurses.h:1794
int64_t raster_min_bytes
Definition notcurses.h:1789
uint64_t restart_period
Definition notcurses.h:4573
char * name
Definition internal.h:234
struct nctabbed * nt
Definition internal.h:232
const char * separator
Definition notcurses.h:4243
unsigned subcount
Definition notcurses.h:4044
void * curry
Definition notcurses.h:4042
struct nctree_item * subs
Definition notcurses.h:4043
int(* nctreecb)(struct ncplane *, void *, int)
Definition notcurses.h:4050
unsigned count
Definition notcurses.h:4049
uint64_t flags
Definition notcurses.h:4052
const struct nctree_item * items
Definition notcurses.h:4048
Definition tree.c:11
unsigned rpixx
Definition notcurses.h:3400
unsigned cdimx
Definition notcurses.h:3399
unsigned scaley
Definition notcurses.h:3402
unsigned lenx
Definition notcurses.h:3404
ncblitter_e blitter
Definition notcurses.h:3406
unsigned pixx
Definition notcurses.h:3398
unsigned pixy
Definition notcurses.h:3398
unsigned rpixy
Definition notcurses.h:3400
unsigned begy
Definition notcurses.h:3403
unsigned maxpixelx
Definition notcurses.h:3405
unsigned maxpixely
Definition notcurses.h:3405
unsigned rcellx
Definition notcurses.h:3401
unsigned begx
Definition notcurses.h:3403
unsigned leny
Definition notcurses.h:3404
unsigned rcelly
Definition notcurses.h:3401
unsigned cdimy
Definition notcurses.h:3399
unsigned scalex
Definition notcurses.h:3402
ncblitter_e blitter
Definition notcurses.h:3370
ncscale_e scaling
Definition notcurses.h:3354
struct ncplane * n
Definition notcurses.h:3350
uint32_t transcolor
Definition notcurses.h:3372
unsigned rowstride
uint32_t * data
const char * termtype
Definition notcurses.h:1047
ncloglevel_e loglevel
Definition notcurses.h:1050
return NULL
Definition termdesc.h:229