Notcurses 3.0.16
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 ncplane 'n'. None of its contents will be visible after the next
1869// call to notcurses_render(). It is an error to attempt to destroy the
1870// standard plane. It is a noop if 'n' is NULL.
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// Destroy ncplane 'n' and all its bound descendants. It is a noop if 'n'
1988// is NULL. It is an error to attempt to destroy the standard plane.
1989API int ncplane_family_destroy(struct ncplane *n);
1990
1991// Return the plane below this one, or NULL if this is at the bottom.
1992API struct ncplane* ncplane_below(struct ncplane* n)
1993 __attribute__ ((nonnull (1)));
1994
1995// Return the plane above this one, or NULL if this is at the top.
1996API struct ncplane* ncplane_above(struct ncplane* n)
1997 __attribute__ ((nonnull (1)));
1998
1999// Effect |r| scroll events on the plane |n|. Returns an error if |n| is not
2000// a scrolling plane, and otherwise returns the number of lines scrolled.
2001API int ncplane_scrollup(struct ncplane* n, int r)
2002 __attribute__ ((nonnull (1)));
2003
2004// Scroll |n| up until |child| is no longer hidden beneath it. Returns an
2005// error if |child| is not a child of |n|, or |n| is not scrolling, or |child|
2006// is fixed. Returns the number of scrolling events otherwise (might be 0).
2007// If the child plane is not fixed, it will likely scroll as well.
2008API int ncplane_scrollup_child(struct ncplane* n, const struct ncplane* child)
2009 __attribute__ ((nonnull (1, 2)));
2010
2011// Rotate the plane π/2 radians clockwise or counterclockwise. This cannot
2012// be performed on arbitrary planes, because glyphs cannot be arbitrarily
2013// rotated. The glyphs which can be rotated are limited: line-drawing
2014// characters, spaces, half blocks, and full blocks. The plane must have
2015// an even number of columns. Use the ncvisual rotation for a more
2016// flexible approach.
2017API int ncplane_rotate_cw(struct ncplane* n)
2018 __attribute__ ((nonnull (1)));
2019API int ncplane_rotate_ccw(struct ncplane* n)
2020 __attribute__ ((nonnull (1)));
2021
2022// Retrieve the current contents of the cell under the cursor. The EGC is
2023// returned, or NULL on error. This EGC must be free()d by the caller. The
2024// stylemask and channels are written to 'stylemask' and 'channels', respectively.
2025API char* ncplane_at_cursor(const struct ncplane* n, uint16_t* stylemask, uint64_t* channels)
2026 __attribute__ ((nonnull (1)));
2027
2028// Retrieve the current contents of the cell under the cursor into 'c'. This
2029// cell is invalidated if the associated plane is destroyed. Returns the number
2030// of bytes in the EGC, or -1 on error.
2032 __attribute__ ((nonnull (1, 2)));
2033
2034// Retrieve the current contents of the specified cell. The EGC is returned, or
2035// NULL on error. This EGC must be free()d by the caller. The stylemask and
2036// channels are written to 'stylemask' and 'channels', respectively. The return
2037// represents how the cell will be used during rendering, and thus integrates
2038// any base cell where appropriate. If called upon the secondary columns of a
2039// wide glyph, the EGC will be returned (i.e. this function does not distinguish
2040// between the primary and secondary columns of a wide glyph). If called on a
2041// sprixel plane, its control sequence is returned for all valid locations.
2042API char* ncplane_at_yx(const struct ncplane* n, int y, int x,
2043 uint16_t* stylemask, uint64_t* channels)
2044 __attribute__ ((nonnull (1)));
2045
2046// Retrieve the current contents of the specified cell into 'c'. This cell is
2047// invalidated if the associated plane is destroyed. Returns the number of
2048// bytes in the EGC, or -1 on error. Unlike ncplane_at_yx(), when called upon
2049// the secondary columns of a wide glyph, the return can be distinguished from
2050// the primary column (nccell_wide_right_p(c) will return true). It is an
2051// error to call this on a sprixel plane (unlike ncplane_at_yx()).
2052API int ncplane_at_yx_cell(struct ncplane* n, int y, int x, nccell* c)
2053 __attribute__ ((nonnull (1, 4)));
2054
2055// Create a flat string from the EGCs of the selected region of the ncplane
2056// 'n'. Start at the plane's 'begy'x'begx' coordinate (which must lie on the
2057// plane), continuing for 'leny'x'lenx' cells. Either or both of 'leny' and
2058// 'lenx' can be specified as 0 to go through the boundary of the plane.
2059// -1 can be specified for 'begx'/'begy' to use the current cursor location.
2060API char* ncplane_contents(struct ncplane* n, int begy, int begx,
2061 unsigned leny, unsigned lenx)
2062 __attribute__ ((nonnull (1)));
2063
2064// Manipulate the opaque user pointer associated with this plane.
2065// ncplane_set_userptr() returns the previous userptr after replacing
2066// it with 'opaque'. the others simply return the userptr.
2067API void* ncplane_set_userptr(struct ncplane* n, void* opaque)
2068 __attribute__ ((nonnull (1)));
2069API void* ncplane_userptr(struct ncplane* n)
2070 __attribute__ ((nonnull (1)));
2071
2072// Find the center coordinate of a plane, preferring the top/left in the
2073// case of an even number of rows/columns (in such a case, there will be one
2074// more cell to the bottom/right of the center than the top/left). The
2075// center is then modified relative to the plane's origin.
2076API void ncplane_center_abs(const struct ncplane* n, int* RESTRICT y,
2077 int* RESTRICT x)
2078 __attribute__ ((nonnull (1)));
2079
2080// Create an RGBA flat array from the selected region of the ncplane 'nc'.
2081// Start at the plane's 'begy'x'begx' coordinate (which must lie on the
2082// plane), continuing for 'leny'x'lenx' cells. Either or both of 'leny' and
2083// 'lenx' can be specified as 0 to go through the boundary of the plane.
2084// Only glyphs from the specified ncblitset may be present. If 'pxdimy' and/or
2085// 'pxdimx' are non-NULL, they will be filled in with the total pixel geometry.
2086API ALLOC uint32_t* ncplane_as_rgba(const struct ncplane* n, ncblitter_e blit,
2087 int begy, int begx,
2088 unsigned leny, unsigned lenx,
2089 unsigned* pxdimy, unsigned* pxdimx)
2090 __attribute__ ((nonnull (1)));
2091
2092// Return the offset into 'availu' at which 'u' ought be output given the
2093// requirements of 'align'. Return -INT_MAX on invalid 'align'. Undefined
2094// behavior on negative 'availu' or 'u'.
2095static inline int
2096notcurses_align(int availu, ncalign_e align, int u){
2097 if(align == NCALIGN_LEFT || align == NCALIGN_TOP){
2098 return 0;
2099 }
2100 if(align == NCALIGN_CENTER){
2101 return (availu - u) / 2;
2102 }
2103 if(align == NCALIGN_RIGHT || align == NCALIGN_BOTTOM){
2104 return availu - u;
2105 }
2106 return -INT_MAX; // invalid |align|
2107}
2108
2109// Return the column at which 'c' cols ought start in order to be aligned
2110// according to 'align' within ncplane 'n'. Return -INT_MAX on invalid
2111// 'align'. Undefined behavior on negative 'c'.
2112static inline int
2113ncplane_halign(const struct ncplane* n, ncalign_e align, int c){
2114 return notcurses_align((int)ncplane_dim_x(n), align, c);
2115}
2116
2117// Return the row at which 'r' rows ought start in order to be aligned
2118// according to 'align' within ncplane 'n'. Return -INT_MAX on invalid
2119// 'align'. Undefined behavior on negative 'r'.
2120static inline int
2121ncplane_valign(const struct ncplane* n, ncalign_e align, int r){
2122 return notcurses_align((int)ncplane_dim_y(n), align, r);
2123}
2124
2125// Move the cursor to the specified position (the cursor needn't be visible).
2126// Pass -1 as either coordinate to hold that axis constant. Returns -1 if the
2127// move would place the cursor outside the plane.
2128API int ncplane_cursor_move_yx(struct ncplane* n, int y, int x)
2129 __attribute__ ((nonnull (1)));
2130
2131// Move the cursor relative to the current cursor position (the cursor needn't
2132// be visible). Returns -1 on error, including target position exceeding the
2133// plane's dimensions.
2134API int ncplane_cursor_move_rel(struct ncplane* n, int y, int x)
2135 __attribute__ ((nonnull (1)));
2136
2137// Move the cursor to 0, 0. Can't fail.
2138API void ncplane_home(struct ncplane* n)
2139 __attribute__ ((nonnull (1)));
2140
2141// Get the current position of the cursor within n. y and/or x may be NULL.
2142API void ncplane_cursor_yx(const struct ncplane* n, unsigned* RESTRICT y, unsigned* RESTRICT x)
2143 __attribute__ ((nonnull (1)));
2144
2145static inline unsigned
2146ncplane_cursor_y(const struct ncplane* n){
2147 unsigned y;
2149 return y;
2150}
2151
2152static inline unsigned
2153ncplane_cursor_x(const struct ncplane* n){
2154 unsigned x;
2156 return x;
2157}
2158
2159// Get the current colors and alpha values for ncplane 'n'.
2160API uint64_t ncplane_channels(const struct ncplane* n)
2161 __attribute__ ((nonnull (1)));
2162
2163// Get the current styling for the ncplane 'n'.
2164API uint16_t ncplane_styles(const struct ncplane* n)
2165 __attribute__ ((nonnull (1)));
2166
2167// Replace the cell at the specified coordinates with the provided cell 'c',
2168// and advance the cursor by the width of the cell (but not past the end of the
2169// plane). On success, returns the number of columns the cursor was advanced.
2170// 'c' must already be associated with 'n'. On failure, -1 is returned.
2171API int ncplane_putc_yx(struct ncplane* n, int y, int x, const nccell* c)
2172 __attribute__ ((nonnull (1, 4)));
2173
2174// Call ncplane_putc_yx() for the current cursor location.
2175static inline int
2176ncplane_putc(struct ncplane* n, const nccell* c){
2177 return ncplane_putc_yx(n, -1, -1, c);
2178}
2179
2180// Replace the cell at the specified coordinates with the provided 7-bit char
2181// 'c'. Advance the cursor by 1. On success, returns the number of columns the
2182// cursor was advanced. On failure, returns -1. This works whether the
2183// underlying char is signed or unsigned.
2184static inline int
2185ncplane_putchar_yx(struct ncplane* n, int y, int x, char c){
2187 return ncplane_putc_yx(n, y, x, &ce);
2188}
2189
2190// Call ncplane_putchar_yx() at the current cursor location.
2191static inline int
2192ncplane_putchar(struct ncplane* n, char c){
2193 return ncplane_putchar_yx(n, -1, -1, c);
2194}
2195
2196// Replace the EGC underneath us, but retain the styling. The current styling
2197// of the plane will not be changed.
2198API int ncplane_putchar_stained(struct ncplane* n, char c)
2199 __attribute__ ((nonnull (1)));
2200
2201// Replace the cell at the specified coordinates with the provided EGC, and
2202// advance the cursor by the width of the cluster (but not past the end of the
2203// plane). On success, returns the number of columns the cursor was advanced.
2204// On failure, -1 is returned. The number of bytes converted from gclust is
2205// written to 'sbytes' if non-NULL.
2206API int ncplane_putegc_yx(struct ncplane* n, int y, int x, const char* gclust,
2207 size_t* sbytes)
2208 __attribute__ ((nonnull (1, 4)));
2209
2210// Call ncplane_putegc_yx() at the current cursor location.
2211static inline int
2212ncplane_putegc(struct ncplane* n, const char* gclust, size_t* sbytes){
2213 return ncplane_putegc_yx(n, -1, -1, gclust, sbytes);
2214}
2215
2216// Replace the EGC underneath us, but retain the styling. The current styling
2217// of the plane will not be changed.
2218API int ncplane_putegc_stained(struct ncplane* n, const char* gclust, size_t* sbytes)
2219 __attribute__ ((nonnull (1, 2)));
2220
2221// generate a heap-allocated UTF-8 encoding of the wide string 'src'.
2222ALLOC static inline char*
2223ncwcsrtombs(const wchar_t* src){
2224 mbstate_t ps;
2225 memset(&ps, 0, sizeof(ps));
2226 size_t mbytes = wcsrtombs(NULL, &src, 0, &ps);
2227 if(mbytes == (size_t)-1){
2228 return NULL;
2229 }
2230 ++mbytes;
2231 char* mbstr = (char*)malloc(mbytes); // need cast for c++ callers
2232 if(mbstr == NULL){
2233 return NULL;
2234 }
2235 size_t s = wcsrtombs(mbstr, &src, mbytes, &ps);
2236 if(s == (size_t)-1){
2237 free(mbstr);
2238 return NULL;
2239 }
2240 return mbstr;
2241}
2242
2243// ncplane_putegc(), but following a conversion from wchar_t to UTF-8 multibyte.
2244static inline int
2245ncplane_putwegc(struct ncplane* n, const wchar_t* gclust, size_t* sbytes){
2246 char* mbstr = ncwcsrtombs(gclust);
2247 if(mbstr == NULL){
2248 return -1;
2249 }
2250 int ret = ncplane_putegc(n, mbstr, sbytes);
2251 free(mbstr);
2252 return ret;
2253}
2254
2255// Call ncplane_putwegc() after successfully moving to y, x.
2256static inline int
2257ncplane_putwegc_yx(struct ncplane* n, int y, int x, const wchar_t* gclust,
2258 size_t* sbytes){
2259 if(ncplane_cursor_move_yx(n, y, x)){
2260 return -1;
2261 }
2262 return ncplane_putwegc(n, gclust, sbytes);
2263}
2264
2265// Replace the EGC underneath us, but retain the styling. The current styling
2266// of the plane will not be changed.
2267API int ncplane_putwegc_stained(struct ncplane* n, const wchar_t* gclust, size_t* sbytes)
2268 __attribute__ ((nonnull (1, 2)));
2269
2270// Write a series of EGCs to the current location, using the current style.
2271// They will be interpreted as a series of columns (according to the definition
2272// of ncplane_putc()). Advances the cursor by some positive number of columns
2273// (though not beyond the end of the plane); this number is returned on success.
2274// On error, a non-positive number is returned, indicating the number of columns
2275// which were written before the error.
2276static inline int
2277ncplane_putstr_yx(struct ncplane* n, int y, int x, const char* gclusters){
2278 int ret = 0;
2279 while(*gclusters){
2280 size_t wcs;
2281 int cols = ncplane_putegc_yx(n, y, x, gclusters, &wcs);
2282//fprintf(stderr, "wrote %.*s %d cols %zu bytes\n", (int)wcs, gclusters, cols, wcs);
2283 if(cols < 0){
2284 return -ret;
2285 }
2286 if(wcs == 0){
2287 break;
2288 }
2289 // after the first iteration, just let the cursor code control where we
2290 // print, so that scrolling is taken into account
2291 y = -1;
2292 x = -1;
2293 gclusters += wcs;
2294 ret += cols;
2295 }
2296 return ret;
2297}
2298
2299static inline int
2300ncplane_putstr(struct ncplane* n, const char* gclustarr){
2301 return ncplane_putstr_yx(n, -1, -1, gclustarr);
2302}
2303
2304static inline int
2305ncplane_putstr_aligned(struct ncplane* n, int y, ncalign_e align, const char* s){
2306 int validbytes, validwidth;
2307 // we'll want to do the partial write if there's an error somewhere within
2308 ncstrwidth(s, &validbytes, &validwidth);
2309 int xpos = ncplane_halign(n, align, validwidth);
2310 if(xpos < 0){
2311 xpos = 0;
2312 }
2313 return ncplane_putstr_yx(n, y, xpos, s);
2314}
2315
2316// Replace a string's worth of glyphs at the current cursor location, but
2317// retain the styling. The current styling of the plane will not be changed.
2318static inline int
2319ncplane_putstr_stained(struct ncplane* n, const char* gclusters){
2320 int ret = 0;
2321 while(*gclusters){
2322 size_t wcs;
2323 int cols = ncplane_putegc_stained(n, gclusters, &wcs);
2324 if(cols < 0){
2325 return -ret;
2326 }
2327 if(wcs == 0){
2328 break;
2329 }
2330 gclusters += wcs;
2331 ret += cols;
2332 }
2333 return ret;
2334}
2335
2336API int ncplane_putnstr_aligned(struct ncplane* n, int y, ncalign_e align, size_t s, const char* str)
2337 __attribute__ ((nonnull (1, 5)));
2338
2339// Write a series of EGCs to the current location, using the current style.
2340// They will be interpreted as a series of columns (according to the definition
2341// of ncplane_putc()). Advances the cursor by some positive number of columns
2342// (though not beyond the end of the plane); this number is returned on success.
2343// On error, a non-positive number is returned, indicating the number of columns
2344// which were written before the error. No more than 's' bytes will be written.
2345static inline int
2346ncplane_putnstr_yx(struct ncplane* n, int y, int x, size_t s, const char* gclusters){
2347 int ret = 0;
2348 size_t offset = 0;
2349//fprintf(stderr, "PUT %zu at %d/%d [%.*s]\n", s, y, x, (int)s, gclusters);
2350 while(offset < s && gclusters[offset]){
2351 size_t wcs;
2352 int cols = ncplane_putegc_yx(n, y, x, gclusters + offset, &wcs);
2353 if(cols < 0){
2354 return -ret;
2355 }
2356 if(wcs == 0){
2357 break;
2358 }
2359 // after the first iteration, just let the cursor code control where we
2360 // print, so that scrolling is taken into account
2361 y = -1;
2362 x = -1;
2363 offset += wcs;
2364 ret += cols;
2365 }
2366 return ret;
2367}
2368
2369static inline int
2370ncplane_putnstr(struct ncplane* n, size_t s, const char* gclustarr){
2371 return ncplane_putnstr_yx(n, -1, -1, s, gclustarr);
2372}
2373
2374// ncplane_putstr(), but following a conversion from wchar_t to UTF-8 multibyte.
2375// FIXME do this as a loop over ncplane_putegc_yx and save the big allocation+copy
2376static inline int
2377ncplane_putwstr_yx(struct ncplane* n, int y, int x, const wchar_t* gclustarr){
2378 // maximum of six UTF8-encoded bytes per wchar_t
2379 const size_t mbytes = (wcslen(gclustarr) * WCHAR_MAX_UTF8BYTES) + 1;
2380 char* mbstr = (char*)malloc(mbytes); // need cast for c++ callers
2381 if(mbstr == NULL){
2382 return -1;
2383 }
2384 mbstate_t ps;
2385 memset(&ps, 0, sizeof(ps));
2386 const wchar_t** gend = &gclustarr;
2387 size_t s = wcsrtombs(mbstr, gend, mbytes, &ps);
2388 if(s == (size_t)-1){
2389 free(mbstr);
2390 return -1;
2391 }
2392 int ret = ncplane_putstr_yx(n, y, x, mbstr);
2393 free(mbstr);
2394 return ret;
2395}
2396
2397static inline int
2398ncplane_putwstr_aligned(struct ncplane* n, int y, ncalign_e align,
2399 const wchar_t* gclustarr){
2400 int width = wcswidth(gclustarr, INT_MAX);
2401 int xpos = ncplane_halign(n, align, width);
2402 if(xpos < 0){
2403 xpos = 0;
2404 }
2405 return ncplane_putwstr_yx(n, y, xpos, gclustarr);
2406}
2407
2408API int ncplane_putwstr_stained(struct ncplane* n, const wchar_t* gclustarr)
2409 __attribute__ ((nonnull (1, 2)));
2410
2411static inline int
2412ncplane_putwstr(struct ncplane* n, const wchar_t* gclustarr){
2413 return ncplane_putwstr_yx(n, -1, -1, gclustarr);
2414}
2415
2416// Replace the cell at the specified coordinates with the provided UTF-32
2417// 'u'. Advance the cursor by the character's width as reported by wcwidth().
2418// On success, returns the number of columns written. On failure, returns -1.
2419static inline int
2420ncplane_pututf32_yx(struct ncplane* n, int y, int x, uint32_t u){
2421 if(u > WCHAR_MAX){
2422 return -1;
2423 }
2424 // we use MB_LEN_MAX (and potentially "waste" a few stack bytes to avoid
2425 // the greater sin of a VLA (and to be locale-independent).
2426 char utf8c[MB_LEN_MAX + 1];
2427 mbstate_t ps;
2428 memset(&ps, 0, sizeof(ps));
2429 // this isn't going to be valid for reconstructued surrogate pairs...
2430 // we need our own, or to use unistring or something.
2431 size_t s = wcrtomb(utf8c, (wchar_t)u, &ps);
2432 if(s == (size_t)-1){
2433 return -1;
2434 }
2435 utf8c[s] = '\0';
2436 return ncplane_putegc_yx(n, y, x, utf8c, NULL);
2437}
2438
2439static inline int
2440ncplane_putwc_yx(struct ncplane* n, int y, int x, wchar_t w){
2441 return ncplane_pututf32_yx(n, y, x, (uint32_t)w);
2442}
2443
2444// Write 'w' at the current cursor position, using the plane's current styling.
2445static inline int
2446ncplane_putwc(struct ncplane* n, wchar_t w){
2447 return ncplane_putwc_yx(n, -1, -1, w);
2448}
2449
2450// Write the first Unicode character from 'w' at the current cursor position,
2451// using the plane's current styling. In environments where wchar_t is only
2452// 16 bits (Windows, essentially), a single Unicode might require two wchar_t
2453// values forming a surrogate pair. On environments with 32-bit wchar_t, this
2454// should not happen. If w[0] is a surrogate, it is decoded together with
2455// w[1], and passed as a single reconstructed UTF-32 character to
2456// ncplane_pututf32(); 'wchars' will get a value of 2 in this case. 'wchars'
2457// otherwise gets a value of 1. A surrogate followed by an invalid pairing
2458// will set 'wchars' to 2, but return -1 immediately.
2459static inline int
2460ncplane_putwc_utf32(struct ncplane* n, const wchar_t* w, unsigned* wchars){
2461 uint32_t utf32;
2462 if(*w >= 0xd000 && *w <= 0xdbff){
2463 *wchars = 2;
2464 if(w[1] < 0xdc00 || w[1] > 0xdfff){
2465 return -1; // invalid surrogate pairing
2466 }
2467 utf32 = (w[0] & 0x3fflu) << 10lu;
2468 utf32 += (w[1] & 0x3fflu);
2469 }else{
2470 *wchars = 1;
2471 utf32 = (uint32_t)*w;
2472 }
2473 return ncplane_pututf32_yx(n, -1, -1, utf32);
2474}
2475
2476// Write 'w' at the current cursor position, using any preexisting styling
2477// at that cell.
2478static inline int
2479ncplane_putwc_stained(struct ncplane* n, wchar_t w){
2480 wchar_t warr[2] = { w, L'\0' };
2481 return ncplane_putwstr_stained(n, warr);
2482}
2483
2484// The ncplane equivalents of printf(3) and vprintf(3).
2486 const char* format, va_list ap)
2487 __attribute__ ((nonnull (1, 4)))
2488 __attribute__ ((format (printf, 4, 0)));
2489
2490API int ncplane_vprintf_yx(struct ncplane* n, int y, int x,
2491 const char* format, va_list ap)
2492 __attribute__ ((nonnull (1, 4)))
2493 __attribute__ ((format (printf, 4, 0)));
2494
2495static inline int
2496ncplane_vprintf(struct ncplane* n, const char* format, va_list ap){
2497 return ncplane_vprintf_yx(n, -1, -1, format, ap);
2498}
2499
2500API int ncplane_vprintf_stained(struct ncplane* n, const char* format, va_list ap)
2501 __attribute__ ((nonnull (1, 2)))
2502 __attribute__ ((format (printf, 2, 0)));
2503
2504static inline int
2505ncplane_printf(struct ncplane* n, const char* format, ...)
2506 __attribute__ ((nonnull (1, 2)))
2507 __attribute__ ((format (printf, 2, 3)));
2508
2509static inline int
2510ncplane_printf(struct ncplane* n, const char* format, ...){
2511 va_list va;
2512 va_start(va, format);
2513 int ret = ncplane_vprintf(n, format, va);
2514 va_end(va);
2515 return ret;
2516}
2517
2518static inline int
2519ncplane_printf_yx(struct ncplane* n, int y, int x, const char* format, ...)
2520 __attribute__ ((nonnull (1, 4))) __attribute__ ((format (printf, 4, 5)));
2521
2522static inline int
2523ncplane_printf_yx(struct ncplane* n, int y, int x, const char* format, ...){
2524 va_list va;
2525 va_start(va, format);
2526 int ret = ncplane_vprintf_yx(n, y, x, format, va);
2527 va_end(va);
2528 return ret;
2529}
2530
2531static inline int
2532ncplane_printf_aligned(struct ncplane* n, int y, ncalign_e align,
2533 const char* format, ...)
2534 __attribute__ ((nonnull (1, 4))) __attribute__ ((format (printf, 4, 5)));
2535
2536static inline int
2537ncplane_printf_aligned(struct ncplane* n, int y, ncalign_e align, const char* format, ...){
2538 va_list va;
2539 va_start(va, format);
2540 int ret = ncplane_vprintf_aligned(n, y, align, format, va);
2541 va_end(va);
2542 return ret;
2543}
2544
2545static inline int
2546ncplane_printf_stained(struct ncplane* n, const char* format, ...)
2547 __attribute__ ((nonnull (1, 2))) __attribute__ ((format (printf, 2, 3)));
2548
2549static inline int
2550ncplane_printf_stained(struct ncplane* n, const char* format, ...){
2551 va_list va;
2552 va_start(va, format);
2553 int ret = ncplane_vprintf_stained(n, format, va);
2554 va_end(va);
2555 return ret;
2556}
2557
2558// Write the specified text to the plane, breaking lines sensibly, beginning at
2559// the specified line. Returns the number of columns written. When breaking a
2560// line, the line will be cleared to the end of the plane (the last line will
2561// *not* be so cleared). The number of bytes written from the input is written
2562// to '*bytes' if it is not NULL. Cleared columns are included in the return
2563// value, but *not* included in the number of bytes written. Leaves the cursor
2564// at the end of output. A partial write will be accomplished as far as it can;
2565// determine whether the write completed by inspecting '*bytes'. Can output to
2566// multiple rows even in the absence of scrolling, but not more rows than are
2567// available. With scrolling enabled, arbitrary amounts of data can be emitted.
2568// All provided whitespace is preserved -- ncplane_puttext() followed by an
2569// appropriate ncplane_contents() will read back the original output.
2570//
2571// If 'y' is -1, the first row of output is taken relative to the current
2572// cursor: it will be left-, right-, or center-aligned in whatever remains
2573// of the row. On subsequent rows -- or if 'y' is not -1 -- the entire row can
2574// be used, and alignment works normally.
2575//
2576// A newline at any point will move the cursor to the next row.
2577API int ncplane_puttext(struct ncplane* n, int y, ncalign_e align,
2578 const char* text, size_t* bytes)
2579 __attribute__ ((nonnull (1, 4)));
2580
2581// Draw horizontal or vertical lines using the specified cell, starting at the
2582// current cursor position. The cursor will end at the cell following the last
2583// cell output (even, perhaps counter-intuitively, when drawing vertical
2584// lines), just as if ncplane_putc() was called at that spot. Return the
2585// number of cells drawn on success. On error, return the negative number of
2586// cells drawn. A length of 0 is an error, resulting in a return of -1.
2588 unsigned len, uint64_t c1, uint64_t c2)
2589 __attribute__ ((nonnull (1, 2)));
2590
2591__attribute__ ((nonnull (1, 2))) static inline int
2592ncplane_hline(struct ncplane* n, const nccell* c, unsigned len){
2594}
2595
2597 unsigned len, uint64_t c1, uint64_t c2)
2598 __attribute__ ((nonnull (1, 2)));
2599
2600__attribute__ ((nonnull (1, 2))) static inline int
2601ncplane_vline(struct ncplane* n, const nccell* c, unsigned len){
2603}
2604
2605#define NCBOXMASK_TOP 0x0001
2606#define NCBOXMASK_RIGHT 0x0002
2607#define NCBOXMASK_BOTTOM 0x0004
2608#define NCBOXMASK_LEFT 0x0008
2609#define NCBOXGRAD_TOP 0x0010
2610#define NCBOXGRAD_RIGHT 0x0020
2611#define NCBOXGRAD_BOTTOM 0x0040
2612#define NCBOXGRAD_LEFT 0x0080
2613#define NCBOXCORNER_MASK 0x0300
2614#define NCBOXCORNER_SHIFT 8u
2615
2616// Draw a box with its upper-left corner at the current cursor position, and its
2617// lower-right corner at 'ystop'x'xstop'. The 6 cells provided are used to draw the
2618// upper-left, ur, ll, and lr corners, then the horizontal and vertical lines.
2619// 'ctlword' is defined in the least significant byte, where bits [7, 4] are a
2620// gradient mask, and [3, 0] are a border mask:
2621// * 7, 3: top
2622// * 6, 2: right
2623// * 5, 1: bottom
2624// * 4, 0: left
2625// If the gradient bit is not set, the styling from the hl/vl cells is used for
2626// the horizontal and vertical lines, respectively. If the gradient bit is set,
2627// the color is linearly interpolated between the two relevant corner cells.
2628//
2629// By default, vertexes are drawn whether their connecting edges are drawn or
2630// not. The value of the bits corresponding to NCBOXCORNER_MASK control this,
2631// and are interpreted as the number of connecting edges necessary to draw a
2632// given corner. At 0 (the default), corners are always drawn. At 3, corners
2633// are never drawn (since at most 2 edges can touch a box's corner).
2634API int ncplane_box(struct ncplane* n, const nccell* ul, const nccell* ur,
2635 const nccell* ll, const nccell* lr, const nccell* hline,
2636 const nccell* vline, unsigned ystop, unsigned xstop,
2637 unsigned ctlword);
2638
2639// Draw a box with its upper-left corner at the current cursor position, having
2640// dimensions 'ylen'x'xlen'. See ncplane_box() for more information. The
2641// minimum box size is 2x2, and it cannot be drawn off-plane.
2642static inline int
2643ncplane_box_sized(struct ncplane* n, const nccell* ul, const nccell* ur,
2644 const nccell* ll, const nccell* lr, const nccell* hline,
2645 const nccell* vline, unsigned ystop, unsigned xstop,
2646 unsigned ctlword){
2647 unsigned y, x;
2648 ncplane_cursor_yx(n, &y, &x);
2649 return ncplane_box(n, ul, ur, ll, lr, hline, vline, y + ystop - 1,
2650 x + xstop - 1, ctlword);
2651}
2652
2653static inline int
2654ncplane_perimeter(struct ncplane* n, const nccell* ul, const nccell* ur,
2655 const nccell* ll, const nccell* lr, const nccell* hline,
2656 const nccell* vline, unsigned ctlword){
2657 if(ncplane_cursor_move_yx(n, 0, 0)){
2658 return -1;
2659 }
2660 unsigned dimy, dimx;
2661 ncplane_dim_yx(n, &dimy, &dimx);
2662 return ncplane_box_sized(n, ul, ur, ll, lr, hline, vline, dimy, dimx, ctlword);
2663}
2664
2665// Starting at the specified coordinate, if its glyph is different from that of
2666// 'c', 'c' is copied into it, and the original glyph is considered the fill
2667// target. We do the same to all cardinally-connected cells having this same
2668// fill target. Returns the number of cells polyfilled. An invalid initial y, x
2669// is an error. Returns the number of cells filled, or -1 on error. Does
2670// not update cursor position.
2671API int ncplane_polyfill_yx(struct ncplane* n, int y, int x, const nccell* c)
2672 __attribute__ ((nonnull (1, 4)));
2673
2674// Draw a gradient with its upper-left corner at the position specified by 'y'/'x',
2675// where -1 means the current cursor position in that dimension. The area is
2676// specified by 'ylen'/'xlen', where 0 means "everything remaining below or
2677// to the right, respectively." The glyph composed of 'egc' and 'styles' is
2678// used for all cells. The channels specified by 'ul', 'ur', 'll', and 'lr'
2679// are composed into foreground and background gradients. To do a vertical
2680// gradient, 'ul' ought equal 'ur' and 'll' ought equal 'lr'. To do a
2681// horizontal gradient, 'ul' ought equal 'll' and 'ur' ought equal 'ul'. To
2682// color everything the same, all four channels should be equivalent. The
2683// resulting alpha values are equal to incoming alpha values. Returns the
2684// number of cells filled on success, or -1 on failure.
2685// Palette-indexed color is not supported. Does not update cursor position.
2686//
2687// Preconditions for gradient operations (error otherwise):
2688//
2689// all: only RGB colors, unless all four channels match as default
2690// all: all alpha values must be the same
2691// 1x1: all four colors must be the same
2692// 1xN: both top and both bottom colors must be the same (vertical gradient)
2693// Nx1: both left and both right colors must be the same (horizontal gradient)
2694API int ncplane_gradient(struct ncplane* n, int y, int x, unsigned ylen,
2695 unsigned xlen, const char* egc, uint16_t styles,
2696 uint64_t ul, uint64_t ur, uint64_t ll, uint64_t lr)
2697 __attribute__ ((nonnull (1, 6)));
2698
2699// Do a high-resolution gradient using upper blocks and synced backgrounds.
2700// This doubles the number of vertical gradations, but restricts you to
2701// half blocks (appearing to be full blocks). Returns the number of cells
2702// filled on success, or -1 on error. Does not update cursor position.
2703API int ncplane_gradient2x1(struct ncplane* n, int y, int x, unsigned ylen,
2704 unsigned xlen, uint32_t ul, uint32_t ur,
2705 uint32_t ll, uint32_t lr)
2706 __attribute__ ((nonnull (1)));
2707
2708// Set the given style throughout the specified region, keeping content and
2709// channels unchanged. The upper left corner is at 'y', 'x', and -1 may be
2710// specified to indicate the cursor's position in that dimension. The area
2711// is specified by 'ylen', 'xlen', and 0 may be specified to indicate everything
2712// remaining to the right and below, respectively. It is an error for any
2713// coordinate to be outside the plane. Returns the number of cells set,
2714// or -1 on failure. Does not update the cursor position.
2715API int ncplane_format(struct ncplane* n, int y, int x, unsigned ylen,
2716 unsigned xlen, uint16_t stylemask)
2717 __attribute__ ((nonnull (1)));
2718
2719// Set the given channels throughout the specified region, keeping content and
2720// channels unchanged. The upper left corner is at 'y', 'x', and -1 may be
2721// specified to indicate the cursor's position in that dimension. The area
2722// is specified by 'ylen', 'xlen', and 0 may be specified to indicate everything
2723// remaining to the right and below, respectively. It is an error for any
2724// coordinate to be outside the plane. Returns the number of cells set,
2725// or -1 on failure. Does not update the cursor position.
2726API int ncplane_stain(struct ncplane* n, int y, int x, unsigned ylen,
2727 unsigned xlen, uint64_t ul, uint64_t ur,
2728 uint64_t ll, uint64_t lr)
2729 __attribute__ ((nonnull (1)));
2730
2731// Merge the entirety of 'src' down onto the ncplane 'dst'. If 'src' does not
2732// intersect with 'dst', 'dst' will not be changed, but it is not an error.
2734 struct ncplane* RESTRICT dst)
2735 __attribute__ ((nonnull (1, 2)));
2736
2737// Merge the ncplane 'src' down onto the ncplane 'dst'. This is most rigorously
2738// defined as "write to 'dst' the frame that would be rendered were the entire
2739// stack made up only of the specified subregion of 'src' and, below it, the
2740// subregion of 'dst' having the specified origin. Supply -1 to indicate the
2741// current cursor position in the relevant dimension. Merging is independent of
2742// the position of 'src' viz 'dst' on the z-axis. It is an error to define a
2743// subregion that is not entirely contained within 'src'. It is an error to
2744// define a target origin such that the projected subregion is not entirely
2745// contained within 'dst'. Behavior is undefined if 'src' and 'dst' are
2746// equivalent. 'dst' is modified, but 'src' remains unchanged. Neither 'src'
2747// nor 'dst' may have sprixels. Lengths of 0 mean "everything left".
2749 struct ncplane* RESTRICT dst,
2750 int begsrcy, int begsrcx,
2751 unsigned leny, unsigned lenx,
2752 int dsty, int dstx)
2753 __attribute__ ((nonnull (1, 2)));
2754
2755// Erase every cell in the ncplane (each cell is initialized to the null glyph
2756// and the default channels/styles). All cells associated with this ncplane are
2757// invalidated, and must not be used after the call, *excluding* the base cell.
2758// The cursor is homed. The plane's active attributes are unaffected.
2759API void ncplane_erase(struct ncplane* n)
2760 __attribute__ ((nonnull (1)));
2761
2762// Erase every cell in the region starting at {ystart, xstart} and having size
2763// {|ylen|x|xlen|} for non-zero lengths. If ystart and/or xstart are -1, the current
2764// cursor position along that axis is used; other negative values are an error. A
2765// negative ylen means to move up from the origin, and a negative xlen means to move
2766// left from the origin. A positive ylen moves down, and a positive xlen moves right.
2767// A value of 0 for the length erases everything along that dimension. It is an error
2768// if the starting coordinate is not in the plane, but the ending coordinate may be
2769// outside the plane.
2770//
2771// For example, on a plane of 20 rows and 10 columns, with the cursor at row 10 and
2772// column 5, the following would hold:
2773//
2774// (-1, -1, 0, 1): clears the column to the right of the cursor (column 6)
2775// (-1, -1, 0, -1): clears the column to the left of the cursor (column 4)
2776// (-1, -1, INT_MAX, 0): clears all rows with or below the cursor (rows 10--19)
2777// (-1, -1, -INT_MAX, 0): clears all rows with or above the cursor (rows 0--10)
2778// (-1, 4, 3, 3): clears from row 5, column 4 through row 7, column 6
2779// (-1, 4, -3, -3): clears from row 5, column 4 through row 3, column 2
2780// (4, -1, 0, 3): clears columns 5, 6, and 7
2781// (-1, -1, 0, 0): clears the plane *if the cursor is in a legal position*
2782// (0, 0, 0, 0): clears the plane in all cases
2783API int ncplane_erase_region(struct ncplane* n, int ystart, int xstart,
2784 int ylen, int xlen)
2785 __attribute__ ((nonnull (1)));
2786
2787// Extract 24 bits of foreground RGB from 'cl', shifted to LSBs.
2788static inline uint32_t
2789nccell_fg_rgb(const nccell* cl){
2790 return ncchannels_fg_rgb(cl->channels);
2791}
2792
2793// Extract 24 bits of background RGB from 'cl', shifted to LSBs.
2794static inline uint32_t
2795nccell_bg_rgb(const nccell* cl){
2796 return ncchannels_bg_rgb(cl->channels);
2797}
2798
2799// Extract 2 bits of foreground alpha from 'cl', shifted to LSBs.
2800static inline uint32_t
2801nccell_fg_alpha(const nccell* cl){
2802 return ncchannels_fg_alpha(cl->channels);
2803}
2804
2805// Extract 2 bits of background alpha from 'cl', shifted to LSBs.
2806static inline uint32_t
2807nccell_bg_alpha(const nccell* cl){
2808 return ncchannels_bg_alpha(cl->channels);
2809}
2810
2811// Extract 24 bits of foreground RGB from 'cl', split into components.
2812static inline uint32_t
2813nccell_fg_rgb8(const nccell* cl, unsigned* r, unsigned* g, unsigned* b){
2814 return ncchannels_fg_rgb8(cl->channels, r, g, b);
2815}
2816
2817// Extract 24 bits of background RGB from 'cl', split into components.
2818static inline uint32_t
2819nccell_bg_rgb8(const nccell* cl, unsigned* r, unsigned* g, unsigned* b){
2820 return ncchannels_bg_rgb8(cl->channels, r, g, b);
2821}
2822
2823// Set the r, g, and b cell for the foreground component of this 64-bit
2824// 'cl' variable, and mark it as not using the default color.
2825static inline int
2826nccell_set_fg_rgb8(nccell* cl, unsigned r, unsigned g, unsigned b){
2827 return ncchannels_set_fg_rgb8(&cl->channels, r, g, b);
2828}
2829
2830// Same, but clipped to [0..255].
2831static inline void
2832nccell_set_fg_rgb8_clipped(nccell* cl, int r, int g, int b){
2833 ncchannels_set_fg_rgb8_clipped(&cl->channels, r, g, b);
2834}
2835
2836// Same, but with an assembled 24-bit RGB value.
2837static inline int
2838nccell_set_fg_rgb(nccell* c, uint32_t channel){
2839 return ncchannels_set_fg_rgb(&c->channels, channel);
2840}
2841
2842// Set the cell's foreground palette index, set the foreground palette index
2843// bit, set it foreground-opaque, and clear the foreground default color bit.
2844static inline int
2845nccell_set_fg_palindex(nccell* cl, unsigned idx){
2846 return ncchannels_set_fg_palindex(&cl->channels, idx);
2847}
2848
2849static inline uint32_t
2850nccell_fg_palindex(const nccell* cl){
2851 return ncchannels_fg_palindex(cl->channels);
2852}
2853
2854// Set the r, g, and b cell for the background component of this 64-bit
2855// 'cl' variable, and mark it as not using the default color.
2856static inline int
2857nccell_set_bg_rgb8(nccell* cl, unsigned r, unsigned g, unsigned b){
2858 return ncchannels_set_bg_rgb8(&cl->channels, r, g, b);
2859}
2860
2861// Same, but clipped to [0..255].
2862static inline void
2863nccell_set_bg_rgb8_clipped(nccell* cl, int r, int g, int b){
2864 ncchannels_set_bg_rgb8_clipped(&cl->channels, r, g, b);
2865}
2866
2867// Same, but with an assembled 24-bit RGB value. A value over 0xffffff
2868// will be rejected, with a non-zero return value.
2869static inline int
2870nccell_set_bg_rgb(nccell* c, uint32_t channel){
2871 return ncchannels_set_bg_rgb(&c->channels, channel);
2872}
2873
2874// Set the cell's background palette index, set the background palette index
2875// bit, set it background-opaque, and clear the background default color bit.
2876static inline int
2877nccell_set_bg_palindex(nccell* cl, unsigned idx){
2878 return ncchannels_set_bg_palindex(&cl->channels, idx);
2879}
2880
2881static inline uint32_t
2882nccell_bg_palindex(const nccell* cl){
2883 return ncchannels_bg_palindex(cl->channels);
2884}
2885
2886// Is the foreground using the "default foreground color"?
2887static inline bool
2888nccell_fg_default_p(const nccell* cl){
2889 return ncchannels_fg_default_p(cl->channels);
2890}
2891
2892static inline bool
2893nccell_fg_palindex_p(const nccell* cl){
2894 return ncchannels_fg_palindex_p(cl->channels);
2895}
2896
2897// Is the background using the "default background color"? The "default
2898// background color" must generally be used to take advantage of
2899// terminal-effected transparency.
2900static inline bool
2901nccell_bg_default_p(const nccell* cl){
2902 return ncchannels_bg_default_p(cl->channels);
2903}
2904
2905static inline bool
2906nccell_bg_palindex_p(const nccell* cl){
2907 return ncchannels_bg_palindex_p(cl->channels);
2908}
2909
2910// Extract the background alpha and coloring bits from a 64-bit channel
2911// pair as a single 32-bit value.
2912static inline uint32_t
2913ncplane_bchannel(const struct ncplane* n){
2914 return ncchannels_bchannel(ncplane_channels(n));
2915}
2916
2917// Extract the foreground alpha and coloring bits from a 64-bit channel
2918// pair as a single 32-bit value.
2919static inline uint32_t
2920ncplane_fchannel(const struct ncplane* n){
2921 return ncchannels_fchannel(ncplane_channels(n));
2922}
2923
2924// Set the alpha and coloring bits of the plane's current channels from a
2925// 64-bit pair of channels.
2926API void ncplane_set_channels(struct ncplane* n, uint64_t channels)
2927 __attribute__ ((nonnull (1)));
2928
2929// Set the background alpha and coloring bits of the plane's current
2930// channels from a single 32-bit value.
2931API uint64_t ncplane_set_bchannel(struct ncplane* n, uint32_t channel)
2932 __attribute__ ((nonnull (1)));
2933
2934// Set the foreground alpha and coloring bits of the plane's current
2935// channels from a single 32-bit value.
2936API uint64_t ncplane_set_fchannel(struct ncplane* n, uint32_t channel)
2937 __attribute__ ((nonnull (1)));
2938
2939// Set the specified style bits for the ncplane 'n', whether they're actively
2940// supported or not.
2941API void ncplane_set_styles(struct ncplane* n, unsigned stylebits)
2942 __attribute__ ((nonnull (1)));
2943
2944// Add the specified styles to the ncplane's existing spec.
2945API void ncplane_on_styles(struct ncplane* n, unsigned stylebits)
2946 __attribute__ ((nonnull (1)));
2947
2948// Remove the specified styles from the ncplane's existing spec.
2949API void ncplane_off_styles(struct ncplane* n, unsigned stylebits)
2950 __attribute__ ((nonnull (1)));
2951
2952// Extract 24 bits of working foreground RGB from an ncplane, shifted to LSBs.
2953static inline uint32_t
2954ncplane_fg_rgb(const struct ncplane* n){
2955 return ncchannels_fg_rgb(ncplane_channels(n));
2956}
2957
2958// Extract 24 bits of working background RGB from an ncplane, shifted to LSBs.
2959static inline uint32_t
2960ncplane_bg_rgb(const struct ncplane* n){
2961 return ncchannels_bg_rgb(ncplane_channels(n));
2962}
2963
2964// Extract 2 bits of foreground alpha from 'struct ncplane', shifted to LSBs.
2965static inline uint32_t
2966ncplane_fg_alpha(const struct ncplane* n){
2967 return ncchannels_fg_alpha(ncplane_channels(n));
2968}
2969
2970// Is the plane's foreground using the "default foreground color"?
2971static inline bool
2972ncplane_fg_default_p(const struct ncplane* n){
2973 return ncchannels_fg_default_p(ncplane_channels(n));
2974}
2975
2976// Extract 2 bits of background alpha from 'struct ncplane', shifted to LSBs.
2977static inline uint32_t
2978ncplane_bg_alpha(const struct ncplane* n){
2979 return ncchannels_bg_alpha(ncplane_channels(n));
2980}
2981
2982// Is the plane's background using the "default background color"?
2983static inline bool
2984ncplane_bg_default_p(const struct ncplane* n){
2985 return ncchannels_bg_default_p(ncplane_channels(n));
2986}
2987
2988// Extract 24 bits of foreground RGB from 'n', split into components.
2989static inline uint32_t
2990ncplane_fg_rgb8(const struct ncplane* n, unsigned* r, unsigned* g, unsigned* b){
2991 return ncchannels_fg_rgb8(ncplane_channels(n), r, g, b);
2992}
2993
2994// Extract 24 bits of background RGB from 'n', split into components.
2995static inline uint32_t
2996ncplane_bg_rgb8(const struct ncplane* n, unsigned* r, unsigned* g, unsigned* b){
2997 return ncchannels_bg_rgb8(ncplane_channels(n), r, g, b);
2998}
2999
3000// Set the current fore/background color using RGB specifications. If the
3001// terminal does not support directly-specified 3x8b cells (24-bit "TrueColor",
3002// indicated by the "RGB" terminfo capability), the provided values will be
3003// interpreted in some lossy fashion. None of r, g, or b may exceed 255.
3004// "HP-like" terminals require setting foreground and background at the same
3005// time using "color pairs"; Notcurses will manage color pairs transparently.
3006API int ncplane_set_fg_rgb8(struct ncplane* n, unsigned r, unsigned g, unsigned b);
3007API int ncplane_set_bg_rgb8(struct ncplane* n, unsigned r, unsigned g, unsigned b);
3008
3009// Same, but clipped to [0..255].
3010API void ncplane_set_bg_rgb8_clipped(struct ncplane* n, int r, int g, int b);
3011API void ncplane_set_fg_rgb8_clipped(struct ncplane* n, int r, int g, int b);
3012
3013// Same, but with rgb assembled into a channel (i.e. lower 24 bits).
3014API int ncplane_set_fg_rgb(struct ncplane* n, uint32_t channel);
3015API int ncplane_set_bg_rgb(struct ncplane* n, uint32_t channel);
3016
3017// Use the default color for the foreground/background.
3018API void ncplane_set_fg_default(struct ncplane* n);
3019API void ncplane_set_bg_default(struct ncplane* n);
3020
3021// Set the ncplane's foreground palette index, set the foreground palette index
3022// bit, set it foreground-opaque, and clear the foreground default color bit.
3023API int ncplane_set_fg_palindex(struct ncplane* n, unsigned idx);
3024API int ncplane_set_bg_palindex(struct ncplane* n, unsigned idx);
3025
3026// Set the alpha parameters for ncplane 'n'.
3027API int ncplane_set_fg_alpha(struct ncplane* n, int alpha);
3028API int ncplane_set_bg_alpha(struct ncplane* n, int alpha);
3029
3030// Called for each fade iteration on 'ncp'. If anything but 0 is returned,
3031// the fading operation ceases immediately, and that value is propagated out.
3032// The recommended absolute display time target is passed in 'tspec'.
3033typedef int (*fadecb)(struct notcurses* nc, struct ncplane* n,
3034 const struct timespec*, void* curry);
3035
3036// Fade the ncplane out over the provided time, calling 'fader' at each
3037// iteration. Requires a terminal which supports truecolor, or at least palette
3038// modification (if the terminal uses a palette, our ability to fade planes is
3039// limited, and affected by the complexity of the rest of the screen).
3040API int ncplane_fadeout(struct ncplane* n, const struct timespec* ts,
3041 fadecb fader, void* curry)
3042 __attribute__ ((nonnull (1)));
3043
3044// Fade the ncplane in over the specified time. Load the ncplane with the
3045// target cells without rendering, then call this function. When it's done, the
3046// ncplane will have reached the target levels, starting from zeroes.
3047API int ncplane_fadein(struct ncplane* n, const struct timespec* ts,
3048 fadecb fader, void* curry)
3049 __attribute__ ((nonnull (1)));
3050
3051// Rather than the simple ncplane_fade{in/out}(), ncfadectx_setup() can be
3052// paired with a loop over ncplane_fade{in/out}_iteration() + ncfadectx_free().
3053API ALLOC struct ncfadectx* ncfadectx_setup(struct ncplane* n)
3054 __attribute__ ((nonnull (1)));
3055
3056// Return the number of iterations through which 'nctx' will fade.
3057API int ncfadectx_iterations(const struct ncfadectx* nctx)
3058 __attribute__ ((nonnull (1)));
3059
3060// Fade out through 'iter' iterations, where
3061// 'iter' < 'ncfadectx_iterations(nctx)'.
3063 int iter, fadecb fader, void* curry)
3064 __attribute__ ((nonnull (1, 2)));
3065
3066// Fade in through 'iter' iterations, where
3067// 'iter' < 'ncfadectx_iterations(nctx)'.
3069 int iter, fadecb fader, void* curry)
3070 __attribute__ ((nonnull (1, 2)));
3071
3072// Pulse the plane in and out until the callback returns non-zero, relying on
3073// the callback 'fader' to initiate rendering. 'ts' defines the half-period
3074// (i.e. the transition from black to full brightness, or back again). Proper
3075// use involves preparing (but not rendering) an ncplane, then calling
3076// ncplane_pulse(), which will fade in from black to the specified colors.
3077API int ncplane_pulse(struct ncplane* n, const struct timespec* ts, fadecb fader, void* curry)
3078 __attribute__ ((nonnull (1)));
3079
3080// Release the resources associated with 'nctx'.
3081API void ncfadectx_free(struct ncfadectx* nctx);
3082
3083// load up six cells with the EGCs necessary to draw a box. returns 0 on
3084// success, -1 on error. on error, any cells this function might
3085// have loaded before the error are nccell_release()d. There must be at least
3086// six EGCs in gcluster.
3087static inline int
3088nccells_load_box(struct ncplane* n, uint16_t styles, uint64_t channels,
3090 nccell* hl, nccell* vl, const char* gclusters){
3091 int ulen;
3092 if((ulen = nccell_prime(n, ul, gclusters, styles, channels)) > 0){
3093 if((ulen = nccell_prime(n, ur, gclusters += ulen, styles, channels)) > 0){
3094 if((ulen = nccell_prime(n, ll, gclusters += ulen, styles, channels)) > 0){
3095 if((ulen = nccell_prime(n, lr, gclusters += ulen, styles, channels)) > 0){
3096 if((ulen = nccell_prime(n, hl, gclusters += ulen, styles, channels)) > 0){
3097 if(nccell_prime(n, vl, gclusters + ulen, styles, channels) > 0){
3098 return 0;
3099 }
3100 nccell_release(n, hl);
3101 }
3103 }
3105 }
3107 }
3109 }
3110 return -1;
3111}
3112
3113static inline int
3114nccells_ascii_box(struct ncplane* n, uint16_t attr, uint64_t channels,
3115 nccell* ul, nccell* ur, nccell* ll, nccell* lr, nccell* hl, nccell* vl){
3116 return nccells_load_box(n, attr, channels, ul, ur, ll, lr, hl, vl, NCBOXASCII);
3117}
3118
3119static inline int
3120nccells_double_box(struct ncplane* n, uint16_t attr, uint64_t channels,
3121 nccell* ul, nccell* ur, nccell* ll, nccell* lr, nccell* hl, nccell* vl){
3122 if(notcurses_canutf8(ncplane_notcurses(n))){
3123 return nccells_load_box(n, attr, channels, ul, ur, ll, lr, hl, vl, NCBOXDOUBLE);
3124 }
3125 return nccells_ascii_box(n, attr, channels, ul, ur, ll, lr, hl, vl);
3126}
3127
3128static inline int
3129nccells_rounded_box(struct ncplane* n, uint16_t attr, uint64_t channels,
3130 nccell* ul, nccell* ur, nccell* ll, nccell* lr, nccell* hl, nccell* vl){
3131 if(notcurses_canutf8(ncplane_notcurses(n))){
3132 return nccells_load_box(n, attr, channels, ul, ur, ll, lr, hl, vl, NCBOXROUND);
3133 }
3134 return nccells_ascii_box(n, attr, channels, ul, ur, ll, lr, hl, vl);
3135}
3136
3137static inline int
3138nccells_light_box(struct ncplane* n, uint16_t attr, uint64_t channels,
3139 nccell* ul, nccell* ur, nccell* ll, nccell* lr, nccell* hl, nccell* vl){
3140 if(notcurses_canutf8(ncplane_notcurses(n))){
3141 return nccells_load_box(n, attr, channels, ul, ur, ll, lr, hl, vl, NCBOXLIGHT);
3142 }
3143 return nccells_ascii_box(n, attr, channels, ul, ur, ll, lr, hl, vl);
3144}
3145
3146static inline int
3147nccells_heavy_box(struct ncplane* n, uint16_t attr, uint64_t channels,
3148 nccell* ul, nccell* ur, nccell* ll, nccell* lr, nccell* hl, nccell* vl){
3149 if(notcurses_canutf8(ncplane_notcurses(n))){
3150 return nccells_load_box(n, attr, channels, ul, ur, ll, lr, hl, vl, NCBOXHEAVY);
3151 }
3152 return nccells_ascii_box(n, attr, channels, ul, ur, ll, lr, hl, vl);
3153}
3154
3155static inline int
3156ncplane_rounded_box(struct ncplane* n, uint16_t styles, uint64_t channels,
3157 unsigned ystop, unsigned xstop, unsigned ctlword){
3158 int ret = 0;
3162 if((ret = nccells_rounded_box(n, styles, channels, &ul, &ur, &ll, &lr, &hl, &vl)) == 0){
3163 ret = ncplane_box(n, &ul, &ur, &ll, &lr, &hl, &vl, ystop, xstop, ctlword);
3164 }
3167 nccell_release(n, &hl); nccell_release(n, &vl);
3168 return ret;
3169}
3170
3171static inline int
3172ncplane_perimeter_rounded(struct ncplane* n, uint16_t stylemask,
3173 uint64_t channels, unsigned ctlword){
3174 if(ncplane_cursor_move_yx(n, 0, 0)){
3175 return -1;
3176 }
3177 unsigned dimy, dimx;
3178 ncplane_dim_yx(n, &dimy, &dimx);
3185 if(nccells_rounded_box(n, stylemask, channels, &ul, &ur, &ll, &lr, &hl, &vl)){
3186 return -1;
3187 }
3188 int r = ncplane_box_sized(n, &ul, &ur, &ll, &lr, &hl, &vl, dimy, dimx, ctlword);
3191 nccell_release(n, &hl); nccell_release(n, &vl);
3192 return r;
3193}
3194
3195static inline int
3196ncplane_rounded_box_sized(struct ncplane* n, uint16_t styles, uint64_t channels,
3197 unsigned ylen, unsigned xlen, unsigned ctlword){
3198 unsigned y, x;
3199 ncplane_cursor_yx(n, &y, &x);
3200 return ncplane_rounded_box(n, styles, channels, y + ylen - 1,
3201 x + xlen - 1, ctlword);
3202}
3203
3204static inline int
3205ncplane_double_box(struct ncplane* n, uint16_t styles, uint64_t channels,
3206 unsigned ylen, unsigned xlen, unsigned ctlword){
3207 int ret = 0;
3211 if((ret = nccells_double_box(n, styles, channels, &ul, &ur, &ll, &lr, &hl, &vl)) == 0){
3212 ret = ncplane_box(n, &ul, &ur, &ll, &lr, &hl, &vl, ylen, xlen, ctlword);
3213 }
3216 nccell_release(n, &hl); nccell_release(n, &vl);
3217 return ret;
3218}
3219
3220static inline int
3221ncplane_ascii_box(struct ncplane* n, uint16_t styles, uint64_t channels,
3222 unsigned ylen, unsigned xlen, unsigned ctlword){
3223 int ret = 0;
3227 if((ret = nccells_ascii_box(n, styles, channels, &ul, &ur, &ll, &lr, &hl, &vl)) == 0){
3228 ret = ncplane_box(n, &ul, &ur, &ll, &lr, &hl, &vl, ylen, xlen, ctlword);
3229 }
3232 nccell_release(n, &hl); nccell_release(n, &vl);
3233 return ret;
3234}
3235
3236static inline int
3237ncplane_perimeter_double(struct ncplane* n, uint16_t stylemask,
3238 uint64_t channels, unsigned ctlword){
3239 if(ncplane_cursor_move_yx(n, 0, 0)){
3240 return -1;
3241 }
3242 unsigned dimy, dimx;
3243 ncplane_dim_yx(n, &dimy, &dimx);
3250 if(nccells_double_box(n, stylemask, channels, &ul, &ur, &ll, &lr, &hl, &vl)){
3251 return -1;
3252 }
3253 int r = ncplane_box_sized(n, &ul, &ur, &ll, &lr, &hl, &vl, dimy, dimx, ctlword);
3256 nccell_release(n, &hl); nccell_release(n, &vl);
3257 return r;
3258}
3259
3260static inline int
3261ncplane_double_box_sized(struct ncplane* n, uint16_t styles, uint64_t channels,
3262 unsigned ylen, unsigned xlen, unsigned ctlword){
3263 unsigned y, x;
3264 ncplane_cursor_yx(n, &y, &x);
3265 return ncplane_double_box(n, styles, channels, y + ylen - 1,
3266 x + xlen - 1, ctlword);
3267}
3268
3269// Open a visual at 'file', extract a codec and parameters, decode the first
3270// image to memory.
3271API ALLOC struct ncvisual* ncvisual_from_file(const char* file)
3272 __attribute__ ((nonnull (1)));
3273
3274// Prepare an ncvisual, and its underlying plane, based off RGBA content in
3275// memory at 'rgba'. 'rgba' is laid out as 'rows' lines, each of which is
3276// 'rowstride' bytes in length. Each line has 'cols' 32-bit 8bpc RGBA pixels
3277// followed by possible padding (there will be 'rowstride' - 'cols' * 4 bytes
3278// of padding). The total size of 'rgba' is thus ('rows' * 'rowstride') bytes,
3279// of which ('rows' * 'cols' * 4) bytes are actual non-padding data. It is an
3280// error if any argument is not positive, if 'rowstride' is not a multiple of
3281// 4, or if 'rowstride' is less than 'cols' * 4.
3282API ALLOC struct ncvisual* ncvisual_from_rgba(const void* rgba, int rows,
3283 int rowstride, int cols)
3284 __attribute__ ((nonnull (1)));
3285
3286// ncvisual_from_rgba(), but the pixels are 3-byte RGB. A is filled in
3287// throughout using 'alpha'. It is an error if 'rows', 'rowstride', or 'cols'
3288// is not positive, if 'rowstride' is not a multiple of 3, or if 'rowstride'
3289// is less than 'cols' * 3.
3290API ALLOC struct ncvisual* ncvisual_from_rgb_packed(const void* rgba, int rows,
3291 int rowstride, int cols,
3292 int alpha)
3293 __attribute__ ((nonnull (1)));
3294
3295// ncvisual_from_rgba(), but the pixels are 4-byte RGBx. A is filled in
3296// throughout using 'alpha'. It is an error if 'rows', 'cols', or 'rowstride'
3297// are not positive, if 'rowstride' is not a multiple of 4, or if 'rowstride'
3298// is less than 'cols' * 4.
3299API ALLOC struct ncvisual* ncvisual_from_rgb_loose(const void* rgba, int rows,
3300 int rowstride, int cols,
3301 int alpha)
3302 __attribute__ ((nonnull (1)));
3303
3304// ncvisual_from_rgba(), but 'bgra' is arranged as BGRA. note that this is a
3305// byte-oriented layout, despite being bunched in 32-bit pixels; the lowest
3306// memory address ought be B, and A is reached by adding 3 to that address.
3307// It is an error if 'rows', 'cols', or 'rowstride' are not positive, if
3308// 'rowstride' is not a multiple of 4, or if 'rowstride' is less than 'cols' * 4.
3309API ALLOC struct ncvisual* ncvisual_from_bgra(const void* bgra, int rows,
3310 int rowstride, int cols)
3311 __attribute__ ((nonnull (1)));
3312
3313// ncvisual_from_rgba(), but 'data' is 'pstride'-byte palette-indexed pixels,
3314// arranged in 'rows' lines of 'rowstride' bytes each, composed of 'cols'
3315// pixels. 'palette' is an array of at least 'palsize' ncchannels.
3316// It is an error if 'rows', 'cols', 'rowstride', or 'pstride' are not
3317// positive, if 'rowstride' is not a multiple of 'pstride', or if 'rowstride'
3318// is less than 'cols' * 'pstride'.
3319API ALLOC struct ncvisual* ncvisual_from_palidx(const void* data, int rows,
3320 int rowstride, int cols,
3321 int palsize, int pstride,
3322 const uint32_t* palette)
3323 __attribute__ ((nonnull (1, 7)));
3324
3325// Promote an ncplane 'n' to an ncvisual. The plane may contain only spaces,
3326// half blocks, and full blocks. The latter will be checked, and any other
3327// glyph will result in a NULL being returned. This function exists so that
3328// planes can be subjected to ncvisual transformations. If possible, it's
3329// better to create the ncvisual from memory using ncvisual_from_rgba().
3330// Lengths of 0 are interpreted to mean "all available remaining area".
3332 ncblitter_e blit,
3333 int begy, int begx,
3334 unsigned leny, unsigned lenx)
3335 __attribute__ ((nonnull (1)));
3336
3337// Construct an ncvisual from a nul-terminated Sixel control sequence.
3338API ALLOC struct ncvisual* ncvisual_from_sixel(const char* s, unsigned leny, unsigned lenx)
3339 __attribute__ ((nonnull (1)));
3340
3341#define NCVISUAL_OPTION_NODEGRADE 0x0001ull // fail rather than degrade
3342#define NCVISUAL_OPTION_BLEND 0x0002ull // use NCALPHA_BLEND with visual
3343#define NCVISUAL_OPTION_HORALIGNED 0x0004ull // x is an alignment, not absolute
3344#define NCVISUAL_OPTION_VERALIGNED 0x0008ull // y is an alignment, not absolute
3345#define NCVISUAL_OPTION_ADDALPHA 0x0010ull // transcolor is in effect
3346#define NCVISUAL_OPTION_CHILDPLANE 0x0020ull // interpret n as parent
3347#define NCVISUAL_OPTION_NOINTERPOLATE 0x0040ull // non-interpolative scaling
3348
3350 // if no ncplane is provided, one will be created using the exact size
3351 // necessary to render the source with perfect fidelity (this might be
3352 // smaller or larger than the rendering area). if NCVISUAL_OPTION_CHILDPLANE
3353 // is provided, this must be non-NULL, and will be interpreted as the parent.
3354 struct ncplane* n;
3355 // the scaling is ignored if no ncplane is provided (it ought be NCSCALE_NONE
3356 // in this case). otherwise, the source is stretched/scaled relative to the
3357 // provided ncplane.
3359 // if an ncplane is provided, y and x specify where the visual will be
3360 // rendered on that plane. otherwise, they specify where the created ncplane
3361 // will be placed relative to the standard plane's origin. x is an ncalign_e
3362 // value if NCVISUAL_OPTION_HORALIGNED is provided. y is an ncalign_e if
3363 // NCVISUAL_OPTION_VERALIGNED is provided.
3364 int y, x;
3365 // the region of the visual that ought be rendered. for the entire visual,
3366 // pass an origin of 0, 0 and a size of 0, 0 (or the true height and width).
3367 // these numbers are all in terms of ncvisual pixels. negative values are
3368 // prohibited.
3369 unsigned begy, begx; // origin of rendered region in pixels
3370 unsigned leny, lenx; // size of rendered region in pixels
3371 // use NCBLIT_DEFAULT if you don't care, an appropriate blitter will be
3372 // chosen for your terminal, given your scaling. NCBLIT_PIXEL is never
3373 // chosen for NCBLIT_DEFAULT.
3374 ncblitter_e blitter; // glyph set to use (maps input to output cells)
3375 uint64_t flags; // bitmask over NCVISUAL_OPTION_*
3376 uint32_t transcolor; // treat this color as transparent under NCVISUAL_OPTION_ADDALPHA
3377 // pixel offsets within the cell. if NCBLIT_PIXEL is used, the bitmap will
3378 // be drawn offset from the upper-left cell's origin by these amounts. it is
3379 // an error if either number exceeds the cell-pixel geometry in its
3380 // dimension. if NCBLIT_PIXEL is not used, these fields are ignored.
3381 // this functionality can be used for smooth bitmap movement.
3382 unsigned pxoffy, pxoffx;
3383};
3384
3385// describes all geometries of an ncvisual: those which are inherent, and those
3386// dependent upon a given rendering regime. pixy and pixx are the true internal
3387// pixel geometry, taken directly from the load (and updated by
3388// ncvisual_resize()). cdimy/cdimx are the cell-pixel geometry *at the time
3389// of this call* (it can change with a font change, in which case all values
3390// other than pixy/pixx are invalidated). rpixy/rpixx are the pixel geometry as
3391// handed to the blitter, following any scaling. scaley/scalex are the number
3392// of input pixels drawn to a single cell; when using NCBLIT_PIXEL, they are
3393// equivalent to cdimy/cdimx. rcelly/rcellx are the cell geometry as written by
3394// the blitter, following any padding (there is padding whenever rpix{y, x} is
3395// not evenly divided by scale{y, x}, and also sometimes for Sixel).
3396// maxpixely/maxpixelx are defined only when NCBLIT_PIXEL is used, and specify
3397// the largest bitmap that the terminal is willing to accept. blitter is the
3398// blitter which will be used, a function of the requested blitter and the
3399// blitters actually supported by this environment. if no ncvisual was
3400// supplied, only cdimy/cdimx are filled in.
3401typedef struct ncvgeom {
3402 unsigned pixy, pixx; // true pixel geometry of ncvisual data
3403 unsigned cdimy, cdimx; // terminal cell geometry when this was calculated
3404 unsigned rpixy, rpixx; // rendered pixel geometry (per visual_options)
3405 unsigned rcelly, rcellx; // rendered cell geometry (per visual_options)
3406 unsigned scaley, scalex; // source pixels per filled cell
3407 unsigned begy, begx; // upper-left corner of used region
3408 unsigned leny, lenx; // geometry of used region
3409 unsigned maxpixely, maxpixelx; // only defined for NCBLIT_PIXEL
3410 ncblitter_e blitter; // blitter that will be used
3412
3413// all-purpose ncvisual geometry solver. one or both of 'nc' and 'n' must be
3414// non-NULL. if 'nc' is NULL, only pixy/pixx will be filled in, with the true
3415// pixel geometry of 'n'. if 'n' is NULL, only cdimy/cdimx, blitter,
3416// scaley/scalex, and maxpixely/maxpixelx are filled in. cdimy/cdimx and
3417// maxpixely/maxpixelx are only ever filled in if we know them.
3418API int ncvisual_geom(const struct notcurses* nc, const struct ncvisual* n,
3419 const struct ncvisual_options* vopts, ncvgeom* geom)
3420 __attribute__ ((nonnull (4)));
3421
3422// Destroy an ncvisual. Rendered elements will not be disrupted, but the visual
3423// can be neither decoded nor rendered any further.
3424API void ncvisual_destroy(struct ncvisual* ncv);
3425
3426// extract the next frame from an ncvisual. returns 1 on end of file, 0 on
3427// success, and -1 on failure.
3428API int ncvisual_decode(struct ncvisual* nc)
3429 __attribute__ ((nonnull (1)));
3430
3431// decode the next frame ala ncvisual_decode(), but if we have reached the end,
3432// rewind to the first frame of the ncvisual. a subsequent 'ncvisual_blit()'
3433// will render the first frame, as if the ncvisual had been closed and reopened.
3434// the return values remain the same as those of ncvisual_decode().
3435API int ncvisual_decode_loop(struct ncvisual* nc)
3436 __attribute__ ((nonnull (1)));
3437
3438// Rotate the visual 'rads' radians. Only M_PI/2 and -M_PI/2 are supported at
3439// the moment, but this might change in the future.
3440API int ncvisual_rotate(struct ncvisual* n, double rads)
3441 __attribute__ ((nonnull (1)));
3442
3443// Scale the visual to 'rows' X 'columns' pixels, using the best scheme
3444// available. This is a lossy transformation, unless the size is unchanged.
3445API int ncvisual_resize(struct ncvisual* n, int rows, int cols)
3446 __attribute__ ((nonnull (1)));
3447
3448// Scale the visual to 'rows' X 'columns' pixels, using non-interpolative
3449// (naive) scaling. No new colors will be introduced as a result.
3450API int ncvisual_resize_noninterpolative(struct ncvisual* n, int rows, int cols)
3451 __attribute__ ((nonnull (1)));
3452
3453// Polyfill at the specified location within the ncvisual 'n', using 'rgba'.
3454API int ncvisual_polyfill_yx(struct ncvisual* n, unsigned y, unsigned x, uint32_t rgba)
3455 __attribute__ ((nonnull (1)));
3456
3457// Get the specified pixel from the specified ncvisual.
3458API int ncvisual_at_yx(const struct ncvisual* n, unsigned y, unsigned x,
3459 uint32_t* pixel)
3460 __attribute__ ((nonnull (1, 4)));
3461
3462// Set the specified pixel in the specified ncvisual.
3463API int ncvisual_set_yx(const struct ncvisual* n, unsigned y, unsigned x,
3464 uint32_t pixel)
3465 __attribute__ ((nonnull (1)));
3466
3467// Render the decoded frame according to the provided options (which may be
3468// NULL). The plane used for rendering depends on vopts->n and vopts->flags.
3469// If NCVISUAL_OPTION_CHILDPLANE is set, vopts->n must not be NULL, and the
3470// plane will always be created as a child of vopts->n. If this flag is not
3471// set, and vopts->n is NULL, a new plane is created as root of a new pile.
3472// If the flag is not set and vopts->n is not NULL, we render to vopts->n.
3473// A subregion of the visual can be rendered using 'begx', 'begy', 'lenx', and
3474// 'leny'. Negative values for any of these are an error. It is an error to
3475// specify any region beyond the boundaries of the frame. Returns the (possibly
3476// newly-created) plane to which we drew. Pixels may not be blitted to the
3477// standard plane.
3478API struct ncplane* ncvisual_blit(struct notcurses* nc, struct ncvisual* ncv,
3479 const struct ncvisual_options* vopts)
3480 __attribute__ ((nonnull (2)));
3481
3482// Create a new plane as prescribed in opts, either as a child of 'vopts->n',
3483// or the root of a new pile if 'vopts->n' is NULL (or 'vopts' itself is NULL).
3484// Blit 'ncv' to the created plane according to 'vopts'. If 'vopts->n' is
3485// non-NULL, NCVISUAL_OPTION_CHILDPLANE must be supplied.
3486__attribute__ ((nonnull (1, 2, 3))) static inline struct ncplane*
3487ncvisualplane_create(struct notcurses* nc, const struct ncplane_options* opts,
3489 struct ncplane* newn;
3490 if(vopts && vopts->n){
3492 return NULL; // the whole point is to create a new plane
3493 }
3495 }else{
3496 newn = ncpile_create(nc, opts);
3497 }
3498 if(newn == NULL){
3499 return NULL;
3500 }
3502 if(!vopts){
3503 vopts = &v;
3504 memset(vopts, 0, sizeof(*vopts));
3505 }
3509 vopts->n = NULL;
3510 return NULL;
3511 }
3512 return newn;
3513}
3514
3515// If a subtitle ought be displayed at this time, return a new plane (bound
3516// to 'parent' containing the subtitle, which might be text or graphics
3517// (depending on the input format).
3519 const struct ncvisual* ncv)
3520 __attribute__ ((nonnull (1, 2)));
3521
3522// Get the default *media* (not plot) blitter for this environment when using
3523// the specified scaling method. Currently, this means:
3524// - if lacking UTF-8, NCBLIT_1x1
3525// - otherwise, if not NCSCALE_STRETCH, NCBLIT_2x1
3526// - otherwise, if octants are known to be good, NCBLIT_4x2
3527// - otherwise, if sextants are not known to be good, NCBLIT_2x2
3528// - otherwise NCBLIT_3x2
3529// NCBLIT_2x2 and NCBLIT_3x2 both distort the original aspect ratio, thus
3530// NCBLIT_2x1 is used outside of NCSCALE_STRETCH.
3532 __attribute__ ((nonnull (1)));
3533
3534// Called for each frame rendered from 'ncv'. If anything but 0 is returned,
3535// the streaming operation ceases immediately, and that value is propagated out.
3536// The recommended absolute display time target is passed in 'tspec'.
3537typedef int (*ncstreamcb)(struct ncvisual*, struct ncvisual_options*,
3538 const struct timespec*, void*);
3539
3540// Shut up and display my frames! Provide as an argument to ncvisual_stream().
3541// If you'd like subtitles to be decoded, provide an ncplane as the curry. If the
3542// curry is NULL, subtitles will not be displayed.
3544 const struct timespec* tspec, void* curry)
3545 __attribute__ ((nonnull (1)));
3546
3547// Stream the entirety of the media, according to its own timing. Blocking,
3548// obviously. streamer may be NULL; it is otherwise called for each frame, and
3549// its return value handled as outlined for streamcb. If streamer() returns
3550// non-zero, the stream is aborted, and that value is returned. By convention,
3551// return a positive number to indicate intentional abort from within
3552// streamer(). 'timescale' allows the frame duration time to be scaled. For a
3553// visual naturally running at 30FPS, a 'timescale' of 0.1 will result in
3554// 300FPS, and a 'timescale' of 10 will result in 3FPS. It is an error to
3555// supply 'timescale' less than or equal to 0.
3556API int ncvisual_stream(struct notcurses* nc, struct ncvisual* ncv,
3557 float timescale, ncstreamcb streamer,
3558 const struct ncvisual_options* vopts, void* curry)
3559 __attribute__ ((nonnull (1, 2)));
3560
3561// Blit a flat array 'data' of RGBA 32-bit values to the ncplane 'vopts->n',
3562// which mustn't be NULL. the blit begins at 'vopts->y' and 'vopts->x' relative
3563// to the specified plane. Each source row ought occupy 'linesize' bytes (this
3564// might be greater than 'vopts->lenx' * 4 due to padding or partial blits). A
3565// subregion of the input can be specified with the 'begy'x'begx' and
3566// 'leny'x'lenx' fields from 'vopts'. Returns the number of pixels blitted, or
3567// -1 on error.
3568API int ncblit_rgba(const void* data, int linesize,
3569 const struct ncvisual_options* vopts)
3570 __attribute__ ((nonnull (1)));
3571
3572// Same as ncblit_rgba(), but for BGRx.
3573API int ncblit_bgrx(const void* data, int linesize,
3574 const struct ncvisual_options* vopts)
3575 __attribute__ ((nonnull (1)));
3576
3577// Supply an alpha value [0..255] to be applied throughout.
3578API int ncblit_rgb_packed(const void* data, int linesize,
3579 const struct ncvisual_options* vopts, int alpha)
3580 __attribute__ ((nonnull (1)));
3581
3582// Supply an alpha value [0..255] to be applied throughout. linesize must be
3583// a multiple of 4 for this RGBx data.
3584API int ncblit_rgb_loose(const void* data, int linesize,
3585 const struct ncvisual_options* vopts, int alpha)
3586 __attribute__ ((nonnull (1)));
3587
3588// The ncpixel API facilitates direct management of the pixels within an
3589// ncvisual (ncvisuals keep a backing store of 32-bit RGBA pixels, and render
3590// them down to terminal graphics in ncvisual_blit()).
3591//
3592// Per libav, we "store as BGRA on little-endian, and ARGB on big-endian".
3593// This is an RGBA *byte-order* scheme. libav emits bytes, not words. Those
3594// bytes are R-G-B-A. When read as words, on little endian this will be ABGR,
3595// and on big-endian this will be RGBA. force everything to LE ABGR, a no-op
3596// on (and thus favoring) little-endian. Take that, big-endian mafia!
3597
3598// Extract the 8-bit alpha component from a pixel
3599static inline unsigned
3600ncpixel_a(uint32_t pixel){
3601 return (htole(pixel) & 0xff000000u) >> 24u;
3602}
3603
3604// Extract the 8-bit red component from an ABGR pixel
3605static inline unsigned
3606ncpixel_r(uint32_t pixel){
3607 return (htole(pixel) & 0x000000ffu);
3608}
3609
3610// Extract the 8-bit green component from an ABGR pixel
3611static inline unsigned
3612ncpixel_g(uint32_t pixel){
3613 return (htole(pixel) & 0x0000ff00u) >> 8u;
3614}
3615
3616// Extract the 8-bit blue component from an ABGR pixel
3617static inline unsigned
3618ncpixel_b(uint32_t pixel){
3619 return (htole(pixel) & 0x00ff0000u) >> 16u;
3620}
3621
3622// Set the 8-bit alpha component of an ABGR pixel
3623static inline int
3624ncpixel_set_a(uint32_t* pixel, unsigned a){
3625 if(a > 255){
3626 return -1;
3627 }
3628 *pixel = htole((htole(*pixel) & 0x00ffffffu) | (a << 24u));
3629 return 0;
3630}
3631
3632// Set the 8-bit red component of an ABGR pixel
3633static inline int
3634ncpixel_set_r(uint32_t* pixel, unsigned r){
3635 if(r > 255){
3636 return -1;
3637 }
3638 *pixel = htole((htole(*pixel) & 0xffffff00u) | r);
3639 return 0;
3640}
3641
3642// Set the 8-bit green component of an ABGR pixel
3643static inline int
3644ncpixel_set_g(uint32_t* pixel, unsigned g){
3645 if(g > 255){
3646 return -1;
3647 }
3648 *pixel = htole((htole(*pixel) & 0xffff00ffu) | (g << 8u));
3649 return 0;
3650}
3651
3652// Set the 8-bit blue component of an ABGR pixel
3653static inline int
3654ncpixel_set_b(uint32_t* pixel, unsigned b){
3655 if(b > 255){
3656 return -1;
3657 }
3658 *pixel = htole((htole(*pixel) & 0xff00ffffu) | (b << 16u));
3659 return 0;
3660}
3661
3662// Construct a libav-compatible ABGR pixel, clipping at [0, 255).
3663static inline uint32_t
3664ncpixel(unsigned r, unsigned g, unsigned b){
3665 uint32_t pixel = 0;
3666 ncpixel_set_a(&pixel, 0xff);
3667 if(r > 255) r = 255;
3668 ncpixel_set_r(&pixel, r);
3669 if(g > 255) g = 255;
3670 ncpixel_set_g(&pixel, g);
3671 if(b > 255) b = 255;
3672 ncpixel_set_b(&pixel, b);
3673 return pixel;
3674}
3675
3676// set the RGB values of an RGB pixel
3677static inline int
3678ncpixel_set_rgb8(uint32_t* pixel, unsigned r, unsigned g, unsigned b){
3679 if(ncpixel_set_r(pixel, r) || ncpixel_set_g(pixel, g) || ncpixel_set_b(pixel, b)){
3680 return -1;
3681 }
3682 return 0;
3683}
3684
3685// An ncreel is a Notcurses region devoted to displaying zero or more
3686// line-oriented, contained tablets between which the user may navigate. If at
3687// least one tablets exists, there is a "focused tablet". As much of the focused
3688// tablet as is possible is always displayed. If there is space left over, other
3689// tablets are included in the display. Tablets can come and go at any time, and
3690// can grow or shrink at any time.
3691//
3692// This structure is amenable to line- and page-based navigation via keystrokes,
3693// scrolling gestures, trackballs, scrollwheels, touchpads, and verbal commands.
3694
3695// is scrolling infinite (can one move down or up forever, or is an end
3696// reached?). if true, 'circular' specifies how to handle the special case of
3697// an incompletely-filled reel.
3698#define NCREEL_OPTION_INFINITESCROLL 0x0001ull
3699// is navigation circular (does moving down from the last tablet move to the
3700// first, and vice versa)? only meaningful when infinitescroll is true. if
3701// infinitescroll is false, this must be false.
3702#define NCREEL_OPTION_CIRCULAR 0x0002ull
3703
3704typedef struct ncreel_options {
3705 // Notcurses can draw a border around the ncreel, and also around the
3706 // component tablets. inhibit borders by setting all valid bits in the masks.
3707 // partially inhibit borders by setting individual bits in the masks. the
3708 // appropriate attr and pair values will be used to style the borders.
3709 // focused and non-focused tablets can have different styles. you can instead
3710 // draw your own borders, or forgo borders entirely.
3711 unsigned bordermask; // bitfield; 1s will not be drawn (see bordermaskbits)
3712 uint64_t borderchan; // attributes used for ncreel border
3713 unsigned tabletmask; // bitfield; same as bordermask but for tablet borders
3714 uint64_t tabletchan; // tablet border styling channel
3715 uint64_t focusedchan;// focused tablet border styling channel
3716 uint64_t flags; // bitfield over NCREEL_OPTION_*
3718
3719// Take over the ncplane 'nc' and use it to draw a reel according to 'popts'.
3720// The plane will be destroyed by ncreel_destroy(); this transfers ownership.
3721API ALLOC struct ncreel* ncreel_create(struct ncplane* n, const ncreel_options* popts)
3722 __attribute__ ((nonnull (1)));
3723
3724// Returns the ncplane on which this ncreel lives.
3725API struct ncplane* ncreel_plane(struct ncreel* nr)
3726 __attribute__ ((nonnull (1)));
3727
3728// Tablet draw callback, provided a tablet (from which the ncplane and userptr
3729// may be extracted), and a bool indicating whether output ought be drawn from
3730// the top (true) or bottom (false). Returns non-negative count of output lines,
3731// which must be less than or equal to ncplane_dim_y(nctablet_plane(t)).
3732typedef int (*tabletcb)(struct nctablet* t, bool drawfromtop);
3733
3734// Add a new nctablet to the provided ncreel 'nr', having the callback object
3735// 'opaque'. Neither, either, or both of 'after' and 'before' may be specified.
3736// If neither is specified, the new tablet can be added anywhere on the reel.
3737// If one or the other is specified, the tablet will be added before or after
3738// the specified tablet. If both are specified, the tablet will be added to the
3739// resulting location, assuming it is valid (after->next == before->prev); if
3740// it is not valid, or there is any other error, NULL will be returned.
3741API ALLOC struct nctablet* ncreel_add(struct ncreel* nr, struct nctablet* after,
3742 struct nctablet* before, tabletcb cb,
3743 void* opaque)
3744 __attribute__ ((nonnull (1)));
3745
3746// Return the number of nctablets in the ncreel 'nr'.
3747API int ncreel_tabletcount(const struct ncreel* nr)
3748 __attribute__ ((nonnull (1)));
3749
3750// Delete the tablet specified by t from the ncreel 'nr'. Returns -1 if the
3751// tablet cannot be found.
3752API int ncreel_del(struct ncreel* nr, struct nctablet* t)
3753 __attribute__ ((nonnull (1)));
3754
3755// Redraw the ncreel 'nr' in its entirety. The reel will be cleared, and
3756// tablets will be lain out, using the focused tablet as a fulcrum. Tablet
3757// drawing callbacks will be invoked for each visible tablet.
3758API int ncreel_redraw(struct ncreel* nr)
3759 __attribute__ ((nonnull (1)));
3760
3761// Offer input 'ni' to the ncreel 'nr'. If it's relevant, this function returns
3762// true, and the input ought not be processed further. If it's irrelevant to
3763// the reel, false is returned. Relevant inputs include:
3764// * a mouse click on a tablet (focuses tablet)
3765// * a mouse scrollwheel event (rolls reel)
3766// * up, down, pgup, or pgdown (navigates among items)
3767API bool ncreel_offer_input(struct ncreel* nr, const ncinput* ni)
3768 __attribute__ ((nonnull (1, 2)));
3769
3770// Return the focused tablet, if any tablets are present. This is not a copy;
3771// be careful to use it only for the duration of a critical section.
3772API struct nctablet* ncreel_focused(struct ncreel* nr)
3773 __attribute__ ((nonnull (1)));
3774
3775// Change focus to the next tablet, if one exists
3776API struct nctablet* ncreel_next(struct ncreel* nr)
3777 __attribute__ ((nonnull (1)));
3778
3779// Change focus to the previous tablet, if one exists
3780API struct nctablet* ncreel_prev(struct ncreel* nr)
3781 __attribute__ ((nonnull (1)));
3782
3783// Destroy an ncreel allocated with ncreel_create().
3784API void ncreel_destroy(struct ncreel* nr);
3785
3786// Returns a pointer to a user pointer associated with this nctablet.
3787API void* nctablet_userptr(struct nctablet* t);
3788
3789// Access the ncplane associated with nctablet 't', if one exists.
3790API struct ncplane* nctablet_plane(struct nctablet* t);
3791
3792// Takes an arbitrarily large number, and prints it into a fixed-size buffer by
3793// adding the necessary SI suffix. Usually, pass a |NC[IB]?PREFIXSTRLEN+1|-sized
3794// buffer to generate up to |NC[IB]?PREFIXCOLUMNS| columns' worth of EGCs. The
3795// characteristic can occupy up through |mult-1| characters (3 for 1000, 4 for
3796// 1024). The mantissa can occupy either zero or two characters.
3797
3798// snprintf(3) is used internally, with 's' as its size bound. If the output
3799// requires more size than is available, NULL will be returned.
3800//
3801// Floating-point is never used, because an IEEE758 double can only losslessly
3802// represent integers through 2^53-1.
3803//
3804// 2^64-1 is 18446744073709551615, 18.45E(xa). KMGTPEZY thus suffice to handle
3805// an 89-bit uintmax_t. Beyond Z(etta) and Y(otta) lie lands unspecified by SI.
3806// 2^-63 is 0.000000000000000000108, 1.08a(tto).
3807// val: value to print
3808// s: maximum output size; see snprintf(3)
3809// decimal: scaling. '1' if none has taken place.
3810// buf: buffer in which string will be generated
3811// omitdec: inhibit printing of all-0 decimal portions
3812// mult: base of suffix system (almost always 1000 or 1024)
3813// uprefix: character to print following suffix ('i' for kibibytes basically).
3814// only printed if suffix is actually printed (input >= mult).
3815//
3816// You are encouraged to consult notcurses_metric(3).
3817API const char* ncnmetric(uintmax_t val, size_t s, uintmax_t decimal,
3818 char* buf, int omitdec, uintmax_t mult, int uprefix)
3819 __attribute__ ((nonnull (4)));
3820
3821// The number of columns is one fewer, as the STRLEN expressions must leave
3822// an extra byte open in case 'µ' (U+00B5, 0xC2 0xB5) shows up. NCPREFIXCOLUMNS
3823// is the maximum number of columns used by a mult == 1000 (standard)
3824// ncnmetric() call. NCIPREFIXCOLUMNS is the maximum number of columns used by a
3825// mult == 1024 (digital information) ncnmetric(). NCBPREFIXSTRLEN is the maximum
3826// number of columns used by a mult == 1024 call making use of the 'i' suffix.
3827// This is the true number of columns; to set up a printf()-style maximum
3828// field width, you should use NC[IB]PREFIXFMT (see below).
3829#define NCPREFIXCOLUMNS 7
3830#define NCIPREFIXCOLUMNS 8
3831#define NCBPREFIXCOLUMNS 9
3832#define NCPREFIXSTRLEN (NCPREFIXCOLUMNS + 1) // Does not include a '\0' (xxx.xxU)
3833#define NCIPREFIXSTRLEN (NCIPREFIXCOLUMNS + 1) // Does not include a '\0' (xxxx.xxU)
3834#define NCBPREFIXSTRLEN (NCBPREFIXCOLUMNS + 1) // Does not include a '\0' (xxxx.xxUi), i == prefix
3835// Used as arguments to a variable field width (i.e. "%*s" -- these are the *).
3836// We need this convoluted grotesquery to properly handle 'µ'.
3837#define NCMETRICFWIDTH(x, cols) \
3838 ((int)(strlen(x) - ncstrwidth(x, NULL, NULL) + (cols)))
3839#define NCPREFIXFMT(x) NCMETRICFWIDTH((x), NCPREFIXCOLUMNS), (x)
3840#define NCIPREFIXFMT(x) NCMETRICFWIDTH((x), NCIPREFIXCOLUMNS), (x)
3841#define NCBPREFIXFMT(x) NCMETRICFWIDTH((x), NCBPREFIXCOLUMNS), (x)
3842
3843// Mega, kilo, gigafoo. Use PREFIXSTRLEN + 1 and PREFIXCOLUMNS.
3844static inline const char*
3845ncqprefix(uintmax_t val, uintmax_t decimal, char* buf, int omitdec){
3846 return ncnmetric(val, NCPREFIXSTRLEN + 1, decimal, buf, omitdec, 1000, '\0');
3847}
3848
3849// Mibi, kebi, gibibytes sans 'i' suffix. Use IPREFIXSTRLEN + 1.
3850static inline const char*
3851nciprefix(uintmax_t val, uintmax_t decimal, char* buf, int omitdec){
3852 return ncnmetric(val, NCIPREFIXSTRLEN + 1, decimal, buf, omitdec, 1024, '\0');
3853}
3854
3855// Mibi, kebi, gibibytes. Use BPREFIXSTRLEN + 1 and BPREFIXCOLUMNS.
3856static inline const char*
3857ncbprefix(uintmax_t val, uintmax_t decimal, char* buf, int omitdec){
3858 return ncnmetric(val, NCBPREFIXSTRLEN + 1, decimal, buf, omitdec, 1024, 'i');
3859}
3860
3861// Get the default foreground color, if it is known. Returns -1 on error
3862// (unknown foreground). On success, returns 0, writing the RGB value to
3863// 'fg' (if non-NULL)
3864API int notcurses_default_foreground(const struct notcurses* nc, uint32_t* fg)
3865 __attribute__ ((nonnull (1)));
3866
3867// Get the default background color, if it is known. Returns -1 on error
3868// (unknown background). On success, returns 0, writing the RGB value to
3869// 'bg' (if non-NULL) and setting 'bgtrans' high iff the background color
3870// is treated as transparent.
3871API int notcurses_default_background(const struct notcurses* nc, uint32_t* bg)
3872 __attribute__ ((nonnull (1)));
3873
3874// Enable or disable the terminal's cursor, if supported, placing it at
3875// 'y', 'x'. Immediate effect (no need for a call to notcurses_render()).
3876// It is an error if 'y', 'x' lies outside the standard plane. Can be
3877// called while already visible to move the cursor.
3878API int notcurses_cursor_enable(struct notcurses* nc, int y, int x)
3879 __attribute__ ((nonnull (1)));
3880
3881// Disable the hardware cursor. It is an error to call this while the
3882// cursor is already disabled.
3884 __attribute__ ((nonnull (1)));
3885
3886// Get the current location of the terminal's cursor, whether visible or not.
3887API int notcurses_cursor_yx(const struct notcurses* nc, int* y, int* x)
3888 __attribute__ ((nonnull (1)));
3889
3890// Convert the plane's content to greyscale.
3891API void ncplane_greyscale(struct ncplane* n)
3892 __attribute__ ((nonnull (1)));
3893
3894// ╭──────────────────────────╮
3895// │This is the primary header│
3896// ╭──────────────────────this is the secondary header──────╮
3897// │ ↑ │
3898// │ option1 Long text #1 │
3899// │ option2 Long text #2 │
3900// │ option3 Long text #3 │
3901// │ option4 Long text #4 │
3902// │ option5 Long text #5 │
3903// │ option6 Long text #6 │
3904// │ ↓ │
3905// ╰────────────────────────────────────here's the footer───╯
3906
3907// selection widget -- an ncplane with a title header and a body section. the
3908// body section supports infinite scrolling up and down.
3909//
3910// At all times, exactly one item is selected.
3912 const char* option;
3913 const char* desc;
3914};
3915
3916typedef struct ncselector_options {
3917 const char* title; // title may be NULL, inhibiting riser, saving two rows.
3918 const char* secondary; // secondary may be NULL
3919 const char* footer; // footer may be NULL
3920 const struct ncselector_item* items; // initial items and descriptions
3921 // default item (selected at start), must be < itemcount unless itemcount is
3922 // 0, in which case 'defidx' must also be 0
3923 unsigned defidx;
3924 // maximum number of options to display at once, 0 to use all available space
3925 unsigned maxdisplay;
3926 // exhaustive styling options
3927 uint64_t opchannels; // option channels
3928 uint64_t descchannels; // description channels
3929 uint64_t titlechannels;// title channels
3930 uint64_t footchannels; // secondary and footer channels
3931 uint64_t boxchannels; // border channels
3932 uint64_t flags; // bitfield of NCSELECTOR_OPTION_*, currently unused
3934
3936 __attribute__ ((nonnull (1)));
3937
3938// Dynamically add or delete items. It is usually sufficient to supply a static
3939// list of items via ncselector_options->items.
3940API int ncselector_additem(struct ncselector* n, const struct ncselector_item* item);
3941API int ncselector_delitem(struct ncselector* n, const char* item);
3942
3943// Return reference to the selected option, or NULL if there are no items.
3944API const char* ncselector_selected(const struct ncselector* n)
3945 __attribute__ ((nonnull (1)));
3946
3947// Return a reference to the ncselector's underlying ncplane.
3948API struct ncplane* ncselector_plane(struct ncselector* n)
3949 __attribute__ ((nonnull (1)));
3950
3951// Move up or down in the list. A reference to the newly-selected item is
3952// returned, or NULL if there are no items in the list.
3953API const char* ncselector_previtem(struct ncselector* n)
3954 __attribute__ ((nonnull (1)));
3955API const char* ncselector_nextitem(struct ncselector* n)
3956 __attribute__ ((nonnull (1)));
3957
3958// Offer the input to the ncselector. If it's relevant, this function returns
3959// true, and the input ought not be processed further. If it's irrelevant to
3960// the selector, false is returned. Relevant inputs include:
3961// * a mouse click on an item
3962// * a mouse scrollwheel event
3963// * a mouse click on the scrolling arrows
3964// * up, down, pgup, or pgdown on an unrolled menu (navigates among items)
3966 __attribute__ ((nonnull (1, 2)));
3967
3968// Destroy the ncselector.
3969API void ncselector_destroy(struct ncselector* n, char** item);
3970
3972 const char* option;
3973 const char* desc;
3975};
3976
3977// ╭───────────────────╮
3978// │ short round title │
3979//╭now this secondary is also very, very, very outlandishly long, you see┤
3980//│ ↑ │
3981//│ ☐ Pa231 Protactinium-231 (162kg) │
3982//│ ☐ U233 Uranium-233 (15kg) │
3983//│ ☐ U235 Uranium-235 (50kg) │
3984//│ ☐ Np236 Neptunium-236 (7kg) │
3985//│ ☐ Np237 Neptunium-237 (60kg) │
3986//│ ☐ Pu238 Plutonium-238 (10kg) │
3987//│ ☐ Pu239 Plutonium-239 (10kg) │
3988//│ ☐ Pu240 Plutonium-240 (40kg) │
3989//│ ☐ Pu241 Plutonium-241 (13kg) │
3990//│ ☐ Am241 Americium-241 (100kg) │
3991//│ ↓ │
3992//╰────────────────────────press q to exit (there is sartrev("no exit"))─╯
3993
3994// multiselection widget -- a selector supporting multiple selections.
3995//
3996// Unlike the selector widget, zero to all of the items can be selected, but
3997// also the widget does not support adding or removing items at runtime.
3999 const char* title; // title may be NULL, inhibiting riser, saving two rows.
4000 const char* secondary; // secondary may be NULL
4001 const char* footer; // footer may be NULL
4002 const struct ncmselector_item* items; // initial items, descriptions, and statuses
4003 // maximum number of options to display at once, 0 to use all available space
4004 unsigned maxdisplay;
4005 // exhaustive styling options
4006 uint64_t opchannels; // option channels
4007 uint64_t descchannels; // description channels
4008 uint64_t titlechannels;// title channels
4009 uint64_t footchannels; // secondary and footer channels
4010 uint64_t boxchannels; // border channels
4011 uint64_t flags; // bitfield of NCMULTISELECTOR_OPTION_*, currently unused
4013
4015 __attribute__ ((nonnull (1)));
4016
4017// Return selected vector. An array of bools must be provided, along with its
4018// length. If that length doesn't match the itemcount, it is an error.
4019API int ncmultiselector_selected(struct ncmultiselector* n, bool* selected, unsigned count);
4020
4021// Return a reference to the ncmultiselector's underlying ncplane.
4023
4024// Offer the input to the ncmultiselector. If it's relevant, this function
4025// returns true, and the input ought not be processed further. If it's
4026// irrelevant to the multiselector, false is returned. Relevant inputs include:
4027// * a mouse click on an item
4028// * a mouse scrollwheel event
4029// * a mouse click on the scrolling arrows
4030// * up, down, pgup, or pgdown on an unrolled menu (navigates among items)
4032 __attribute__ ((nonnull (1, 2)));
4033
4034// Destroy the ncmultiselector.
4036
4037// nctree widget -- a vertical browser supporting line-based hierarchies.
4038//
4039// each item can have subitems, and has a curry. there is one callback for the
4040// entirety of the nctree. visible items have the callback invoked upon their
4041// curry and an ncplane. the ncplane can be reused across multiple invocations
4042// of the callback.
4043
4044// each item has a curry, and zero or more subitems.
4046 void* curry;
4048 unsigned subcount;
4049};
4050
4051typedef struct nctree_options {
4052 const struct nctree_item* items; // top-level nctree_item array
4053 unsigned count; // size of |items|
4054 int (*nctreecb)(struct ncplane*, void*, int); // item callback function
4055 int indentcols; // columns to indent per level of hierarchy
4056 uint64_t flags; // bitfield of NCTREE_OPTION_*
4058
4059// |opts| may *not* be NULL, since it is necessary to define a callback
4060// function.
4062 __attribute__ ((nonnull (1, 2)));
4063
4064// Returns the ncplane on which this nctree lives.
4065API struct ncplane* nctree_plane(struct nctree* n)
4066 __attribute__ ((nonnull (1)));
4067
4068// Redraw the nctree 'n' in its entirety. The tree will be cleared, and items
4069// will be lain out, using the focused item as a fulcrum. Item-drawing
4070// callbacks will be invoked for each visible item.
4071API int nctree_redraw(struct nctree* n)
4072 __attribute__ ((nonnull (1)));
4073
4074// Offer input 'ni' to the nctree 'n'. If it's relevant, this function returns
4075// true, and the input ought not be processed further. If it's irrelevant to
4076// the tree, false is returned. Relevant inputs include:
4077// * a mouse click on an item (focuses item)
4078// * a mouse scrollwheel event (srolls tree)
4079// * up, down, pgup, or pgdown (navigates among items)
4080API bool nctree_offer_input(struct nctree* n, const ncinput* ni)
4081 __attribute__ ((nonnull (1, 2)));
4082
4083// Return the focused item, if any items are present. This is not a copy;
4084// be careful to use it only for the duration of a critical section.
4085API void* nctree_focused(struct nctree* n) __attribute__ ((nonnull (1)));
4086
4087// Change focus to the next item.
4088API void* nctree_next(struct nctree* n) __attribute__ ((nonnull (1)));
4089
4090// Change focus to the previous item.
4091API void* nctree_prev(struct nctree* n) __attribute__ ((nonnull (1)));
4092
4093// Go to the item specified by the array |spec| (a spec is a series of unsigned
4094// values, each identifying a subelement in the hierarchy thus far, terminated
4095// by UINT_MAX). If the spec is invalid, NULL is returned, and the depth of the
4096// first invalid spec is written to *|failspec|. Otherwise, the true depth is
4097// written to *|failspec|, and the curry is returned (|failspec| is necessary
4098// because the curry could itself be NULL).
4099API void* nctree_goto(struct nctree* n, const unsigned* spec, int* failspec);
4100
4101// Insert |add| into the nctree |n| at |spec|. The path up to the last element
4102// must already exist. If an item already exists at the path, it will be moved
4103// to make room for |add|.
4104API int nctree_add(struct nctree* n, const unsigned* spec, const struct nctree_item* add)
4105 __attribute__ ((nonnull (1, 2, 3)));
4106
4107// Delete the item at |spec|, including any subitems.
4108API int nctree_del(struct nctree* n, const unsigned* spec)
4109 __attribute__ ((nonnull (1, 2)));
4110
4111// Destroy the nctree.
4112API void nctree_destroy(struct nctree* n);
4113
4114// Menus. Horizontal menu bars are supported, on the top and/or bottom rows.
4115// If the menu bar is longer than the screen, it will be only partially
4116// visible. Menus may be either visible or invisible by default. In the event of
4117// a plane resize, menus will be automatically moved/resized. Elements can be
4118// dynamically enabled or disabled at all levels (menu, section, and item),
4120 const char* desc; // utf-8 menu item, NULL for horizontal separator
4121 ncinput shortcut; // shortcut, all should be distinct
4122};
4123
4125 const char* name; // utf-8 c string
4128 ncinput shortcut; // shortcut, will be underlined if present in name
4129};
4130
4131#define NCMENU_OPTION_BOTTOM 0x0001ull // bottom row (as opposed to top row)
4132#define NCMENU_OPTION_HIDING 0x0002ull // hide the menu when not unrolled
4133
4134typedef struct ncmenu_options {
4135 struct ncmenu_section* sections; // array of 'sectioncount' menu_sections
4136 int sectioncount; // must be positive
4137 uint64_t headerchannels; // styling for header
4138 uint64_t sectionchannels; // styling for sections
4139 uint64_t flags; // flag word of NCMENU_OPTION_*
4141
4142// Create a menu with the specified options, bound to the specified plane.
4143API ALLOC struct ncmenu* ncmenu_create(struct ncplane* n, const ncmenu_options* opts)
4144 __attribute__ ((nonnull (1)));
4145
4146// Unroll the specified menu section, making the menu visible if it was
4147// invisible, and rolling up any menu section that is already unrolled.
4148API int ncmenu_unroll(struct ncmenu* n, int sectionidx);
4149
4150// Roll up any unrolled menu section, and hide the menu if using hiding.
4151API int ncmenu_rollup(struct ncmenu* n) __attribute__ ((nonnull (1)));
4152
4153// Unroll the previous/next section (relative to current unrolled). If no
4154// section is unrolled, the first section will be unrolled.
4155API int ncmenu_nextsection(struct ncmenu* n) __attribute__ ((nonnull (1)));
4156API int ncmenu_prevsection(struct ncmenu* n) __attribute__ ((nonnull (1)));
4157
4158// Move to the previous/next item within the currently unrolled section. If no
4159// section is unrolled, the first section will be unrolled.
4160API int ncmenu_nextitem(struct ncmenu* n) __attribute__ ((nonnull (1)));
4161API int ncmenu_previtem(struct ncmenu* n) __attribute__ ((nonnull (1)));
4162
4163// Disable or enable a menu item. Returns 0 if the item was found.
4164API int ncmenu_item_set_status(struct ncmenu* n, const char* section,
4165 const char* item, bool enabled);
4166
4167// Return the selected item description, or NULL if no section is unrolled. If
4168// 'ni' is not NULL, and the selected item has a shortcut, 'ni' will be filled
4169// in with that shortcut--this can allow faster matching.
4170API const char* ncmenu_selected(const struct ncmenu* n, ncinput* ni);
4171
4172// Return the item description corresponding to the mouse click 'click'. The
4173// item must be on an actively unrolled section, and the click must be in the
4174// area of a valid item. If 'ni' is not NULL, and the selected item has a
4175// shortcut, 'ni' will be filled in with the shortcut.
4176API const char* ncmenu_mouse_selected(const struct ncmenu* n,
4177 const ncinput* click, ncinput* ni);
4178
4179// Return the ncplane backing this ncmenu.
4180API struct ncplane* ncmenu_plane(struct ncmenu* n);
4181
4182// Offer the input to the ncmenu. If it's relevant, this function returns true,
4183// and the input ought not be processed further. If it's irrelevant to the
4184// menu, false is returned. Relevant inputs include:
4185// * mouse movement over a hidden menu
4186// * a mouse click on a menu section (the section is unrolled)
4187// * a mouse click outside of an unrolled menu (the menu is rolled up)
4188// * left or right on an unrolled menu (navigates among sections)
4189// * up or down on an unrolled menu (navigates among items)
4190// * escape on an unrolled menu (the menu is rolled up)
4191API bool ncmenu_offer_input(struct ncmenu* n, const ncinput* nc)
4192 __attribute__ ((nonnull (1, 2)));
4193
4194// Destroy a menu created with ncmenu_create().
4195API void ncmenu_destroy(struct ncmenu* n);
4196
4197// Progress bars. They proceed linearly in any of four directions. The entirety
4198// of the plane will be used -- any border should be provided by the caller on
4199// another plane. The plane will not be erased; text preloaded into the plane
4200// will be consumed by the progress indicator. The bar is redrawn for each
4201// provided progress report (a double between 0 and 1), and can regress with
4202// lower values. The procession will take place along the longer dimension (at
4203// the time of each redraw), with the horizontal length scaled by 2 for
4204// purposes of comparison. I.e. for a plane of 20 rows and 50 columns, the
4205// progress will be to the right (50 > 40) or left with OPTION_RETROGRADE.
4206
4207#define NCPROGBAR_OPTION_RETROGRADE 0x0001u // proceed left/down
4208
4209typedef struct ncprogbar_options {
4210 uint32_t ulchannel; // upper-left channel. in the context of a progress bar,
4211 uint32_t urchannel; // "up" is the direction we are progressing towards, and
4212 uint32_t blchannel; // "bottom" is the direction of origin. for monochromatic
4213 uint32_t brchannel; // bar, all four channels ought be the same.
4214 uint64_t flags;
4216
4217// Takes ownership of the ncplane 'n', which will be destroyed by
4218// ncprogbar_destroy(). The progress bar is initially at 0%.
4220 __attribute__ ((nonnull (1)));
4221
4222// Return a reference to the ncprogbar's underlying ncplane.
4223API struct ncplane* ncprogbar_plane(struct ncprogbar* n)
4224 __attribute__ ((nonnull (1)));
4225
4226// Set the progress bar's completion, a double 0 <= 'p' <= 1.
4227API int ncprogbar_set_progress(struct ncprogbar* n, double p)
4228 __attribute__ ((nonnull (1)));
4229
4230// Get the progress bar's completion, a double on [0, 1].
4231API double ncprogbar_progress(const struct ncprogbar* n)
4232 __attribute__ ((nonnull (1)));
4233
4234// Destroy the progress bar and its underlying ncplane.
4235API void ncprogbar_destroy(struct ncprogbar* n);
4236
4237// Tabbed widgets. The tab list is displayed at the top or at the bottom of the
4238// plane, and only one tab is visible at a time.
4239
4240// Display the tab list at the bottom instead of at the top of the plane
4241#define NCTABBED_OPTION_BOTTOM 0x0001ull
4242
4243typedef struct nctabbed_options {
4244 uint64_t selchan; // channel for the selected tab header
4245 uint64_t hdrchan; // channel for unselected tab headers
4246 uint64_t sepchan; // channel for the tab separator
4247 const char* separator; // separator string (copied by nctabbed_create())
4248 uint64_t flags; // bitmask of NCTABBED_OPTION_*
4250
4251// Tab content drawing callback. Takes the tab it was associated to, the ncplane
4252// on which tab content is to be drawn, and the user pointer of the tab.
4253// It is called during nctabbed_redraw().
4254typedef void (*tabcb)(struct nctab* t, struct ncplane* ncp, void* curry);
4255
4256// Creates a new nctabbed widget, associated with the given ncplane 'n', and with
4257// additional options given in 'opts'. When 'opts' is NULL, it acts as if it were
4258// called with an all-zero opts. The widget takes ownership of 'n', and destroys
4259// it when the widget is destroyed. Returns the newly created widget. Returns
4260// NULL on failure, also destroying 'n'.
4262 __attribute ((nonnull (1)));
4263
4264// Destroy an nctabbed widget. All memory belonging to 'nt' is deallocated,
4265// including all tabs and their names. The plane associated with 'nt' is also
4266// destroyed. Calling this with NULL does nothing.
4267API void nctabbed_destroy(struct nctabbed* nt);
4268
4269// Redraw the widget. This calls the tab callback of the currently selected tab
4270// to draw tab contents, and draws tab headers. The tab content plane is not
4271// modified by this function, apart from resizing the plane is necessary.
4272API void nctabbed_redraw(struct nctabbed* nt)
4273 __attribute__ ((nonnull (1)));
4274
4275// Make sure the tab header of the currently selected tab is at least partially
4276// visible. (by rotating tabs until at least one column is displayed)
4277// Does nothing if there are no tabs.
4279 __attribute__ ((nonnull (1)));
4280
4281// Returns the currently selected tab, or NULL if there are no tabs.
4282API struct nctab* nctabbed_selected(struct nctabbed* nt)
4283 __attribute__ ((nonnull (1)));
4284
4285// Returns the leftmost tab, or NULL if there are no tabs.
4286API struct nctab* nctabbed_leftmost(struct nctabbed* nt)
4287 __attribute__ ((nonnull (1)));
4288
4289// Returns the number of tabs in the widget.
4290API int nctabbed_tabcount(struct nctabbed* nt)
4291 __attribute__ ((nonnull (1)));
4292
4293// Returns the plane associated to 'nt'.
4294API struct ncplane* nctabbed_plane(struct nctabbed* nt)
4295 __attribute__ ((nonnull (1)));
4296
4297// Returns the tab content plane.
4298API struct ncplane* nctabbed_content_plane(struct nctabbed* nt)
4299 __attribute__ ((nonnull (1)));
4300
4301// Returns the tab callback.
4302API tabcb nctab_cb(struct nctab* t)
4303 __attribute__ ((nonnull (1)));
4304
4305// Returns the tab name. This is not a copy and it should not be stored.
4306API const char* nctab_name(struct nctab* t)
4307 __attribute__ ((nonnull (1)));
4308
4309// Returns the width (in columns) of the tab's name.
4310API int nctab_name_width(struct nctab* t)
4311 __attribute__ ((nonnull (1)));
4312
4313// Returns the tab's user pointer.
4314API void* nctab_userptr(struct nctab* t)
4315 __attribute__ ((nonnull (1)));
4316
4317// Returns the tab to the right of 't'. This does not change which tab is selected.
4318API struct nctab* nctab_next(struct nctab* t)
4319 __attribute__ ((nonnull (1)));
4320
4321// Returns the tab to the left of 't'. This does not change which tab is selected.
4322API struct nctab* nctab_prev(struct nctab* t)
4323 __attribute__ ((nonnull (1)));
4324
4325// Add a new tab to 'nt' with the given tab callback, name, and user pointer.
4326// If both 'before' and 'after' are NULL, the tab is inserted after the selected
4327// tab. Otherwise, it gets put after 'after' (if not NULL) and before 'before'
4328// (if not NULL). If both 'after' and 'before' are given, they must be two
4329// neighboring tabs (the tab list is circular, so the last tab is immediately
4330// before the leftmost tab), otherwise the function returns NULL. If 'name' is
4331// NULL or a string containing illegal characters, the function returns NULL.
4332// On all other failures the function also returns NULL. If it returns NULL,
4333// none of the arguments are modified, and the widget state is not altered.
4334API ALLOC struct nctab* nctabbed_add(struct nctabbed* nt, struct nctab* after,
4335 struct nctab* before, tabcb tcb,
4336 const char* name, void* opaque)
4337 __attribute__ ((nonnull (1, 5)));
4338
4339// Remove a tab 't' from 'nt'. Its neighboring tabs become neighbors to each
4340// other. If 't' if the selected tab, the tab after 't' becomes selected.
4341// Likewise if 't' is the leftmost tab, the tab after 't' becomes leftmost.
4342// If 't' is the only tab, there will no more be a selected or leftmost tab,
4343// until a new tab is added. Returns -1 if 't' is NULL, and 0 otherwise.
4344API int nctabbed_del(struct nctabbed* nt, struct nctab* t)
4345 __attribute__ ((nonnull (1)));
4346
4347// Move 't' after 'after' (if not NULL) and before 'before' (if not NULL).
4348// If both 'after' and 'before' are NULL, the function returns -1, otherwise
4349// it returns 0.
4350API int nctab_move(struct nctabbed* nt, struct nctab* t, struct nctab* after,
4351 struct nctab* before)
4352 __attribute__ ((nonnull (1, 2)));
4353
4354// Move 't' to the right by one tab, looping around to become leftmost if needed.
4355API void nctab_move_right(struct nctabbed* nt, struct nctab* t)
4356 __attribute__ ((nonnull (1, 2)));
4357
4358// Move 't' to the right by one tab, looping around to become the last tab if needed.
4359API void nctab_move_left(struct nctabbed* nt, struct nctab* t)
4360 __attribute__ ((nonnull (1, 2)));
4361
4362// Rotate the tabs of 'nt' right by 'amt' tabs, or '-amt' tabs left if 'amt' is
4363// negative. Tabs are rotated only by changing the leftmost tab; the selected tab
4364// stays the same. If there are no tabs, nothing happens.
4365API void nctabbed_rotate(struct nctabbed* nt, int amt)
4366 __attribute__ ((nonnull (1)));
4367
4368// Select the tab after the currently selected tab, and return the newly selected
4369// tab. Returns NULL if there are no tabs.
4370API struct nctab* nctabbed_next(struct nctabbed* nt)
4371 __attribute__ ((nonnull (1)));
4372
4373// Select the tab before the currently selected tab, and return the newly selected
4374// tab. Returns NULL if there are no tabs.
4375API struct nctab* nctabbed_prev(struct nctabbed* nt)
4376 __attribute__ ((nonnull (1)));
4377
4378// Change the selected tab to be 't'. Returns the previously selected tab.
4379API struct nctab* nctabbed_select(struct nctabbed* nt, struct nctab* t)
4380 __attribute__ ((nonnull (1, 2)));
4381
4382// Write the channels for tab headers, the selected tab header, and the separator
4383// to '*hdrchan', '*selchan', and '*sepchan' respectively.
4384API void nctabbed_channels(struct nctabbed* nt, uint64_t* RESTRICT hdrchan,
4385 uint64_t* RESTRICT selchan, uint64_t* RESTRICT sepchan)
4386 __attribute__ ((nonnull (1)));
4387
4388static inline uint64_t
4389nctabbed_hdrchan(struct nctabbed* nt){
4390 uint64_t ch;
4391 nctabbed_channels(nt, &ch, NULL, NULL);
4392 return ch;
4393}
4394
4395static inline uint64_t
4396nctabbed_selchan(struct nctabbed* nt){
4397 uint64_t ch;
4398 nctabbed_channels(nt, NULL, &ch, NULL);
4399 return ch;
4400}
4401
4402static inline uint64_t
4403nctabbed_sepchan(struct nctabbed* nt){
4404 uint64_t ch;
4405 nctabbed_channels(nt, NULL, NULL, &ch);
4406 return ch;
4407}
4408
4409// Returns the tab separator. This is not a copy and it should not be stored.
4410// This can be NULL, if the separator was set to NULL in ncatbbed_create() or
4411// nctabbed_set_separator().
4412API const char* nctabbed_separator(struct nctabbed* nt)
4413 __attribute__ ((nonnull (1)));
4414
4415// Returns the tab separator width, or zero if there is no separator.
4417 __attribute__ ((nonnull (1)));
4418
4419// Set the tab headers channel for 'nt'.
4420API void nctabbed_set_hdrchan(struct nctabbed* nt, uint64_t chan)
4421 __attribute__ ((nonnull (1)));
4422
4423// Set the selected tab header channel for 'nt'.
4424API void nctabbed_set_selchan(struct nctabbed* nt, uint64_t chan)
4425 __attribute__ ((nonnull (1)));
4426
4427// Set the tab separator channel for 'nt'.
4428API void nctabbed_set_sepchan(struct nctabbed* nt, uint64_t chan)
4429 __attribute__ ((nonnull (1)));
4430
4431// Set the tab callback function for 't'. Returns the previous tab callback.
4432API tabcb nctab_set_cb(struct nctab* t, tabcb newcb)
4433 __attribute__ ((nonnull (1)));
4434
4435// Change the name of 't'. Returns -1 if 'newname' is NULL, and 0 otherwise.
4436API int nctab_set_name(struct nctab* t, const char* newname)
4437 __attribute__ ((nonnull (1, 2)));
4438
4439// Set the user pointer of 't'. Returns the previous user pointer.
4440API void* nctab_set_userptr(struct nctab* t, void* newopaque)
4441 __attribute__ ((nonnull (1)));
4442
4443// Change the tab separator for 'nt'. Returns -1 if 'separator' is not NULL and
4444// is not a valid string, and 0 otherwise.
4445API int nctabbed_set_separator(struct nctabbed* nt, const char* separator)
4446 __attribute__ ((nonnull (1, 2)));
4447
4448// Plots. Given a rectilinear area, an ncplot can graph samples along some axis.
4449// There is some underlying independent variable--this could be e.g. measurement
4450// sequence number, or measurement time. Samples are tagged with this variable, which
4451// should never fall, but may grow non-monotonically. The desired range in terms
4452// of the underlying independent variable is provided at creation time. The
4453// desired domain can be specified, or can be autosolved. Granularity of the
4454// dependent variable depends on glyph selection.
4455//
4456// For instance, perhaps we're sampling load as a time series. We want to
4457// display an hour's worth of samples in 40 columns and 5 rows. We define the
4458// x-axis to be the independent variable, time. We'll stamp at second
4459// granularity. In this case, there are 60 * 60 == 3600 total elements in the
4460// range. Each column will thus cover a 90s span. Using vertical blocks (the
4461// most granular glyph), we have 8 * 5 == 40 levels of domain. If we report the
4462// following samples, starting at 0, using autosolving, we will observe:
4463//
4464// 60 -- 1% |domain: 1--1, 0: 20 levels
4465// 120 -- 50% |domain: 1--50, 0: 0 levels, 1: 40 levels
4466// 180 -- 50% |domain: 1--50, 0: 0 levels, 1: 40 levels, 2: 40 levels
4467// 240 -- 100% |domain: 1--75, 0: 1, 1: 27, 2: 40
4468// 271 -- 100% |domain: 1--100, 0: 0, 1: 20, 2: 30, 3: 40
4469// 300 -- 25% |domain: 1--75, 0: 0, 1: 27, 2: 40, 3: 33
4470//
4471// At the end, we have data in 4 90s spans: [0--89], [90--179], [180--269], and
4472// [270--359]. The first two spans have one sample each, while the second two
4473// have two samples each. Samples within a span are averaged (FIXME we could
4474// probably do better), so the results are 0, 50, 75, and 62.5. Scaling each of
4475// these out of 90 and multiplying by 40 gets our resulting levels. The final
4476// domain is 75 rather than 100 due to the averaging of 100+25/2->62.5 in the
4477// third span, at which point the maximum span value is once again 75.
4478//
4479// The 20 levels at first is a special case. When the domain is only 1 unit,
4480// and autoscaling is in play, assign 50%.
4481//
4482// This options structure works for both the ncuplot (uint64_t) and ncdplot
4483// (double) types.
4484#define NCPLOT_OPTION_LABELTICKSD 0x0001u // show labels for dependent axis
4485#define NCPLOT_OPTION_EXPONENTIALD 0x0002u // exponential dependent axis
4486#define NCPLOT_OPTION_VERTICALI 0x0004u // independent axis is vertical
4487#define NCPLOT_OPTION_NODEGRADE 0x0008u // fail rather than degrade blitter
4488#define NCPLOT_OPTION_DETECTMAXONLY 0x0010u // use domain detection only for max
4489#define NCPLOT_OPTION_PRINTSAMPLE 0x0020u // print the most recent sample
4490
4491typedef struct ncplot_options {
4492 // channels for the maximum and minimum levels. linear or exponential
4493 // interpolation will be applied across the domain between these two.
4494 uint64_t maxchannels;
4495 uint64_t minchannels;
4496 // styling used for the legend, if NCPLOT_OPTION_LABELTICKSD is set
4497 uint16_t legendstyle;
4498 // if you don't care, pass NCBLIT_DEFAULT and get NCBLIT_8x1 (assuming
4499 // UTF8) or NCBLIT_1x1 (in an ASCII environment)
4500 ncblitter_e gridtype; // number of "pixels" per row x column
4501 // independent variable can either be a contiguous range, or a finite set
4502 // of keys. for a time range, say the previous hour sampled with second
4503 // resolution, the independent variable would be the range [0..3600): 3600.
4504 // if rangex is 0, it is dynamically set to the number of columns.
4506 const char* title; // optional, printed by the labels
4507 uint64_t flags; // bitfield over NCPLOT_OPTION_*
4509
4510// Use the provided plane 'n' for plotting according to the options 'opts'. The
4511// plot will make free use of the entirety of the plane. For domain
4512// autodiscovery, set miny == maxy == 0. ncuplot holds uint64_ts, while
4513// ncdplot holds doubles.
4514API ALLOC struct ncuplot* ncuplot_create(struct ncplane* n, const ncplot_options* opts,
4515 uint64_t miny, uint64_t maxy)
4516 __attribute__ ((nonnull (1)));
4517
4518API ALLOC struct ncdplot* ncdplot_create(struct ncplane* n, const ncplot_options* opts,
4519 double miny, double maxy)
4520 __attribute__ ((nonnull (1)));
4521
4522// Return a reference to the ncplot's underlying ncplane.
4523API struct ncplane* ncuplot_plane(struct ncuplot* n)
4524 __attribute__ ((nonnull (1)));
4525
4526API struct ncplane* ncdplot_plane(struct ncdplot* n)
4527 __attribute__ ((nonnull (1)));
4528
4529// Add to or set the value corresponding to this x. If x is beyond the current
4530// x window, the x window is advanced to include x, and values passing beyond
4531// the window are lost. The first call will place the initial window. The plot
4532// will be redrawn, but notcurses_render() is not called.
4533API int ncuplot_add_sample(struct ncuplot* n, uint64_t x, uint64_t y)
4534 __attribute__ ((nonnull (1)));
4535API int ncdplot_add_sample(struct ncdplot* n, uint64_t x, double y)
4536 __attribute__ ((nonnull (1)));
4537API int ncuplot_set_sample(struct ncuplot* n, uint64_t x, uint64_t y)
4538 __attribute__ ((nonnull (1)));
4539API int ncdplot_set_sample(struct ncdplot* n, uint64_t x, double y)
4540 __attribute__ ((nonnull (1)));
4541
4542API int ncuplot_sample(const struct ncuplot* n, uint64_t x, uint64_t* y)
4543 __attribute__ ((nonnull (1)));
4544API int ncdplot_sample(const struct ncdplot* n, uint64_t x, double* y)
4545 __attribute__ ((nonnull (1)));
4546
4547API void ncuplot_destroy(struct ncuplot* n);
4548API void ncdplot_destroy(struct ncdplot* n);
4549
4550typedef int(*ncfdplane_callback)(struct ncfdplane* n, const void* buf, size_t s, void* curry);
4551typedef int(*ncfdplane_done_cb)(struct ncfdplane* n, int fderrno, void* curry);
4552
4553// read from an fd until EOF (or beyond, if follow is set), invoking the user's
4554// callback each time. runs in its own context. on EOF or error, the finalizer
4555// callback will be invoked, and the user ought destroy the ncfdplane. the
4556// data is *not* guaranteed to be nul-terminated, and may contain arbitrary
4557// zeroes.
4558typedef struct ncfdplane_options {
4559 void* curry; // parameter provided to callbacks
4560 bool follow; // keep reading after hitting end? (think tail -f)
4561 uint64_t flags; // bitfield over NCOPTION_FDPLANE_*
4563
4564// Create an ncfdplane around the fd 'fd'. Consider this function to take
4565// ownership of the file descriptor, which will be closed in ncfdplane_destroy().
4567 int fd, ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn)
4568 __attribute__ ((nonnull (1)));
4569
4570API struct ncplane* ncfdplane_plane(struct ncfdplane* n)
4571 __attribute__ ((nonnull (1)));
4572
4573API int ncfdplane_destroy(struct ncfdplane* n);
4574
4575typedef struct ncsubproc_options {
4576 void* curry;
4577 uint64_t restart_period; // restart this many seconds after an exit (watch)
4578 uint64_t flags; // bitfield over NCOPTION_SUBPROC_*
4580
4581// see exec(2). p-types use $PATH. e-type passes environment vars.
4583 const char* bin, const char* const arg[],
4584 ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn)
4585 __attribute__ ((nonnull (1)));
4586
4588 const char* bin, const char* const arg[],
4589 ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn)
4590 __attribute__ ((nonnull (1)));
4591
4593 const char* bin, const char* const arg[],
4594 const char* const env[],
4595 ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn)
4596 __attribute__ ((nonnull (1)));
4597
4598API struct ncplane* ncsubproc_plane(struct ncsubproc* n)
4599 __attribute__ ((nonnull (1)));
4600
4601API int ncsubproc_destroy(struct ncsubproc* n);
4602
4603// Draw a QR code at the current position on the plane. If there is insufficient
4604// room to draw the code here, or there is any other error, non-zero will be
4605// returned. Otherwise, the QR code "version" (size) is returned. The QR code
4606// is (version * 4 + 17) columns wide, and ⌈version * 4 + 17⌉ rows tall (the
4607// properly-scaled values are written back to '*ymax' and '*xmax').
4608// NCBLIT_2x1 is always used, and the call will fail if it is not available,
4609// as only this blitter can generate a proper aspect ratio.
4610API int ncplane_qrcode(struct ncplane* n, unsigned* ymax, unsigned* xmax,
4611 const void* data, size_t len)
4612 __attribute__ ((nonnull (1, 4)));
4613
4614// Enable horizontal scrolling. Virtual lines can then grow arbitrarily long.
4615#define NCREADER_OPTION_HORSCROLL 0x0001ull
4616// Enable vertical scrolling. You can then use arbitrarily many virtual lines.
4617#define NCREADER_OPTION_VERSCROLL 0x0002ull
4618// Disable all editing shortcuts. By default, emacs-style keys are available.
4619#define NCREADER_OPTION_NOCMDKEYS 0x0004ull
4620// Make the terminal cursor visible across the lifetime of the ncreader, and
4621// have the ncreader manage the cursor's placement.
4622#define NCREADER_OPTION_CURSOR 0x0008ull
4623
4624typedef struct ncreader_options {
4625 uint64_t tchannels; // channels used for input
4626 uint32_t tattrword; // attributes used for input
4627 uint64_t flags; // bitfield of NCREADER_OPTION_*
4629
4630// ncreaders provide freeform input in a (possibly multiline) region, supporting
4631// optional readline keybindings. takes ownership of 'n', destroying it on any
4632// error (ncreader_destroy() otherwise destroys the ncplane).
4634 __attribute__ ((nonnull (1)));
4635
4636// empty the ncreader of any user input, and home the cursor.
4637API int ncreader_clear(struct ncreader* n)
4638 __attribute__ ((nonnull (1)));
4639
4640API struct ncplane* ncreader_plane(struct ncreader* n)
4641 __attribute__ ((nonnull (1)));
4642
4643// Offer the input to the ncreader. If it's relevant, this function returns
4644// true, and the input ought not be processed further. Almost all inputs
4645// are relevant to an ncreader, save synthesized ones.
4647 __attribute__ ((nonnull (1, 2)));
4648
4649// Atttempt to move in the specified direction. Returns 0 if a move was
4650// successfully executed, -1 otherwise. Scrolling is taken into account.
4651API int ncreader_move_left(struct ncreader* n)
4652 __attribute__ ((nonnull (1)));
4653API int ncreader_move_right(struct ncreader* n)
4654 __attribute__ ((nonnull (1)));
4655API int ncreader_move_up(struct ncreader* n)
4656 __attribute__ ((nonnull (1)));
4657API int ncreader_move_down(struct ncreader* n)
4658 __attribute__ ((nonnull (1)));
4659
4660// Destructively write the provided EGC to the current cursor location. Move
4661// the cursor as necessary, scrolling if applicable.
4662API int ncreader_write_egc(struct ncreader* n, const char* egc)
4663 __attribute__ ((nonnull (1, 2)));
4664
4665// return a heap-allocated copy of the current (UTF-8) contents.
4666API char* ncreader_contents(const struct ncreader* n)
4667 __attribute__ ((nonnull (1)));
4668
4669// destroy the reader and its bound plane. if 'contents' is not NULL, the
4670// UTF-8 input will be heap-duplicated and written to 'contents'.
4671API void ncreader_destroy(struct ncreader* n, char** contents);
4672
4673// Returns a heap-allocated copy of the user name under which we are running.
4674API ALLOC char* notcurses_accountname(void);
4675
4676// Returns a heap-allocated copy of the local host name.
4677API ALLOC char* notcurses_hostname(void);
4678
4679// Returns a heap-allocated copy of human-readable OS name and version.
4680API ALLOC char* notcurses_osversion(void);
4681
4682// Dump selected Notcurses state to the supplied 'debugfp'. Output is freeform,
4683// newline-delimited, and subject to change. It includes geometry of all
4684// planes, from all piles. No line has more than 80 columns' worth of output.
4685API void notcurses_debug(const struct notcurses* nc, FILE* debugfp)
4686 __attribute__ ((nonnull (1, 2)));
4687
4688#undef API
4689#undef ALLOC
4690
4691#ifdef __cplusplus
4692} // extern "C"
4693#endif
4694
4695#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:162
const char size_t ulen
Definition egcpool.h:162
uint32_t idx
Definition egcpool.h:209
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:1576
#define NCVISUAL_OPTION_CHILDPLANE
Definition notcurses.h:3346
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:2077
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:1350
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:1231
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:1572
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:1009
API struct ncplane * ncreel_plane(struct ncreel *nr) __attribute__((nonnull(1)))
Definition reel.c:803
return newn
Definition notcurses.h:3512
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:809
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:1244
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:1557
API uint32_t notcurses_get(struct notcurses *n, const struct timespec *ts, ncinput *ni) __attribute__((nonnull(1)))
Definition in.c:2776
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:3488
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:1517
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:4254
API int nctabbed_tabcount(struct nctabbed *nt) __attribute__((nonnull(1)))
Definition tabbed.c:112
#define NCIPREFIXSTRLEN
Definition notcurses.h:3833
#define NCALPHA_OPAQUE
Definition notcurses.h:108
API int ncvisual_resize(struct ncvisual *n, int rows, int cols) __attribute__((nonnull(1)))
Definition visual.c:988
API int notcurses_stop(struct notcurses *nc)
Definition notcurses.c:1449
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:723
#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:1142
API int ncplane_set_base(struct ncplane *n, const char *egc, uint16_t stylemask, uint64_t channels)
Definition notcurses.c:1568
API int ncstrwidth(const char *egcs, int *validbytes, int *validwidth) __attribute__((nonnull(1)))
Definition notcurses.c:3311
#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:3033
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:702
const struct ncplane_options struct ncvisual struct ncvisual_options * vopts
Definition notcurses.h:3488
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:1265
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:2014
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:3487
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:2545
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:75
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:1537
API int ncplane_set_fg_alpha(struct ncplane *n, int alpha)
Definition notcurses.c:1545
int(* tabletcb)(struct nctablet *t, bool drawfromtop)
Definition notcurses.h:3732
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:862
#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:1437
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:1509
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:2591
API int ncplane_erase_region(struct ncplane *n, int ystart, int xstart, int ylen, int xlen) __attribute__((nonnull(1)))
Definition notcurses.c:2484
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:998
#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:1533
API int ncplane_scrollup(struct ncplane *n, int r) __attribute__((nonnull(1)))
Definition notcurses.c:1795
API int ncplane_resize_placewithin(struct ncplane *n)
Definition notcurses.c:2686
API ALLOC struct ncvisual * ncvisual_from_rgba(const void *rgba, int rows, int rowstride, int cols) __attribute__((nonnull(1)))
Definition visual.c:779
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:707
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:1505
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:1245
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:3040
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:3834
API int notcurses_mice_enable(struct notcurses *n, unsigned eventmask) __attribute__((nonnull(1)))
Definition notcurses.c:2561
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:3096
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:3506
API const char * notcurses_str_scalemode(ncscale_e scalemode)
Definition notcurses.c:3057
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:1836
API struct ncplane * ncplane_parent(struct ncplane *n) __attribute__((nonnull(1)))
Definition notcurses.c:2656
API int notcurses_linesigs_enable(struct notcurses *n) __attribute__((nonnull(1)))
Definition in.c:2917
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:3832
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:2549
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:1497
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:1525
API bool ncplane_set_scrolling(struct ncplane *n, unsigned scrollp) __attribute__((nonnull(1)))
Definition notcurses.c:2998
API struct ncplane * ncplane_below(struct ncplane *n) __attribute__((nonnull(1)))
Definition notcurses.c:2553
API struct ncplane * ncplane_above(struct ncplane *n) __attribute__((nonnull(1)))
Definition notcurses.c:2557
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:1513
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:718
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:1561
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:2758
#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:3008
API ALLOC struct ncvisual * ncvisual_from_bgra(const void *bgra, int rows, int rowstride, int cols) __attribute__((nonnull(1)))
Definition visual.c:895
int(* ncfdplane_done_cb)(struct ncfdplane *n, int fderrno, void *curry)
Definition notcurses.h:4551
API ALLOC char * notcurses_osversion(void)
Definition util.c:95
API int ncplane_cursor_move_rel(struct ncplane *n, int y, int x) __attribute__((nonnull(1)))
Definition notcurses.c:753
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:2568
API int ncplane_family_destroy(struct ncplane *n)
Definition notcurses.c:1071
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:195
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:820
API int nccell_duplicate(struct ncplane *n, nccell *targ, const nccell *c)
Definition render.c:133
struct ncvisual_options v
Definition notcurses.h:3501
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:1521
API int ncplane_resize_marginalized(struct ncplane *n)
Definition notcurses.c:2728
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:3230
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:4550
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:2664
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:2082
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:3072
int(* ncstreamcb)(struct ncvisual *, struct ncvisual_options *, const struct timespec *, void *)
Definition notcurses.h:3537
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:2464
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:185
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:2277
API int API int const nccell unsigned len
Definition notcurses.h:2592
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:2417
API double ncprogbar_progress(const struct ncprogbar *n) __attribute__((nonnull(1)))
API int ncplane_destroy(struct ncplane *n)
Definition notcurses.c:1021
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:1553
API void * ncplane_set_userptr(struct ncplane *n, void *opaque) __attribute__((nonnull(1)))
Definition notcurses.c:189
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:2087
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:1549
API int notcurses_linesigs_disable(struct notcurses *n) __attribute__((nonnull(1)))
Definition in.c:2875
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:2769
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:4121
const char * desc
Definition notcurses.h:4120
uint64_t sectionchannels
Definition notcurses.h:4138
uint64_t flags
Definition notcurses.h:4139
struct ncmenu_section * sections
Definition notcurses.h:4135
uint64_t headerchannels
Definition notcurses.h:4137
struct ncmenu_item * items
Definition notcurses.h:4127
ncinput shortcut
Definition notcurses.h:4128
const char * name
Definition notcurses.h:4125
Definition menu.c:25
const char * option
Definition notcurses.h:3972
const char * desc
Definition notcurses.h:3973
const struct ncmselector_item * items
Definition notcurses.h:4002
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:4497
const char * title
Definition notcurses.h:4506
uint64_t maxchannels
Definition notcurses.h:4494
uint64_t flags
Definition notcurses.h:4507
ncblitter_e gridtype
Definition notcurses.h:4500
uint64_t minchannels
Definition notcurses.h:4495
uint64_t tchannels
Definition notcurses.h:4625
uint32_t tattrword
Definition notcurses.h:4626
unsigned bordermask
Definition notcurses.h:3711
uint64_t borderchan
Definition notcurses.h:3712
uint64_t tabletchan
Definition notcurses.h:3714
uint64_t flags
Definition notcurses.h:3716
unsigned tabletmask
Definition notcurses.h:3713
uint64_t focusedchan
Definition notcurses.h:3715
const char * option
Definition notcurses.h:3912
const char * desc
Definition notcurses.h:3913
uint64_t footchannels
Definition notcurses.h:3930
uint64_t descchannels
Definition notcurses.h:3928
uint64_t titlechannels
Definition notcurses.h:3929
const char * title
Definition notcurses.h:3917
const char * secondary
Definition notcurses.h:3918
const struct ncselector_item * items
Definition notcurses.h:3920
const char * footer
Definition notcurses.h:3919
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:4577
char * name
Definition internal.h:234
struct nctabbed * nt
Definition internal.h:232
const char * separator
Definition notcurses.h:4247
unsigned subcount
Definition notcurses.h:4048
void * curry
Definition notcurses.h:4046
struct nctree_item * subs
Definition notcurses.h:4047
int(* nctreecb)(struct ncplane *, void *, int)
Definition notcurses.h:4054
unsigned count
Definition notcurses.h:4053
uint64_t flags
Definition notcurses.h:4056
const struct nctree_item * items
Definition notcurses.h:4052
Definition tree.c:11
unsigned rpixx
Definition notcurses.h:3404
unsigned cdimx
Definition notcurses.h:3403
unsigned scaley
Definition notcurses.h:3406
unsigned lenx
Definition notcurses.h:3408
ncblitter_e blitter
Definition notcurses.h:3410
unsigned pixx
Definition notcurses.h:3402
unsigned pixy
Definition notcurses.h:3402
unsigned rpixy
Definition notcurses.h:3404
unsigned begy
Definition notcurses.h:3407
unsigned maxpixelx
Definition notcurses.h:3409
unsigned maxpixely
Definition notcurses.h:3409
unsigned rcellx
Definition notcurses.h:3405
unsigned begx
Definition notcurses.h:3407
unsigned leny
Definition notcurses.h:3408
unsigned rcelly
Definition notcurses.h:3405
unsigned cdimy
Definition notcurses.h:3403
unsigned scalex
Definition notcurses.h:3406
ncblitter_e blitter
Definition notcurses.h:3374
ncscale_e scaling
Definition notcurses.h:3358
struct ncplane * n
Definition notcurses.h:3354
uint32_t transcolor
Definition notcurses.h:3376
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