Notcurses 3.0.16
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
notcurses.c File Reference
#include "linux.h"
#include "version.h"
#include "egcpool.h"
#include "internal.h"
#include <time.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <limits.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <unistr.h>
#include <locale.h>
#include <uniwbrk.h>
#include <inttypes.h>
#include "compat/compat.h"
#include "unixsig.h"
#include "banner.h"
Include dependency graph for notcurses.c:

Go to the source code of this file.

Macros

#define ESC   "\x1b"
 
#define TABSTOP   8
 
#define PTHREAD_MUTEX_RECURSIVE_NP   PTHREAD_MUTEX_RECURSIVE
 

Functions

void notcurses_version_components (int *major, int *minor, int *patch, int *tweak)
 
int notcurses_enter_alternate_screen (notcurses *nc)
 
int notcurses_leave_alternate_screen (notcurses *nc)
 
int reset_term_attributes (const tinfo *ti, fbuf *f)
 
int reset_term_palette (const tinfo *ti, fbuf *f, unsigned touchedpalette)
 
const char * notcurses_version (void)
 
void * ncplane_set_userptr (ncplane *n, void *opaque)
 
void * ncplane_userptr (ncplane *n)
 
const void * ncplane_userptr_const (const ncplane *n)
 
char * ncplane_at_cursor (const ncplane *n, uint16_t *stylemask, uint64_t *channels)
 
char * ncplane_at_yx (const ncplane *n, int y, int x, uint16_t *stylemask, uint64_t *channels)
 
int ncplane_at_cursor_cell (ncplane *n, nccell *c)
 
int ncplane_at_yx_cell (ncplane *n, int y, int x, nccell *c)
 
void ncplane_dim_yx (const ncplane *n, unsigned *rows, unsigned *cols)
 
int update_term_dimensions (unsigned *rows, unsigned *cols, tinfo *tcache, int margin_b, unsigned *cgeo_changed, unsigned *pgeo_changed)
 
void free_plane (ncplane *p)
 
 __attribute__ ((malloc))
 
ncplanencplane_new_internal (notcurses *nc, ncplane *n, const ncplane_options *nopts)
 
ncplanenotcurses_stdplane (notcurses *nc)
 
const ncplanenotcurses_stdplane_const (const notcurses *nc)
 
ncplanencplane_create (ncplane *n, const ncplane_options *nopts)
 
ncplanencpile_create (notcurses *nc, const struct ncplane_options *nopts)
 
void ncplane_home (ncplane *n)
 
int ncplane_cursor_move_yx (ncplane *n, int y, int x)
 
int ncplane_cursor_move_rel (ncplane *n, int y, int x)
 
ncplanencplane_dup (const ncplane *n, void *opaque)
 
int resize_callbacks_children (ncplane *n)
 
int ncplane_resize_internal (ncplane *n, int keepy, int keepx, unsigned keepleny, unsigned keeplenx, int yoff, int xoff, unsigned ylen, unsigned xlen)
 
int ncplane_resize (ncplane *n, int keepy, int keepx, unsigned keepleny, unsigned keeplenx, int yoff, int xoff, unsigned ylen, unsigned xlen)
 
int ncplane_destroy (ncplane *ncp)
 
int ncplane_family_destroy (ncplane *ncp)
 
void init_lang (void)
 
ncpixelimpl_e notcurses_check_pixel_support (const notcurses *nc)
 
 __attribute__ ((nonnull(2)))
 
notcursesnotcurses_core_init (const notcurses_options *opts, FILE *outfp)
 
void notcurses_drop_planes (notcurses *nc)
 
int notcurses_stop (notcurses *nc)
 
uint64_t ncplane_channels (const ncplane *n)
 
void ncplane_set_channels (ncplane *n, uint64_t channels)
 
uint16_t ncplane_styles (const ncplane *n)
 
void ncplane_set_fg_default (ncplane *n)
 
void ncplane_set_bg_default (ncplane *n)
 
void ncplane_set_bg_rgb8_clipped (ncplane *n, int r, int g, int b)
 
int ncplane_set_bg_rgb8 (ncplane *n, unsigned r, unsigned g, unsigned b)
 
void ncplane_set_fg_rgb8_clipped (ncplane *n, int r, int g, int b)
 
int ncplane_set_fg_rgb8 (ncplane *n, unsigned r, unsigned g, unsigned b)
 
int ncplane_set_fg_rgb (ncplane *n, unsigned channel)
 
uint64_t ncplane_set_bchannel (ncplane *n, uint32_t channel)
 
uint64_t ncplane_set_fchannel (ncplane *n, uint32_t channel)
 
int ncplane_set_bg_rgb (ncplane *n, unsigned channel)
 
int ncplane_set_fg_alpha (ncplane *n, int alpha)
 
int ncplane_set_bg_alpha (ncplane *n, int alpha)
 
int ncplane_set_fg_palindex (ncplane *n, unsigned idx)
 
int ncplane_set_bg_palindex (ncplane *n, unsigned idx)
 
int ncplane_set_base_cell (ncplane *ncp, const nccell *c)
 
int ncplane_set_base (ncplane *ncp, const char *egc, uint16_t stylemask, uint64_t channels)
 
int ncplane_base (ncplane *ncp, nccell *c)
 
const char * nccell_extended_gcluster (const ncplane *n, const nccell *c)
 
int ncplane_move_above (ncplane *restrict n, ncplane *restrict above)
 
int ncplane_move_below (ncplane *restrict n, ncplane *restrict below)
 
int ncplane_move_family_above (ncplane *restrict n, ncplane *restrict bpoint)
 
int ncplane_move_family_below (ncplane *restrict n, ncplane *restrict bpoint)
 
void ncplane_cursor_yx (const ncplane *n, unsigned *y, unsigned *x)
 
void scroll_down (ncplane *n)
 
int ncplane_scrollup (ncplane *n, int r)
 
int ncplane_scrollup_child (ncplane *n, const ncplane *child)
 
int nccell_load (ncplane *n, nccell *c, const char *gcluster)
 
int ncplane_putc_yx (ncplane *n, int y, int x, const nccell *c)
 
int ncplane_putegc_yx (ncplane *n, int y, int x, const char *gclust, size_t *sbytes)
 
int ncplane_putchar_stained (ncplane *n, char c)
 
int ncplane_putwegc_stained (ncplane *n, const wchar_t *gclust, size_t *sbytes)
 
int ncplane_putegc_stained (ncplane *n, const char *gclust, size_t *sbytes)
 
int ncplane_cursor_at (const ncplane *n, nccell *c, char **gclust)
 
uint16_t notcurses_supported_styles (const notcurses *nc)
 
unsigned notcurses_palette_size (const notcurses *nc)
 
char * notcurses_detected_terminal (const notcurses *nc)
 
void ncplane_set_styles (ncplane *n, unsigned stylebits)
 
void ncplane_on_styles (ncplane *n, unsigned stylebits)
 
void ncplane_off_styles (ncplane *n, unsigned stylebits)
 
char * ncplane_vprintf_prep (const char *format, va_list ap)
 
int ncplane_vprintf_yx (ncplane *n, int y, int x, const char *format, va_list ap)
 
int ncplane_vprintf_aligned (ncplane *n, int y, ncalign_e align, const char *format, va_list ap)
 
int ncplane_vprintf_stained (struct ncplane *n, const char *format, va_list ap)
 
int ncplane_putnstr_aligned (struct ncplane *n, int y, ncalign_e align, size_t s, const char *str)
 
int ncplane_hline_interp (ncplane *n, const nccell *c, unsigned len, uint64_t c1, uint64_t c2)
 
int ncplane_vline_interp (ncplane *n, const nccell *c, unsigned len, uint64_t c1, uint64_t c2)
 
int ncplane_box (ncplane *n, const nccell *ul, const nccell *ur, const nccell *ll, const nccell *lr, const nccell *hl, const nccell *vl, unsigned ystop, unsigned xstop, unsigned ctlword)
 
int ncplane_move_yx (ncplane *n, int y, int x)
 
int ncplane_y (const ncplane *n)
 
int ncplane_x (const ncplane *n)
 
void ncplane_yx (const ncplane *n, int *y, int *x)
 
void ncplane_erase (ncplane *n)
 
int ncplane_erase_region (ncplane *n, int ystart, int xstart, int ylen, int xlen)
 
ncplanencpile_top (ncplane *n)
 
ncplanencpile_bottom (ncplane *n)
 
ncplanencplane_below (ncplane *n)
 
ncplanencplane_above (ncplane *n)
 
int notcurses_mice_enable (notcurses *n, unsigned eventmask)
 
ncpalettencpalette_new (notcurses *nc)
 
int ncpalette_use (notcurses *nc, const ncpalette *p)
 
void ncpalette_free (ncpalette *p)
 
bool ncplane_translate_abs (const ncplane *n, int *restrict y, int *restrict x)
 
void ncplane_translate (const ncplane *src, const ncplane *dst, int *restrict y, int *restrict x)
 
notcursesncplane_notcurses (const ncplane *n)
 
const notcursesncplane_notcurses_const (const ncplane *n)
 
int ncplane_abs_y (const ncplane *n)
 
int ncplane_abs_x (const ncplane *n)
 
void ncplane_abs_yx (const ncplane *n, int *RESTRICT y, int *RESTRICT x)
 
ncplanencplane_parent (ncplane *n)
 
const ncplanencplane_parent_const (const ncplane *n)
 
int ncplane_set_name (ncplane *n, const char *name)
 
char * ncplane_name (const ncplane *n)
 
void ncplane_set_resizecb (ncplane *n, int(*resizecb)(ncplane *))
 
int ncplane_resize_placewithin (ncplane *n)
 
int ncplane_resize_marginalized (ncplane *n)
 
int ncplane_resize_maximize (ncplane *n)
 
int ncplane_resize_realign (ncplane *n)
 
ncplanencplane_reparent (ncplane *n, ncplane *newparent)
 
ncplanencplane_reparent_family (ncplane *n, ncplane *newparent)
 
bool ncplane_set_scrolling (ncplane *n, unsigned scrollp)
 
bool ncplane_scrolling_p (const ncplane *n)
 
bool ncplane_set_autogrow (ncplane *n, unsigned growp)
 
bool ncplane_autogrow_p (const ncplane *n)
 
int notcurses_lex_scalemode (const char *op, ncscale_e *scalemode)
 
const char * notcurses_str_scalemode (ncscale_e scalemode)
 
int notcurses_lex_margins (const char *op, notcurses_options *opts)
 
int notcurses_inputready_fd (notcurses *n)
 
int ncdirect_inputready_fd (ncdirect *n)
 
uint32_t * ncplane_as_rgba (const ncplane *nc, ncblitter_e blit, int begy, int begx, unsigned leny, unsigned lenx, unsigned *pxdimy, unsigned *pxdimx)
 
char * ncplane_contents (ncplane *nc, int begy, int begx, unsigned leny, unsigned lenx)
 
void ncplane_center_abs (const ncplane *n, int *RESTRICT y, int *RESTRICT x)
 
int ncplane_putwstr_stained (ncplane *n, const wchar_t *gclustarr)
 
int notcurses_ucs32_to_utf8 (const uint32_t *ucs32, unsigned ucs32count, unsigned char *resultbuf, size_t buflen)
 
int ncstrwidth (const char *egcs, int *validbytes, int *validwidth)
 
void ncplane_pixel_geom (const ncplane *n, unsigned *RESTRICT pxy, unsigned *RESTRICT pxx, unsigned *RESTRICT celldimy, unsigned *RESTRICT celldimx, unsigned *RESTRICT maxbmapy, unsigned *RESTRICT maxbmapx)
 
const nccapabilitiesnotcurses_capabilities (const notcurses *n)
 

Variables

int(*)(ncplane *) ncplane_resizecb (const ncplane *n)
 

Macro Definition Documentation

◆ ESC

#define ESC   "\x1b"

Definition at line 21 of file notcurses.c.

◆ PTHREAD_MUTEX_RECURSIVE_NP

#define PTHREAD_MUTEX_RECURSIVE_NP   PTHREAD_MUTEX_RECURSIVE

◆ TABSTOP

#define TABSTOP   8

Definition at line 22 of file notcurses.c.

Function Documentation

◆ __attribute__() [1/2]

__attribute__ ( (malloc)  )

Definition at line 504 of file notcurses.c.

506 {
507 ncpile* ret = malloc(sizeof(*ret));
508 if(ret){
509 ret->nc = nc;
510 ret->top = n;
511 ret->bottom = n;
512 ret->roots = n;
513 n->bprev = &ret->roots;
514 if(nc->stdplane){ // stdplane (and thus stdpile) has already been created
515 ret->prev = ncplane_pile(nc->stdplane)->prev;
516 ncplane_pile(nc->stdplane)->prev->next = ret;
517 ret->next = ncplane_pile(nc->stdplane);
518 ncplane_pile(nc->stdplane)->prev = ret;
519 }else{
520 ret->prev = ret;
521 ret->next = ret;
522 }
523 n->above = NULL;
524 n->below = NULL;
525 ret->dimy = nc->tcache.dimy;
526 ret->dimx = nc->tcache.dimx;
527 ret->cellpxy = nc->tcache.cellpxy;
528 ret->cellpxx = nc->tcache.cellpxx;
529 ret->crender = NULL;
530 ret->crenderlen = 0;
531 ret->sprixelcache = NULL;
532 ret->scrolls = 0;
533 }
534 n->pile = ret;
535 return ret;
536}
vopts n
Definition notcurses.h:3506
unsigned cellpxx
Definition internal.h:326
struct ncpile * next
Definition internal.h:323
ncplane * bottom
Definition internal.h:319
sprixel * sprixelcache
Definition internal.h:328
unsigned dimx
Definition internal.h:325
struct ncpile * prev
Definition internal.h:323
size_t crenderlen
Definition internal.h:324
struct notcurses * nc
Definition internal.h:322
ncplane * roots
Definition internal.h:320
unsigned dimy
Definition internal.h:325
struct crender * crender
Definition internal.h:321
int scrolls
Definition internal.h:327
unsigned cellpxy
Definition internal.h:326
ncplane * top
Definition internal.h:318
struct ncplane ** bprev
Definition internal.h:101
return NULL
Definition termdesc.h:229

◆ __attribute__() [2/2]

__attribute__ ( (nonnull(2))  )

Definition at line 1172 of file notcurses.c.

1173 {
1174 if(fwide(fp, 0) > 0){
1175 fprintf(stderr, "error: output stream is wide-oriented");
1176 return NULL;
1177 }
1178 notcurses* ret = malloc(sizeof(*ret));
1179 if(ret == NULL){
1180 return ret;
1181 }
1182 memset(ret, 0, sizeof(*ret));
1183 if(opts){
1184 if(opts->flags >= (NCOPTION_SCROLLING << 1u)){
1185 fprintf(stderr, "warning: unknown Notcurses options %016" PRIu64, opts->flags);
1186 }
1187 if(opts->termtype){
1188 if(putenv_term(opts->termtype)){
1189 free(ret);
1190 return NULL;
1191 }
1192 }
1193 ret->flags = opts->flags;
1194 ret->margin_t = opts->margin_t;
1195 ret->margin_b = opts->margin_b;
1196 ret->margin_l = opts->margin_l;
1197 ret->margin_r = opts->margin_r;
1198 ret->loglevel = opts->loglevel;
1199 }
1201 if(!(ret->flags & NCOPTION_INHIBIT_SETLOCALE)){
1202 init_lang();
1203 }
1204//fprintf(stderr, "getenv LC_ALL: %s LC_CTYPE: %s\n", getenv("LC_ALL"), getenv("LC_CTYPE"));
1205 const char* encoding = nl_langinfo(CODESET);
1206 if(encoding && encoding_is_utf8(encoding)){
1207 *utf8 = true;
1208 }else{
1209 *utf8 = false;
1210 if(encoding && (strcmp(encoding, "ANSI_X3.4-1968") &&
1211 strcmp(encoding, "US-ASCII") &&
1212 strcmp(encoding, "ASCII"))){
1213 fprintf(stderr, "encoding (\"%s\") was neither ANSI_X3.4-1968 nor UTF-8, refusing to start\n did you call setlocale()?\n",
1214 encoding ? encoding : "none found");
1215 free(ret);
1216 return NULL;
1217 }
1218 }
1219 ret->cursory = ret->cursorx = -1;
1220 reset_stats(&ret->stats.s);
1222 ret->ttyfp = fp;
1223 egcpool_init(&ret->pool);
1225 fprintf(stderr, "invalid loglevel %d", ret->loglevel);
1226 free(ret);
1227 return NULL;
1228 }
1229 if(recursive_lock_init(&ret->pilelock)){
1230 fprintf(stderr, "couldn't initialize pile mutex");
1231 free(ret);
1232 return NULL;
1233 }
1234 if(pthread_mutex_init(&ret->stats.lock, NULL)){
1235 pthread_mutex_destroy(&ret->pilelock);
1236 free(ret);
1237 return NULL;
1238 }
1239 if(*utf8){
1241 }
1242 return ret;
1243}
int putenv_term(const char *termname) __attribute__((nonnull(1)))
Definition termdesc.c:1655
void reset_stats(ncstats *stats)
Definition stats.c:74
int set_loglevel_from_env(ncloglevel_e *loglevel) __attribute__((nonnull(1)))
Definition util.c:19
void ncmetric_use_utf8(void)
Definition metric.c:24
void init_lang(void)
Definition notcurses.c:1097
#define NCOPTION_INHIBIT_SETLOCALE
Definition notcurses.h:990
const struct ncplane_options * opts
Definition notcurses.h:3487
#define NCOPTION_SCROLLING
Definition notcurses.h:1034
@ NCLOGLEVEL_SILENT
Definition notcurses.h:969
@ NCLOGLEVEL_TRACE
Definition notcurses.h:977
unsigned margin_r
Definition notcurses.h:1473
unsigned margin_b
Definition notcurses.h:1473
ncstats s
Definition internal.h:247
pthread_mutex_t lock
Definition internal.h:246
ncstats stashed_stats
Definition internal.h:357
pthread_mutex_t pilelock
Definition internal.h:361
int cursorx
Definition internal.h:354
uint64_t flags
Definition internal.h:369
int margin_l
Definition internal.h:364
ncsharedstats stats
Definition internal.h:356
int cursory
Definition internal.h:353
FILE * ttyfp
Definition internal.h:359
int margin_t
Definition internal.h:364
int margin_b
Definition internal.h:364
egcpool pool
Definition internal.h:348
int margin_r
Definition internal.h:364
int loglevel
Definition internal.h:365
Here is the call graph for this function:

◆ free_plane()

void free_plane ( ncplane p)

Definition at line 467 of file notcurses.c.

467 {
468 if(p){
469 // ncdirect fakes an ncplane with no ->pile
470 if(ncplane_pile(p)){
472 pthread_mutex_lock(&nc->stats.lock);
474 ncplane_notcurses(p)->stats.s.fbbytes -= sizeof(*p->fb) * p->leny * p->lenx;
475 pthread_mutex_unlock(&nc->stats.lock);
476 if(p->above == NULL && p->below == NULL){
477 pthread_mutex_lock(&nc->pilelock);
478 ncpile_destroy(ncplane_pile(p));
479 pthread_mutex_unlock(&nc->pilelock);
480 }
481 }
482 if(p->widget){
483 void* w = p->widget;
484 void (*wdestruct)(void*) = p->wdestruct;
485 p->widget = NULL;
486 p->wdestruct = NULL;
487 logdebug("calling widget destructor %p(%p)", wdestruct, w);
488 wdestruct(w);
489 logdebug("got the widget");
490 }
491 if(p->sprite){
493 }
494 destroy_tam(p);
495 egcpool_dump(&p->pool);
496 free(p->name);
497 free(p->fb);
498 free(p);
499 }
500}
void sprixel_hide(sprixel *s)
Definition sprite.c:83
#define logdebug(fmt,...)
Definition logging.h:52
notcurses * ncplane_notcurses(const ncplane *n)
Definition notcurses.c:2631
struct ncplane * below
Definition internal.h:94
sprixel * sprite
Definition internal.h:105
unsigned lenx
Definition internal.h:86
struct ncplane * above
Definition internal.h:93
char * name
Definition internal.h:111
void(* wdestruct)(void *)
Definition internal.h:124
unsigned leny
Definition internal.h:86
void * widget
Definition internal.h:123
egcpool pool
Definition internal.h:87
nccell * fb
Definition internal.h:77
unsigned planes
Definition notcurses.h:1820
uint64_t fbbytes
Definition notcurses.h:1819
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_lang()

void init_lang ( void  )

Definition at line 1097 of file notcurses.c.

1097 {
1098#ifdef __MINGW32__
1099 if(setlocale(LC_ALL, ".UTF8") == NULL){
1100 logwarn("couldn't set LC_ALL to utf8");
1101 }
1102#endif
1103 const char* encoding = nl_langinfo(CODESET);
1104 if(encoding && encoding_is_utf8(encoding)){
1105 return; // already utf-8, great!
1106 }
1107 const char* lang = getenv("LANG");
1108 // if LANG was explicitly set to C/POSIX, life sucks, roll with it
1109 if(lang && (!strcmp(lang, "C") || !strcmp(lang, "POSIX"))){
1110 loginfo("LANG was explicitly set to %s, not changing locale", lang);
1111 return;
1112 }
1113#ifndef __MINGW32__
1114 if(setlocale(LC_ALL, "") == NULL){
1115 logwarn("setting locale based on LANG failed");
1116 }
1117#endif
1118 encoding = nl_langinfo(CODESET);
1119 if(encoding && encoding_is_utf8(encoding)){
1120 loginfo("set locale from LANG; client should call setlocale(2)!");
1121 return;
1122 }
1123 setlocale(LC_CTYPE, "C.UTF-8");
1124 encoding = nl_langinfo(CODESET);
1125 if(encoding && encoding_is_utf8(encoding)){
1126 loginfo("forced UTF-8 encoding; client should call setlocale(2)!");
1127 return;
1128 }
1129}
#define loginfo(fmt,...)
Definition logging.h:42
#define logwarn(fmt,...)
Definition logging.h:37
Here is the caller graph for this function:

◆ nccell_extended_gcluster()

const char * nccell_extended_gcluster ( const ncplane n,
const nccell c 
)

Definition at line 1576 of file notcurses.c.

1576 {
1577 if(cell_simple_p(c)){
1578 return (const char*)&c->gcluster;
1579 }
1580 return egcpool_extended_gcluster(&n->pool, c);
1581}
const nccell * c
Definition egcpool.h:207
uint32_t gcluster
Definition notcurses.h:693
Here is the caller graph for this function:

◆ nccell_load()

int nccell_load ( ncplane n,
nccell c,
const char *  gcluster 
)

Definition at line 1836 of file notcurses.c.

1836 {
1837 int cols;
1838 int bytes = utf8_egc_len(gcluster, &cols);
1839 return pool_load_direct(&n->pool, c, gcluster, bytes, cols);
1840}
Here is the caller graph for this function:

◆ ncdirect_inputready_fd()

int ncdirect_inputready_fd ( ncdirect n)

Definition at line 3100 of file notcurses.c.

3100 {
3101 return inputready_fd(n->tcache.ictx);
3102}
int inputready_fd(const inputctx *ictx)
Definition in.c:2672
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncpalette_free()

void ncpalette_free ( ncpalette p)

Definition at line 2591 of file notcurses.c.

2591 {
2592 free(p);
2593}
Here is the caller graph for this function:

◆ ncpalette_new()

ncpalette * ncpalette_new ( notcurses nc)

Definition at line 2568 of file notcurses.c.

2568 {
2569 ncpalette* p = malloc(sizeof(*p));
2570 if(p){
2571 memcpy(p, &nc->palette, sizeof(*p));
2572 }
2573 return p;
2574}
ncpalette palette
Definition internal.h:366
Here is the caller graph for this function:

◆ ncpalette_use()

int ncpalette_use ( notcurses nc,
const ncpalette p 
)

Definition at line 2576 of file notcurses.c.

2576 {
2577 int ret = -1;
2578 if(!notcurses_canchangecolor(nc)){
2579 return -1;
2580 }
2581 for(size_t z = 0 ; z < sizeof(p->chans) / sizeof(*p->chans) ; ++z){
2582 if(nc->palette.chans[z] != p->chans[z]){
2583 nc->palette.chans[z] = p->chans[z];
2584 nc->palette_damage[z] = true;
2585 }
2586 }
2587 ret = 0;
2588 return ret;
2589}
uint32_t chans[NCPALETTESIZE]
Definition notcurses.h:1585
bool palette_damage[NCPALETTESIZE]
Definition internal.h:367
Here is the caller graph for this function:

◆ ncpile_bottom()

ncplane * ncpile_bottom ( ncplane n)

Definition at line 2549 of file notcurses.c.

2549 {
2550 return ncplane_pile(n)->bottom;
2551}
Here is the caller graph for this function:

◆ ncpile_create()

ncplane * ncpile_create ( notcurses nc,
const struct ncplane_options nopts 
)

Definition at line 714 of file notcurses.c.

714 {
715 return ncplane_new_internal(nc, NULL, nopts);
716}
ncplane * ncplane_new_internal(notcurses *nc, ncplane *n, const ncplane_options *nopts)
Definition notcurses.c:560
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncpile_top()

ncplane * ncpile_top ( ncplane n)

Definition at line 2545 of file notcurses.c.

2545 {
2546 return ncplane_pile(n)->top;
2547}
Here is the caller graph for this function:

◆ ncplane_above()

ncplane * ncplane_above ( ncplane n)

Definition at line 2557 of file notcurses.c.

2557 {
2558 return n->above;
2559}
Here is the caller graph for this function:

◆ ncplane_abs_x()

int ncplane_abs_x ( const ncplane n)

Definition at line 2643 of file notcurses.c.

2643 {
2644 return n->absx;
2645}
Here is the caller graph for this function:

◆ ncplane_abs_y()

int ncplane_abs_y ( const ncplane n)

Definition at line 2639 of file notcurses.c.

2639 {
2640 return n->absy;
2641}
Here is the caller graph for this function:

◆ ncplane_abs_yx()

void ncplane_abs_yx ( const ncplane n,
int *RESTRICT  y,
int *RESTRICT  x 
)

Definition at line 2647 of file notcurses.c.

2647 {
2648 if(y){
2649 *y = ncplane_abs_y(n);
2650 }
2651 if(x){
2652 *x = ncplane_abs_x(n);
2653 }
2654}
int ncplane_abs_x(const ncplane *n)
Definition notcurses.c:2643
int ncplane_abs_y(const ncplane *n)
Definition notcurses.c:2639
int y
Definition notcurses.h:1905
int int x
Definition notcurses.h:1905
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_as_rgba()

uint32_t * ncplane_as_rgba ( const ncplane nc,
ncblitter_e  blit,
int  begy,
int  begx,
unsigned  leny,
unsigned  lenx,
unsigned *  pxdimy,
unsigned *  pxdimx 
)

Definition at line 3216 of file notcurses.c.

3218 {
3219 unsigned px, py;
3220 if(!pxdimy){
3221 pxdimy = &py;
3222 }
3223 if(!pxdimx){
3224 pxdimx = &px;
3225 }
3226 return ncplane_as_rgba_internal(nc, blit, begy, begx, leny, lenx, pxdimy, pxdimx);
3227}
Here is the caller graph for this function:

◆ ncplane_at_cursor()

char * ncplane_at_cursor ( const ncplane n,
uint16_t *  stylemask,
uint64_t *  channels 
)

Definition at line 213 of file notcurses.c.

213 {
214 return ncplane_at_yx(n, n->y, n->x, stylemask, channels);
215}
char * ncplane_at_yx(const ncplane *n, int y, int x, uint16_t *stylemask, uint64_t *channels)
Definition notcurses.c:217
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_at_cursor_cell()

int ncplane_at_cursor_cell ( ncplane n,
nccell c 
)

Definition at line 269 of file notcurses.c.

269 {
270 return ncplane_at_yx_cell(n, n->y, n->x, c);
271}
int ncplane_at_yx_cell(ncplane *n, int y, int x, nccell *c)
Definition notcurses.c:273
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_at_yx()

char * ncplane_at_yx ( const ncplane n,
int  y,
int  x,
uint16_t *  stylemask,
uint64_t *  channels 
)

Definition at line 217 of file notcurses.c.

217 {
218 if(y < 0){
219 if(y != -1){
220 logerror("invalid y: %d", y);
221 return NULL;
222 }
223 y = n->y;
224 }
225 if(x < 0){
226 if(x != -1){
227 logerror("invalid x: %d", x);
228 return NULL;
229 }
230 x = n->x;
231 }
232 if((unsigned)y >= n->leny || (unsigned)x >= n->lenx){
233 logerror("invalid coordinates: %d/%d", y, x);
234 return NULL;
235 }
236 if(n->sprite){
237 if(stylemask){
238 *stylemask = 0;
239 }
240 if(channels){
241 *channels = 0;
242 }
243 return strdup(n->sprite->glyph.buf);
244 }
245 const nccell* yx = &n->fb[nfbcellidx(n, y, x)];
246 // if we're the right side of a wide glyph, we return the main glyph
247 if(nccell_wide_right_p(yx)){
248 return ncplane_at_yx(n, y, x - 1, stylemask, channels);
249 }
250 char* ret = nccell_extract(n, yx, stylemask, channels);
251 if(ret == NULL){
252 return NULL;
253 }
254//fprintf(stderr, "GOT [%s]\n", ret);
255 if(strcmp(ret, "") == 0){
256 free(ret);
257 ret = nccell_strdup(n, &n->basecell);
258 if(ret == NULL){
259 return NULL;
260 }
261 if(stylemask){
262 *stylemask = n->basecell.stylemask;
263 }
264 }
265 // FIXME load basecell channels if appropriate
266 return ret;
267}
#define logerror(fmt,...)
Definition logging.h:32
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_at_yx_cell()

int ncplane_at_yx_cell ( ncplane n,
int  y,
int  x,
nccell c 
)

Definition at line 273 of file notcurses.c.

273 {
274 if(n->sprite){
275 logerror("invoked on a sprixel plane");
276 return -1;
277 }
278 if(y < 0){
279 if(y != -1){
280 logerror("invalid y: %d", y);
281 return -1;
282 }
283 y = n->y;
284 }
285 if(x < 0){
286 if(x != -1){
287 logerror("invalid x: %d", x);
288 return -1;
289 }
290 x = n->x;
291 }
292 if((unsigned)y >= n->leny || (unsigned)x >= n->lenx){
293 logerror("invalid coordinates: %d/%d", y, x);
294 return -1;
295 }
296 nccell* targ = ncplane_cell_ref_yx(n, y, x);
297 if(nccell_duplicate(n, c, targ)){
298 return -1;
299 }
300 // FIXME take base cell into account where necessary!
301 return strlen(nccell_extended_gcluster(n, targ));
302}
const char * nccell_extended_gcluster(const ncplane *n, const nccell *c)
Definition notcurses.c:1576
int nccell_duplicate(ncplane *n, nccell *targ, const nccell *c)
Definition render.c:133
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_autogrow_p()

bool ncplane_autogrow_p ( const ncplane n)

Definition at line 3018 of file notcurses.c.

3018 {
3019 return n->autogrow;
3020}

◆ ncplane_base()

int ncplane_base ( ncplane ncp,
nccell c 
)

Definition at line 1572 of file notcurses.c.

1572 {
1573 return nccell_duplicate(ncp, c, &ncp->basecell);
1574}
nccell basecell
Definition internal.h:110
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_below()

ncplane * ncplane_below ( ncplane n)

Definition at line 2553 of file notcurses.c.

2553 {
2554 return n->below;
2555}
Here is the caller graph for this function:

◆ ncplane_box()

int ncplane_box ( ncplane n,
const nccell ul,
const nccell ur,
const nccell ll,
const nccell lr,
const nccell hl,
const nccell vl,
unsigned  ystop,
unsigned  xstop,
unsigned  ctlword 
)

Definition at line 2277 of file notcurses.c.

2280 {
2281 unsigned yoff, xoff;
2282 ncplane_cursor_yx(n, &yoff, &xoff);
2283 // must be at least 2x2, with its upper-left corner at the current cursor
2284 if(ystop < yoff + 1){
2285 logerror("ystop (%u) insufficient for yoff (%d)", ystop, yoff);
2286 return -1;
2287 }
2288 if(xstop < xoff + 1){
2289 logerror("xstop (%u) insufficient for xoff (%d)", xstop, xoff);
2290 return -1;
2291 }
2292 unsigned ymax, xmax;
2293 ncplane_dim_yx(n, &ymax, &xmax);
2294 // must be within the ncplane
2295 if(xstop >= xmax || ystop >= ymax){
2296 logerror("boundary (%ux%u) beyond plane (%dx%d)", ystop, xstop, ymax, xmax);
2297 return -1;
2298 }
2299 unsigned edges;
2300 edges = !(ctlword & NCBOXMASK_TOP) + !(ctlword & NCBOXMASK_LEFT);
2301 if(edges >= box_corner_needs(ctlword)){
2302 if(ncplane_putc(n, ul) < 0){
2303 return -1;
2304 }
2305 }
2306 if(!(ctlword & NCBOXMASK_TOP)){ // draw top border, if called for
2307 if(xstop - xoff >= 2){
2308 if(ncplane_cursor_move_yx(n, yoff, xoff + 1)){
2309 return -1;
2310 }
2311 if(!(ctlword & NCBOXGRAD_TOP)){ // cell styling, hl
2312 if(ncplane_hline(n, hl, xstop - xoff - 1) < 0){
2313 return -1;
2314 }
2315 }else{ // gradient, ul -> ur
2316 if(ncplane_hline_interp(n, hl, xstop - xoff - 1, ul->channels, ur->channels) < 0){
2317 return -1;
2318 }
2319 }
2320 }
2321 }
2322 edges = !(ctlword & NCBOXMASK_TOP) + !(ctlword & NCBOXMASK_RIGHT);
2323 if(edges >= box_corner_needs(ctlword)){
2324 if(ncplane_cursor_move_yx(n, yoff, xstop)){
2325 return -1;
2326 }
2327 if(ncplane_putc(n, ur) < 0){
2328 return -1;
2329 }
2330 }
2331 ++yoff;
2332 // middle rows (vertical lines)
2333 if(yoff < ystop){
2334 if(!(ctlword & NCBOXMASK_LEFT)){
2335 if(ncplane_cursor_move_yx(n, yoff, xoff)){
2336 return -1;
2337 }
2338 if((ctlword & NCBOXGRAD_LEFT)){ // grad styling, ul->ll
2339 if(ncplane_vline_interp(n, vl, ystop - yoff, ul->channels, ll->channels) < 0){
2340 return -1;
2341 }
2342 }else{
2343 if(ncplane_vline(n, vl, ystop - yoff) < 0){
2344 return -1;
2345 }
2346 }
2347 }
2348 if(!(ctlword & NCBOXMASK_RIGHT)){
2349 if(ncplane_cursor_move_yx(n, yoff, xstop)){
2350 return -1;
2351 }
2352 if((ctlword & NCBOXGRAD_RIGHT)){ // grad styling, ur->lr
2353 if(ncplane_vline_interp(n, vl, ystop - yoff, ur->channels, lr->channels) < 0){
2354 return -1;
2355 }
2356 }else{
2357 if(ncplane_vline(n, vl, ystop - yoff) < 0){
2358 return -1;
2359 }
2360 }
2361 }
2362 }
2363 // bottom line
2364 yoff = ystop;
2365 edges = !(ctlword & NCBOXMASK_BOTTOM) + !(ctlword & NCBOXMASK_LEFT);
2366 if(edges >= box_corner_needs(ctlword)){
2367 if(ncplane_cursor_move_yx(n, yoff, xoff)){
2368 return -1;
2369 }
2370 if(ncplane_putc(n, ll) < 0){
2371 return -1;
2372 }
2373 }
2374 if(!(ctlword & NCBOXMASK_BOTTOM)){
2375 if(xstop - xoff >= 2){
2376 if(ncplane_cursor_move_yx(n, yoff, xoff + 1)){
2377 return -1;
2378 }
2379 if(!(ctlword & NCBOXGRAD_BOTTOM)){ // cell styling, hl
2380 if(ncplane_hline(n, hl, xstop - xoff - 1) < 0){
2381 return -1;
2382 }
2383 }else{
2384 if(ncplane_hline_interp(n, hl, xstop - xoff - 1, ll->channels, lr->channels) < 0){
2385 return -1;
2386 }
2387 }
2388 }
2389 }
2390 edges = !(ctlword & NCBOXMASK_BOTTOM) + !(ctlword & NCBOXMASK_RIGHT);
2391 if(edges >= box_corner_needs(ctlword)){
2392 if(ncplane_cursor_move_yx(n, yoff, xstop)){
2393 return -1;
2394 }
2395 if(ncplane_putc(n, lr) < 0){
2396 return -1;
2397 }
2398 }
2399 return 0;
2400}
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 ul
Definition direct.h:215
API int API int API int uint64_t uint64_t ur
Definition direct.h:215
int ncplane_cursor_move_yx(ncplane *n, int y, int x)
Definition notcurses.c:723
void ncplane_cursor_yx(const ncplane *n, unsigned *y, unsigned *x)
Definition notcurses.c:1744
int ncplane_hline_interp(ncplane *n, const nccell *c, unsigned len, uint64_t c1, uint64_t c2)
Definition notcurses.c:2159
int ncplane_vline_interp(ncplane *n, const nccell *c, unsigned len, uint64_t c1, uint64_t c2)
Definition notcurses.c:2215
void ncplane_dim_yx(const ncplane *n, unsigned *rows, unsigned *cols)
Definition notcurses.c:304
#define NCBOXMASK_TOP
Definition notcurses.h:2605
#define NCBOXGRAD_RIGHT
Definition notcurses.h:2610
#define NCBOXMASK_LEFT
Definition notcurses.h:2608
#define NCBOXGRAD_BOTTOM
Definition notcurses.h:2611
#define NCBOXGRAD_LEFT
Definition notcurses.h:2612
#define NCBOXMASK_BOTTOM
Definition notcurses.h:2607
#define NCBOXMASK_RIGHT
Definition notcurses.h:2606
#define NCBOXGRAD_TOP
Definition notcurses.h:2609
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_center_abs()

void ncplane_center_abs ( const ncplane n,
int *RESTRICT  y,
int *RESTRICT  x 
)

Definition at line 3270 of file notcurses.c.

3270 {
3271 ncplane_center(n, y, x);
3272 if(y){
3273 *y += n->absy;
3274 }
3275 if(x){
3276 *x += n->absx;
3277 }
3278}
Here is the caller graph for this function:

◆ ncplane_channels()

uint64_t ncplane_channels ( const ncplane n)

Definition at line 1493 of file notcurses.c.

1493 {
1494 return ncchannels_channels(n->channels);
1495}
Here is the caller graph for this function:

◆ ncplane_contents()

char * ncplane_contents ( ncplane nc,
int  begy,
int  begx,
unsigned  leny,
unsigned  lenx 
)

Definition at line 3230 of file notcurses.c.

3230 {
3231 unsigned ystart, xstart;
3232 if(check_geometry_args(nc, begy, begx, &leny, &lenx, &ystart, &xstart)){
3233 return NULL;
3234 }
3235 size_t retlen = 1;
3236 char* ret = malloc(retlen);
3237 if(ret){
3238 for(unsigned y = ystart, targy = 0 ; y < ystart + leny ; ++y, targy += 2){
3239 for(unsigned x = xstart, targx = 0 ; x < xstart + lenx ; ++x, ++targx){
3241 // we need ncplane_at_yx_cell() here instead of ncplane_at_yx(),
3242 // because we should only have one copy of each wide EGC.
3243 int clen;
3244 if((clen = ncplane_at_yx_cell(nc, y, x, &ncl)) < 0){
3245 free(ret);
3246 return NULL;
3247 }
3248 const char* c = nccell_extended_gcluster(nc, &ncl);
3249 if(clen){
3250 char* tmp = realloc(ret, retlen + clen);
3251 if(!tmp){
3252 free(ret);
3253 return NULL;
3254 }
3255 ret = tmp;
3256 memcpy(ret + retlen - 1, c, clen);
3257 retlen += clen;
3258 }
3259 }
3260 }
3261 ret[retlen - 1] = '\0';
3262 }
3263 return ret;
3264}
#define NCCELL_TRIVIAL_INITIALIZER
Definition notcurses.h:737
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_create()

ncplane * ncplane_create ( ncplane n,
const ncplane_options nopts 
)

Definition at line 710 of file notcurses.c.

710 {
711 return ncplane_new_internal(ncplane_notcurses(n), n, nopts);
712}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_cursor_at()

int ncplane_cursor_at ( const ncplane n,
nccell c,
char **  gclust 
)

Definition at line 2050 of file notcurses.c.

2050 {
2051 if(n->y >= n->leny || n->x >= n->lenx){
2052 return -1;
2053 }
2054 const nccell* src = &n->fb[nfbcellidx(n, n->y, n->x)];
2055 memcpy(c, src, sizeof(*src));
2056 if(cell_simple_p(c)){
2057 *gclust = NULL;
2058 }else if((*gclust = strdup(nccell_extended_gcluster(n, src))) == NULL){
2059 return -1;
2060 }
2061 return 0;
2062}
Here is the call graph for this function:

◆ ncplane_cursor_move_rel()

int ncplane_cursor_move_rel ( ncplane n,
int  y,
int  x 
)

Definition at line 753 of file notcurses.c.

753 {
754 if((int)n->y + y == -1){
755 logerror("invalid target y -1");
756 return -1;
757 }else if((int)n->x + x == -1){
758 logerror("invalid target x -1");
759 return -1;
760 }else return ncplane_cursor_move_yx(n, n->y + y, n->x + x);
761}
Here is the call graph for this function:

◆ ncplane_cursor_move_yx()

int ncplane_cursor_move_yx ( ncplane n,
int  y,
int  x 
)

Definition at line 723 of file notcurses.c.

723 {
724 if(x < 0){
725 if(x < -1){
726 logerror("negative target x %d", x);
727 return -1;
728 }
729 }else if((unsigned)x >= n->lenx){
730 logerror("target x %d >= width %u", x, n->lenx);
731 return -1;
732 }else{
733 n->x = x;
734 }
735 if(y < 0){
736 if(y < -1){
737 logerror("negative target y %d", y);
738 return -1;
739 }
740 }else if((unsigned)y >= n->leny){
741 logerror("target y %d >= height %u", y, n->leny);
742 return -1;
743 }else{
744 n->y = y;
745 }
746 if(cursor_invalid_p(n)){
747 logerror("invalid cursor following move (%d/%d)", n->y, n->x);
748 return -1;
749 }
750 return 0;
751}
Here is the caller graph for this function:

◆ ncplane_cursor_yx()

void ncplane_cursor_yx ( const ncplane n,
unsigned *  y,
unsigned *  x 
)

Definition at line 1744 of file notcurses.c.

1744 {
1745 if(y){
1746 *y = n->y;
1747 }
1748 if(x){
1749 *x = n->x;
1750 }
1751}
Here is the caller graph for this function:

◆ ncplane_destroy()

int ncplane_destroy ( ncplane ncp)

Definition at line 1021 of file notcurses.c.

1021 {
1022 if(ncp == NULL){
1023 return 0;
1024 }
1025 if(ncplane_notcurses(ncp)->stdplane == ncp){
1026 logerror("won't destroy standard plane");
1027 return -1;
1028 }
1029//notcurses_debug(ncplane_notcurses(ncp), stderr);
1030 loginfo("destroying %dx%d plane \"%s\" @ %dx%d",
1031 ncp->leny, ncp->lenx, ncp->name ? ncp->name : NULL, ncp->absy, ncp->absx);
1032 int ret = 0;
1033 // dissolve our binding from behind (->bprev is either NULL, or its
1034 // predecessor on the bound list's ->bnext, or &ncp->boundto->blist)
1035 if(ncp->bprev){
1036 if( (*ncp->bprev = ncp->bnext) ){
1037 ncp->bnext->bprev = ncp->bprev;
1038 }
1039 }else if(ncp->bnext){
1040 //assert(ncp->boundto->blist == ncp);
1041 ncp->bnext->bprev = NULL;
1042 }
1043 // recursively reparent our children to the plane to which we are bound.
1044 // this will extract each one from the sibling list.
1045 struct ncplane* bound = ncp->blist;
1046 while(bound){
1047 struct ncplane* tmp = bound->bnext;
1048 ncplane* bindto = ((ncp == ncp->boundto) ? bound : ncp->boundto);
1049 if(ncplane_reparent_family(bound, bindto) == NULL){
1050 ret = -1;
1051 }
1052 bound = tmp;
1053 }
1054 // extract ourselves from the z-axis. do this *after* reparenting, in case
1055 // reparenting shifts up the z-axis somehow (though i don't think it can,
1056 // at least not within a pile?).
1057 if(ncp->above){
1058 ncp->above->below = ncp->below;
1059 }else{
1060 ncplane_pile(ncp)->top = ncp->below;
1061 }
1062 if(ncp->below){
1063 ncp->below->above = ncp->above;
1064 }else{
1065 ncplane_pile(ncp)->bottom = ncp->above;
1066 }
1067 free_plane(ncp);
1068 return ret;
1069}
ncplane * ncplane_reparent_family(ncplane *n, ncplane *newparent)
Definition notcurses.c:2918
void free_plane(ncplane *p)
Definition notcurses.c:467
struct ncplane * blist
Definition internal.h:102
struct ncplane * boundto
Definition internal.h:103
struct ncplane * bnext
Definition internal.h:100
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_dim_yx()

void ncplane_dim_yx ( const ncplane n,
unsigned *  rows,
unsigned *  cols 
)

Definition at line 304 of file notcurses.c.

304 {
305 if(rows){
306 *rows = n->leny;
307 }
308 if(cols){
309 *cols = n->lenx;
310 }
311}
Here is the caller graph for this function:

◆ ncplane_dup()

ncplane * ncplane_dup ( const ncplane n,
void *  opaque 
)

Definition at line 763 of file notcurses.c.

763 {
764 int dimy = n->leny;
765 int dimx = n->lenx;
766 const int placey = n->absy;
767 const int placex = n->absx;
768 struct ncplane_options nopts = {
769 .y = placey,
770 .x = placex,
771 .rows = dimy,
772 .cols = dimx,
773 .userptr = opaque,
774 .name = n->name,
775 .resizecb = ncplane_resizecb(n),
776 .flags = 0,
777 };
778 ncplane* newn = ncplane_create(n->boundto, &nopts);
779 if(newn == NULL){
780 return NULL;
781 }
782 // we don't duplicate sprites...though i'm unsure why not
783 size_t fbsize = sizeof(*n->fb) * dimx * dimy;
784 if(egcpool_dup(&newn->pool, &n->pool)){
786 return NULL;
787 }
788 memmove(newn->fb, n->fb, fbsize);
789 // don't use ncplane_cursor_move_yx() here; the cursor could be in an
790 // invalid location, which will be disallowed, failing out.
791 newn->y = n->y;
792 newn->x = n->x;
793 newn->halign = n->halign;
794 newn->stylemask = ncplane_styles(n);
795 newn->channels = ncplane_channels(n);
796 // we dupd the egcpool, so just dup the goffset
797 newn->basecell = n->basecell;
798 return newn;
799}
int ncplane_destroy(ncplane *ncp)
Definition notcurses.c:1021
uint16_t ncplane_styles(const ncplane *n)
Definition notcurses.c:1501
int(*)(ncplane *) ncplane_resizecb(const ncplane *n)
Definition notcurses.c:2682
uint64_t ncplane_channels(const ncplane *n)
Definition notcurses.c:1493
ncplane * ncplane_create(ncplane *n, const ncplane_options *nopts)
Definition notcurses.c:710
return newn
Definition notcurses.h:3512
Here is the call graph for this function:

◆ ncplane_erase()

void ncplane_erase ( ncplane n)

Definition at line 2464 of file notcurses.c.

2464 {
2465 loginfo("erasing %dx%d plane", n->leny, n->lenx);
2466 if(n->sprite){
2467 sprixel_hide(n->sprite);
2468 destroy_tam(n);
2469 }
2470 // we must preserve the background, but a pure nccell_duplicate() would be
2471 // wiped out by the egcpool_dump(). do a duplication (to get the stylemask
2472 // and channels), and then reload.
2473 char* egc = nccell_strdup(n, &n->basecell);
2474 memset(n->fb, 0, sizeof(*n->fb) * n->leny * n->lenx);
2475 egcpool_dump(&n->pool);
2476 // we need to zero out the EGC before handing this off to nccell_load, but
2477 // we don't want to lose the channels/attributes, so explicit gcluster load.
2478 n->basecell.gcluster = 0;
2479 nccell_load(n, &n->basecell, egc);
2480 free(egc);
2481 n->y = n->x = 0;
2482}
const char * egc
Definition egcpool.h:162
int nccell_load(ncplane *n, nccell *c, const char *gcluster)
Definition notcurses.c:1836
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_erase_region()

int ncplane_erase_region ( ncplane n,
int  ystart,
int  xstart,
int  ylen,
int  xlen 
)

Definition at line 2484 of file notcurses.c.

2484 {
2485 if(ystart == -1){
2486 ystart = n->y;
2487 }
2488 if(xstart == -1){
2489 xstart = n->x;
2490 }
2491 if(ystart < 0 || xstart < 0){
2492 logerror("illegal start of erase (%d, %d)", ystart, xstart);
2493 return -1;
2494 }
2495 if(ystart >= (int)ncplane_dim_y(n) || xstart >= (int)ncplane_dim_x(n)){
2496 logerror("illegal start of erase (%d, %d)", ystart, xstart);
2497 return -1;
2498 }
2499 if(xlen < 0){
2500 if(xlen + 1 < -xstart){
2501 xlen = -xstart - 1;
2502 }
2503 xstart = xstart + xlen + 1;
2504 xlen = -xlen;
2505 }else if(xlen == 0){
2506 xstart = 0;
2507 xlen = ncplane_dim_x(n);
2508 }
2509 if(xlen > (int)ncplane_dim_x(n) || xstart + xlen > (int)ncplane_dim_x(n)){
2510 xlen = ncplane_dim_x(n) - xstart;
2511 }
2512 if(ylen < 0){
2513 if(ylen + 1 < -ystart){
2514 ylen = -ystart - 1;
2515 }
2516 ystart = ystart + ylen + 1;
2517 ylen = -ylen;
2518 }else if(ylen == 0){
2519 ystart = 0;
2520 ylen = ncplane_dim_y(n);
2521 }
2522 if(ylen > (int)ncplane_dim_y(n) || ystart + ylen > (int)ncplane_dim_y(n)){
2523 ylen = ncplane_dim_y(n) - ystart;
2524 }
2525 // special-case the full plane erasure, as it's powerfully optimized (O(1))
2526 if(ystart == 0 && xstart == 0 &&
2527 ylen == (int)ncplane_dim_y(n) && xlen == (int)ncplane_dim_x(n)){
2528 int tmpy = n->y; // preserve cursor location
2529 int tmpx = n->x;
2531 n->y = tmpy;
2532 n->x = tmpx;
2533 return 0;
2534 }
2535 loginfo("erasing %d/%d - %d/%d", ystart, xstart, ystart + ylen, xstart + xlen);
2536 for(int y = ystart ; y < ystart + ylen ; ++y){
2537 for(int x = xstart ; x < xstart + xlen ; ++x){
2538 nccell_release(n, &n->fb[nfbcellidx(n, y, x)]);
2539 nccell_init(&n->fb[nfbcellidx(n, y, x)]);
2540 }
2541 }
2542 return 0;
2543}
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
void ncplane_erase(ncplane *n)
Definition notcurses.c:2464
void nccell_release(ncplane *n, nccell *c)
Definition render.c:128
Here is the call graph for this function:

◆ ncplane_family_destroy()

int ncplane_family_destroy ( ncplane ncp)

Definition at line 1071 of file notcurses.c.

1071 {
1072 if(ncp == NULL){
1073 return 0;
1074 }
1075 if(ncplane_notcurses(ncp)->stdplane == ncp){
1076 logerror("won't destroy standard plane");
1077 return -1;
1078 }
1079 int ret = 0;
1080 while(ncp->blist){
1081 ret |= ncplane_family_destroy(ncp->blist);
1082 }
1083 ret |= ncplane_destroy(ncp);
1084 return ret;
1085}
int ncplane_family_destroy(ncplane *ncp)
Definition notcurses.c:1071
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_hline_interp()

int ncplane_hline_interp ( ncplane n,
const nccell c,
unsigned  len,
uint64_t  c1,
uint64_t  c2 
)

Definition at line 2159 of file notcurses.c.

2160 {
2161 if(len <= 0){
2162 logerror("passed invalid length %u", len);
2163 return -1;
2164 }
2165 unsigned ur, ug, ub;
2166 int r1, g1, b1, r2, g2, b2;
2167 int br1, bg1, bb1, br2, bg2, bb2;
2168 ncchannels_fg_rgb8(c1, &ur, &ug, &ub);
2169 r1 = ur; g1 = ug; b1 = ub;
2170 ncchannels_fg_rgb8(c2, &ur, &ug, &ub);
2171 r2 = ur; g2 = ug; b2 = ub;
2172 ncchannels_bg_rgb8(c1, &ur, &ug, &ub);
2173 br1 = ur; bg1 = ug; bb1 = ub;
2174 ncchannels_bg_rgb8(c2, &ur, &ug, &ub);
2175 br2 = ur; bg2 = ug; bb2 = ub;
2176 int deltr = r2 - r1;
2177 int deltg = g2 - g1;
2178 int deltb = b2 - b1;
2179 int deltbr = br2 - br1;
2180 int deltbg = bg2 - bg1;
2181 int deltbb = bb2 - bb1;
2182 unsigned ret;
2184 if(nccell_duplicate(n, &dupc, c) < 0){
2185 return -1;
2186 }
2187 bool fgdef = false, bgdef = false;
2188 if(ncchannels_fg_default_p(c1) && ncchannels_fg_default_p(c2)){
2189 fgdef = true;
2190 }
2191 if(ncchannels_bg_default_p(c1) && ncchannels_bg_default_p(c2)){
2192 bgdef = true;
2193 }
2194 for(ret = 0 ; ret < len ; ++ret){
2195 int r = (deltr * (int)ret) / (int)len + r1;
2196 int g = (deltg * (int)ret) / (int)len + g1;
2197 int b = (deltb * (int)ret) / (int)len + b1;
2198 int br = (deltbr * (int)ret) / (int)len + br1;
2199 int bg = (deltbg * (int)ret) / (int)len + bg1;
2200 int bb = (deltbb * (int)ret) / (int)len + bb1;
2201 if(!fgdef){
2202 nccell_set_fg_rgb8(&dupc, r, g, b);
2203 }
2204 if(!bgdef){
2205 nccell_set_bg_rgb8(&dupc, br, bg, bb);
2206 }
2207 if(ncplane_putc(n, &dupc) <= 0){
2208 return -1;
2209 }
2210 }
2211 nccell_release(n, &dupc);
2212 return ret;
2213}
int r
Definition fbuf.h:226
API int API int const nccell unsigned len
Definition notcurses.h:2592
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_home()

void ncplane_home ( ncplane n)

Definition at line 718 of file notcurses.c.

718 {
719 n->x = 0;
720 n->y = 0;
721}
Here is the caller graph for this function:

◆ ncplane_move_above()

int ncplane_move_above ( ncplane *restrict  n,
ncplane *restrict  above 
)

Definition at line 1584 of file notcurses.c.

1584 {
1585 if(n == above){ // probably gets optimized out =/
1586 return -1;
1587 }
1588 ncpile* p = ncplane_pile(n);
1589 if(above == NULL){
1590 if(n->below){
1591 if( (n->below->above = n->above) ){
1592 n->above->below = n->below;
1593 }else{
1594 p->top = n->below;
1595 }
1596 n->below = NULL;
1597 if( (n->above = p->bottom) ){
1598 n->above->below = n;
1599 }
1600 p->bottom = n;
1601 }
1602 return 0;
1603 }
1604 if(n->below != above){
1605 if(p != ncplane_pile(above)){ // can't move among piles
1606 return -1;
1607 }
1608 // splice out 'n'
1609 if(n->below){
1610 n->below->above = n->above;
1611 }else{
1612 p->bottom = n->above;
1613 }
1614 if(n->above){
1615 n->above->below = n->below;
1616 }else{
1617 p->top = n->below;
1618 }
1619 if( (n->above = above->above) ){
1620 above->above->below = n;
1621 }else{
1622 p->top = n;
1623 }
1624 above->above = n;
1625 n->below = above;
1626 }
1627 return 0;
1628}
Here is the caller graph for this function:

◆ ncplane_move_below()

int ncplane_move_below ( ncplane *restrict  n,
ncplane *restrict  below 
)

Definition at line 1631 of file notcurses.c.

1631 {
1632 if(n == below){ // probably gets optimized out =/
1633 return -1;
1634 }
1635 ncpile* p = ncplane_pile(n);
1636 if(below == NULL){
1637 if(n->above){
1638 if( (n->above->below = n->below) ){
1639 n->below->above = n->above;
1640 }else{
1641 p->bottom = n->above;
1642 }
1643 n->above = NULL;
1644 if( (n->below = p->top) ){
1645 n->below->above = n;
1646 }
1647 p->top = n;
1648 }
1649 return 0;
1650 }
1651 if(n->above != below){
1652 if(p != ncplane_pile(below)){ // can't move among piles
1653 return -1;
1654 }
1655 if(n->below){
1656 n->below->above = n->above;
1657 }else{
1658 p->bottom = n->above;
1659 }
1660 if(n->above){
1661 n->above->below = n->below;
1662 }else{
1663 p->top = n->below;
1664 }
1665 if( (n->below = below->below) ){
1666 below->below->above = n;
1667 }else{
1668 p->bottom = n;
1669 }
1670 below->below = n;
1671 n->above = below;
1672 }
1673 return 0;
1674}
Here is the caller graph for this function:

◆ ncplane_move_family_above()

int ncplane_move_family_above ( ncplane *restrict  n,
ncplane *restrict  bpoint 
)

Definition at line 1677 of file notcurses.c.

1677 {
1678 ncplane* above = ncplane_above(n);
1679 ncplane* below = ncplane_below(n);
1680 if(ncplane_move_above(n, bpoint)){
1681 return -1;
1682 }
1683 // traverse the planes above n, until we hit NULL. do the planes above n
1684 // first, so that we know the topmost element of our new ensplicification.
1685 // at this point, n is the bottommost plane, and we're inserting above it.
1686 ncplane* targ = n;
1687 while(above && above != n){
1688 ncplane* tmp = ncplane_above(above);
1689 if(ncplane_descendant_p(above, n)){
1690 ncplane_move_above(above, targ);
1691 targ = above;
1692 }
1693 above = tmp;
1694 }
1695 // n remains the topmost plane, and we're inserting above it. we have to be
1696 // careful this time not to cross into any we moved below n.
1697 const ncplane* topmost = targ;
1698 targ = n;
1699 while(below && below != topmost){
1700 ncplane* tmp = ncplane_below(below);
1701 if(ncplane_descendant_p(below, n)){
1702 ncplane_move_below(below, targ);
1703 targ = below;
1704 }
1705 below = tmp;
1706 }
1707 return 0;
1708}
ncplane * ncplane_above(ncplane *n)
Definition notcurses.c:2557
ncplane * ncplane_below(ncplane *n)
Definition notcurses.c:2553
int ncplane_move_below(ncplane *restrict n, ncplane *restrict below)
Definition notcurses.c:1631
int ncplane_move_above(ncplane *restrict n, ncplane *restrict above)
Definition notcurses.c:1584
Here is the call graph for this function:

◆ ncplane_move_family_below()

int ncplane_move_family_below ( ncplane *restrict  n,
ncplane *restrict  bpoint 
)

Definition at line 1711 of file notcurses.c.

1711 {
1712 ncplane* below = ncplane_below(n);
1713 ncplane* above = ncplane_above(n);
1714 if(ncplane_move_below(n, bpoint)){
1715 return -1;
1716 }
1717 // traverse the planes below n, until we hit NULL. do the planes below n
1718 // first, so that we know the bottommost element of our new ensplicification.
1719 // we're inserting below n...
1720 ncplane* targ = n;
1721 while(below && below != n){
1722 ncplane* tmp = ncplane_below(below);
1723 if(ncplane_descendant_p(below, n)){
1724 ncplane_move_below(below, targ);
1725 targ = below;
1726 }
1727 below = tmp;
1728 }
1729 // n remains the topmost plane, and we're inserting above it. we have to be
1730 // careful this time not to cross into any we moved below n.
1731 const ncplane* bottommost = targ;
1732 targ = n;
1733 while(above && above != bottommost){
1734 ncplane* tmp = ncplane_above(above);
1735 if(ncplane_descendant_p(above, n)){
1736 ncplane_move_above(above, targ);
1737 targ = above;
1738 }
1739 above = tmp;
1740 }
1741 return 0;
1742}
Here is the call graph for this function:

◆ ncplane_move_yx()

int ncplane_move_yx ( ncplane n,
int  y,
int  x 
)

Definition at line 2417 of file notcurses.c.

2417 {
2418 if(n == ncplane_notcurses(n)->stdplane){
2419 return -1;
2420 }
2421 int dy, dx; // amount moved
2422 if(n->boundto == n){
2423 dy = y - n->absy;
2424 dx = x - n->absx;
2425 }else{
2426 dy = (n->boundto->absy + y) - n->absy;
2427 dx = (n->boundto->absx + x) - n->absx;
2428 }
2429 if(dy || dx){ // don't want to trigger sprixel_movefrom() if unneeded
2430 if(n->sprite){
2431 sprixel_movefrom(n->sprite, n->absy, n->absx);
2432 }
2433 n->absx += dx;
2434 n->absy += dy;
2435 move_bound_planes(n->blist, dy, dx);
2436 }
2437 return 0;
2438}
void sprixel_movefrom(sprixel *s, int y, int x)
Definition sprite.c:68
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_name()

char * ncplane_name ( const ncplane n)

Definition at line 2674 of file notcurses.c.

2674 {
2675 return n->name ? strdup(n->name) : NULL;
2676}

◆ ncplane_new_internal()

ncplane * ncplane_new_internal ( notcurses nc,
ncplane n,
const ncplane_options nopts 
)

Definition at line 560 of file notcurses.c.

561 {
562 if(nopts->flags >= (NCPLANE_OPTION_FIXED << 1u)){
563 logwarn("provided unsupported flags %016" PRIx64, nopts->flags);
564 }
566 if(n == NULL){
567 logerror("alignment requires a parent plane");
568 return NULL;
569 }
570 }
572 if(nopts->rows != 0 || nopts->cols != 0){
573 logerror("geometry specified with margins (r=%u, c=%u)",
574 nopts->rows, nopts->cols);
575 return NULL;
576 }
577 }
578 ncplane* p = malloc(sizeof(*p));
579 if(p == NULL){
580 return NULL;
581 }
585 p->widget = NULL;
586 p->wdestruct = NULL;
588 p->margin_b = nopts->margin_b;
589 p->margin_r = nopts->margin_r;
590 if(n){ // use parent size
591 p->leny = ncplane_dim_y(n);
592 p->lenx = ncplane_dim_x(n);
593 }else{ // use pile size
594 notcurses_term_dim_yx(nc, &p->leny, &p->lenx);
595 }
596 if((p->leny -= p->margin_b) <= 0){
597 p->leny = 1;
598 }
599 if((p->lenx -= p->margin_r) <= 0){
600 p->lenx = 1;
601 }
602 }else{
603 p->leny = nopts->rows;
604 p->lenx = nopts->cols;
605 }
606
607 size_t fbsize = ncplane_sizeof_cellarray(p->leny, p->lenx);
608 if(!fbsize || (p->fb = calloc(fbsize, sizeof(struct nccell))) == NULL){
609 logerror("error allocating cellmatrix (r=%u, c=%u)",
610 p->leny, p->lenx);
611 free(p);
612 return NULL;
613 }
614 p->x = p->y = 0;
615 p->logrow = 0;
616 p->sprite = NULL;
617 p->blist = NULL;
618 p->name = strdup(nopts->name ? nopts->name : "");
621 p->tam = NULL;
622 if(!n){ // new root/standard plane
623 p->absy = nopts->y;
624 p->absx = nopts->x;
625 p->bnext = NULL;
626 p->bprev = NULL;
627 p->boundto = p;
628 }else{ // bound to preexisting pile
629 if(nopts->flags & NCPLANE_OPTION_HORALIGNED){
630 p->absx = ncplane_halign(n, nopts->x, nopts->cols);
631 p->halign = nopts->x;
632 }else{
633 p->absx = nopts->x;
634 }
635 p->absx += n->absx;
636 if(nopts->flags & NCPLANE_OPTION_VERALIGNED){
637 p->absy = ncplane_valign(n, nopts->y, nopts->rows);
638 p->valign = nopts->y;
639 }else{
640 p->absy = nopts->y;
641 }
642 p->absy += n->absy;
643 if( (p->bnext = n->blist) ){
644 n->blist->bprev = &p->bnext;
645 }
646 p->bprev = &n->blist;
647 *p->bprev = p;
648 p->boundto = n;
649 }
650 // FIXME handle top/left margins
651 p->resizecb = nopts->resizecb;
652 p->stylemask = 0;
653 p->channels = 0;
654 egcpool_init(&p->pool);
655 nccell_init(&p->basecell);
656 p->userptr = nopts->userptr;
657 if(nc == NULL){ // fake ncplane backing ncdirect object
658 p->above = NULL;
659 p->below = NULL;
660 p->pile = NULL;
661 }else{
662 pthread_mutex_lock(&nc->pilelock);
663 ncpile* pile = n ? ncplane_pile(n) : NULL;
664 if( (p->pile = pile) ){ // existing pile
665 p->above = NULL;
666 if( (p->below = pile->top) ){ // always happens save initial plane
667 pile->top->above = p;
668 }else{
669 pile->bottom = p;
670 }
671 pile->top = p;
672 }else{ // new pile
673 make_ncpile(nc, p);
674 }
675 pthread_mutex_lock(&nc->stats.lock);
676 nc->stats.s.fbbytes += fbsize;
677 ++nc->stats.s.planes;
678 pthread_mutex_unlock(&nc->stats.lock);
679 pthread_mutex_unlock(&nc->pilelock);
680 }
681 loginfo("created new %ux%u plane \"%s\" @ %dx%d",
682 p->leny, p->lenx, p->name ? p->name : "", p->absy, p->absx);
683 return p;
684}
#define NCPLANE_OPTION_HORALIGNED
Definition notcurses.h:1441
#define NCPLANE_OPTION_AUTOGROW
Definition notcurses.h:1458
#define NCPLANE_OPTION_MARGINALIZED
Definition notcurses.h:1450
#define NCPLANE_OPTION_VSCROLL
Definition notcurses.h:1462
@ NCALIGN_UNALIGNED
Definition notcurses.h:81
#define NCPLANE_OPTION_VERALIGNED
Definition notcurses.h:1443
#define NCPLANE_OPTION_FIXED
Definition notcurses.h:1454
const char * name
Definition notcurses.h:1470
int(* resizecb)(struct ncplane *)
Definition notcurses.h:1471
int logrow
Definition internal.h:78
ncalign_e valign
Definition internal.h:113
bool fixedbound
Definition internal.h:117
bool scrolling
Definition internal.h:116
bool autogrow
Definition internal.h:118
struct ncpile * pile
Definition internal.h:92
uint64_t channels
Definition internal.h:88
ncalign_e halign
Definition internal.h:112
unsigned x
Definition internal.h:79
int absy
Definition internal.h:83
uint16_t stylemask
Definition internal.h:114
void * userptr
Definition internal.h:108
tament * tam
Definition internal.h:106
int(* resizecb)(struct ncplane *)
Definition internal.h:109
unsigned y
Definition internal.h:79
int absx
Definition internal.h:83
int margin_b
Definition internal.h:115
int margin_r
Definition internal.h:115
Here is the caller graph for this function:

◆ ncplane_notcurses()

notcurses * ncplane_notcurses ( const ncplane n)

Definition at line 2631 of file notcurses.c.

2631 {
2632 return ncplane_pile(n)->nc;
2633}
Here is the caller graph for this function:

◆ ncplane_notcurses_const()

const notcurses * ncplane_notcurses_const ( const ncplane n)

Definition at line 2635 of file notcurses.c.

2635 {
2636 return ncplane_pile_const(n)->nc;
2637}
Here is the caller graph for this function:

◆ ncplane_off_styles()

void ncplane_off_styles ( ncplane n,
unsigned  stylebits 
)

Definition at line 2087 of file notcurses.c.

2087 {
2088 n->stylemask &= ~(stylebits & NCSTYLE_MASK);
2089}
#define NCSTYLE_MASK
Definition notcurses.h:769
Here is the caller graph for this function:

◆ ncplane_on_styles()

void ncplane_on_styles ( ncplane n,
unsigned  stylebits 
)

Definition at line 2082 of file notcurses.c.

2082 {
2083 n->stylemask |= (stylebits & NCSTYLE_MASK);
2084}
Here is the caller graph for this function:

◆ ncplane_parent()

ncplane * ncplane_parent ( ncplane n)

Definition at line 2656 of file notcurses.c.

2656 {
2657 return n->boundto;
2658}
Here is the caller graph for this function:

◆ ncplane_parent_const()

const ncplane * ncplane_parent_const ( const ncplane n)

Definition at line 2660 of file notcurses.c.

2660 {
2661 return n->boundto;
2662}
Here is the caller graph for this function:

◆ ncplane_pixel_geom()

void ncplane_pixel_geom ( const ncplane n,
unsigned *RESTRICT  pxy,
unsigned *RESTRICT  pxx,
unsigned *RESTRICT  celldimy,
unsigned *RESTRICT  celldimx,
unsigned *RESTRICT  maxbmapy,
unsigned *RESTRICT  maxbmapx 
)

Definition at line 3335 of file notcurses.c.

3338 {
3339 const notcurses* nc = ncplane_notcurses_const(n);
3340 const ncpile* p = ncplane_pile_const(n);
3341 if(celldimy){
3342 *celldimy = p->cellpxy;
3343 }
3344 if(celldimx){
3345 *celldimx = p->cellpxx;
3346 }
3347 if(pxy){
3348 *pxy = p->cellpxy * ncplane_dim_y(n);
3349 }
3350 if(pxx){
3351 *pxx = p->cellpxx * ncplane_dim_x(n);
3352 }
3354 if(maxbmapy){
3355 *maxbmapy = p->cellpxy * ncplane_dim_y(n);
3356 if(*maxbmapy > nc->tcache.sixel_maxy && nc->tcache.sixel_maxy){
3357 *maxbmapy = nc->tcache.sixel_maxy;
3358 }
3359 }
3360 if(maxbmapx){
3361 *maxbmapx = p->cellpxx * ncplane_dim_x(n);
3362 if(*maxbmapx > nc->tcache.sixel_maxx && nc->tcache.sixel_maxx){
3363 *maxbmapx = nc->tcache.sixel_maxx;
3364 }
3365 }
3366 }else{
3367 if(maxbmapy){
3368 *maxbmapy = 0;
3369 }
3370 if(maxbmapx){
3371 *maxbmapx = 0;
3372 }
3373 }
3374}
const notcurses * ncplane_notcurses_const(const ncplane *n)
Definition notcurses.c:2635
ncpixelimpl_e notcurses_check_pixel_support(const notcurses *nc)
Definition notcurses.c:1156
tinfo tcache
Definition internal.h:360
unsigned sixel_maxx
Definition termdesc.h:165
unsigned sixel_maxy
Definition termdesc.h:172
Here is the call graph for this function:

◆ ncplane_putc_yx()

int ncplane_putc_yx ( ncplane n,
int  y,
int  x,
const nccell c 
)

Definition at line 1986 of file notcurses.c.

1986 {
1987 const int cols = nccell_cols(c);
1988 // unfortunately, |c| comes from |n|. the act of writing |c| to |n| could
1989 // grow |n|'s egcpool, invalidating the reference represented by
1990 // nccell_extended_gcluster(). so we must copy and free it.
1991 char* egc = nccell_strdup(n, c);
1992 if(egc == NULL){
1993 logerror("couldn't duplicate cell");
1994 return -1;
1995 }
1996 int r = ncplane_put(n, y, x, egc, cols, c->stylemask, c->channels, strlen(egc));
1997 free(egc);
1998 return r;
1999}
uint64_t channels
Definition notcurses.h:723
uint16_t stylemask
Definition notcurses.h:703
Here is the caller graph for this function:

◆ ncplane_putchar_stained()

int ncplane_putchar_stained ( ncplane n,
char  c 
)

Definition at line 2014 of file notcurses.c.

2014 {
2015 uint64_t channels = n->channels;
2016 uint16_t stylemask = n->stylemask;
2017 const nccell* targ = &n->fb[nfbcellidx(n, n->y, n->x)];
2018 n->channels = targ->channels;
2019 n->stylemask = targ->stylemask;
2020 int ret = ncplane_putchar(n, c);
2021 n->channels = channels;
2022 n->stylemask = stylemask;
2023 return ret;
2024}
Here is the caller graph for this function:

◆ ncplane_putegc_stained()

int ncplane_putegc_stained ( ncplane n,
const char *  gclust,
size_t *  sbytes 
)

Definition at line 2038 of file notcurses.c.

2038 {
2039 uint64_t channels = n->channels;
2040 uint16_t stylemask = n->stylemask;
2041 const nccell* targ = &n->fb[nfbcellidx(n, n->y, n->x)];
2042 n->channels = targ->channels;
2043 n->stylemask = targ->stylemask;
2044 int ret = ncplane_putegc(n, gclust, sbytes);
2045 n->channels = channels;
2046 n->stylemask = stylemask;
2047 return ret;
2048}
Here is the caller graph for this function:

◆ ncplane_putegc_yx()

int ncplane_putegc_yx ( ncplane n,
int  y,
int  x,
const char *  gclust,
size_t *  sbytes 
)

Definition at line 2001 of file notcurses.c.

2001 {
2002 int cols;
2003 int bytes = utf8_egc_len(gclust, &cols);
2004 if(bytes < 0){
2005 return -1;
2006 }
2007 if(sbytes){
2008 *sbytes = bytes;
2009 }
2010//fprintf(stderr, "glust: %s cols: %d wcs: %d\n", gclust, cols, bytes);
2011 return ncplane_put(n, y, x, gclust, cols, n->stylemask, n->channels, bytes);
2012}
Here is the caller graph for this function:

◆ ncplane_putnstr_aligned()

int ncplane_putnstr_aligned ( struct ncplane n,
int  y,
ncalign_e  align,
size_t  s,
const char *  str 
)

Definition at line 2152 of file notcurses.c.

2152 {
2153 char* chopped = strndup(str, s);
2154 int ret = ncplane_putstr_aligned(n, y, align, chopped);
2155 free(chopped);
2156 return ret;
2157}

◆ ncplane_putwegc_stained()

int ncplane_putwegc_stained ( ncplane n,
const wchar_t *  gclust,
size_t *  sbytes 
)

Definition at line 2026 of file notcurses.c.

2026 {
2027 uint64_t channels = n->channels;
2028 uint16_t stylemask = n->stylemask;
2029 const nccell* targ = &n->fb[nfbcellidx(n, n->y, n->x)];
2030 n->channels = targ->channels;
2031 n->stylemask = targ->stylemask;
2032 int ret = ncplane_putwegc(n, gclust, sbytes);
2033 n->channels = channels;
2034 n->stylemask = stylemask;
2035 return ret;
2036}
Here is the caller graph for this function:

◆ ncplane_putwstr_stained()

int ncplane_putwstr_stained ( ncplane n,
const wchar_t *  gclustarr 
)

Definition at line 3280 of file notcurses.c.

3280 {
3281 mbstate_t ps = {0};
3282 const wchar_t** wset = &gclustarr;
3283 size_t mbytes = wcsrtombs(NULL, wset, 0, &ps);
3284 if(mbytes == (size_t)-1){
3285 logerror("error converting wide string");
3286 return -1;
3287 }
3288 ++mbytes;
3289 char* mbstr = malloc(mbytes);
3290 if(mbstr == NULL){
3291 return -1;
3292 }
3293 size_t s = wcsrtombs(mbstr, wset, mbytes, &ps);
3294 if(s == (size_t)-1){
3295 free(mbstr);
3296 return -1;
3297 }
3298 int r = ncplane_putstr_stained(n, mbstr);
3299 free(mbstr);
3300 return r;
3301}
Here is the caller graph for this function:

◆ ncplane_reparent()

ncplane * ncplane_reparent ( ncplane n,
ncplane newparent 
)

Definition at line 2796 of file notcurses.c.

2796 {
2797 const notcurses* nc = ncplane_notcurses_const(n);
2798 if(n == nc->stdplane){
2799 logerror("won't reparent standard plane");
2800 return NULL; // can't reparent standard plane
2801 }
2802 if(n->boundto == newparent){
2803 loginfo("won't reparent plane to itself");
2804 return n; // don't return error, just a no-op
2805 }
2806//notcurses_debug(ncplane_notcurses(n), stderr);
2807 if(n->blist){
2808 if(n->boundto == n){ // children become new root planes
2809 ncplane* lastlink;
2810 ncplane* child = n->blist;
2811 do{
2812 child->boundto = child;
2813 lastlink = child;
2814 child = child->bnext;
2815 }while(child); // n->blist != NULL -> lastlink != NULL
2816 if( (lastlink->bnext = ncplane_pile(n)->roots) ){
2817 lastlink->bnext->bprev = &lastlink->bnext;
2818 }
2819 n->blist->bprev = &ncplane_pile(n)->roots;
2820 ncplane_pile(n)->roots = n->blist;
2821 }else{ // children are rebound to current parent
2822 ncplane* lastlink;
2823 ncplane* child = n->blist;
2824 do{
2825 child->boundto = n->boundto;
2826 lastlink = child;
2827 child = child->bnext;
2828 }while(child); // n->blist != NULL -> lastlink != NULL
2829 if( (lastlink->bnext = n->boundto->blist) ){
2830 lastlink->bnext->bprev = &lastlink->bnext;
2831 }
2832 n->blist->bprev = &n->boundto->blist;
2833 n->boundto->blist = n->blist;
2834 }
2835 n->blist = NULL;
2836 }
2837 // FIXME would be nice to skip ncplane_descendant_p() on this call...:/
2838 return ncplane_reparent_family(n, newparent);
2839}
ncplane * stdplane
Definition internal.h:333
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_reparent_family()

ncplane * ncplane_reparent_family ( ncplane n,
ncplane newparent 
)

Definition at line 2918 of file notcurses.c.

2918 {
2919 // ncplane_notcurses() goes through ncplane_pile(). since we're possibly
2920 // destroying piles below, get the notcurses reference early on.
2922 if(n == nc->stdplane){
2923 return NULL; // can't reparent standard plane
2924 }
2925 if(n->boundto == newparent){ // no-op
2926 return n;
2927 }
2928 if(ncplane_descendant_p(newparent, n)){
2929 return NULL;
2930 }
2931//notcurses_debug(ncplane_notcurses(n), stderr);
2932 if(n->bprev){ // extract from sibling list
2933 if( (*n->bprev = n->bnext) ){
2934 n->bnext->bprev = n->bprev;
2935 }
2936 }else if(n->bnext){
2937 n->bnext->bprev = NULL;
2938 }
2939 n->bprev = NULL;
2940 n->bnext = NULL;
2941 // if leaving a pile, extract n from the old zaxis, and also any sprixel
2942 sprixel* s = NULL;
2943 if(n == newparent || ncplane_pile(n) != ncplane_pile(newparent)){
2944 unsplice_zaxis_recursive(n);
2945 s = unsplice_sprixels_recursive(n, NULL);
2946 }
2947 const unsigned ocellpxy = ncplane_pile(n)->cellpxy;
2948 const unsigned ocellpxx = ncplane_pile(n)->cellpxx;
2949 n->boundto = newparent;
2950 if(n == n->boundto){ // we're a new root plane
2951 logdebug("reparenting new root plane %p", n);
2952 unsplice_zaxis_recursive(n);
2953 n->bnext = NULL;
2954 n->bprev = NULL;
2955 pthread_mutex_lock(&nc->pilelock);
2956 if(ncplane_pile(n)->top == NULL){ // did we just empty our pile?
2957 ncpile_destroy(ncplane_pile(n));
2958 }
2959 make_ncpile(nc, n);
2960 unsigned ncellpxy = ncplane_pile(n)->cellpxy;
2961 unsigned ncellpxx = ncplane_pile(n)->cellpxx;
2962 pthread_mutex_unlock(&nc->pilelock);
2963 if(ncplane_pile(n)){ // FIXME otherwise, we've got a problem...!
2964 splice_zaxis_recursive(n, ncplane_pile(n), ocellpxy, ocellpxx, ncellpxy, ncellpxx);
2965 }
2966 }else{ // establish ourselves as a sibling of new parent's children
2967 if( (n->bnext = newparent->blist) ){
2968 n->bnext->bprev = &n->bnext;
2969 }
2970 n->bprev = &newparent->blist;
2971 newparent->blist = n;
2972 // place it immediately above the new binding plane if crossing piles
2973 if(ncplane_pile(n) != ncplane_pile(n->boundto)){
2974 unsigned ncellpxy = ncplane_pile(n->boundto)->cellpxy;
2975 unsigned ncellpxx = ncplane_pile(n->boundto)->cellpxx;
2976 pthread_mutex_lock(&nc->pilelock);
2977 if(ncplane_pile(n)->top == NULL){ // did we just empty our pile?
2978 ncpile_destroy(ncplane_pile(n));
2979 }
2980 n->pile = ncplane_pile(n->boundto);
2981 pthread_mutex_unlock(&nc->pilelock);
2982 splice_zaxis_recursive(n, ncplane_pile(n), ocellpxy, ocellpxx, ncellpxy, ncellpxx);
2983 }
2984 }
2985 if(s){ // must be on new plane, with sprixels to donate
2986 sprixel* lame = s;
2987 while(lame->next){
2988 lame = lame->next;
2989 }
2990 if( (lame->next = n->pile->sprixelcache) ){
2991 n->pile->sprixelcache->prev = lame;
2992 }
2993 n->pile->sprixelcache = s;
2994 }
2995 return n;
2996}
struct sprixel * prev
Definition sprite.h:145
struct sprixel * next
Definition sprite.h:144
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_resize()

int ncplane_resize ( ncplane n,
int  keepy,
int  keepx,
unsigned  keepleny,
unsigned  keeplenx,
int  yoff,
int  xoff,
unsigned  ylen,
unsigned  xlen 
)

Definition at line 1009 of file notcurses.c.

1012 {
1013 if(n == ncplane_notcurses(n)->stdplane){
1014//fprintf(stderr, "Can't resize standard plane\n");
1015 return -1;
1016 }
1017 return ncplane_resize_internal(n, keepy, keepx, keepleny, keeplenx,
1018 yoff, xoff, ylen, xlen);
1019}
int ncplane_resize_internal(ncplane *n, int keepy, int keepx, unsigned keepleny, unsigned keeplenx, int yoff, int xoff, unsigned ylen, unsigned xlen)
Definition notcurses.c:857
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_resize_internal()

int ncplane_resize_internal ( ncplane n,
int  keepy,
int  keepx,
unsigned  keepleny,
unsigned  keeplenx,
int  yoff,
int  xoff,
unsigned  ylen,
unsigned  xlen 
)

Definition at line 857 of file notcurses.c.

860 {
861 unsigned rows, cols;
862 if(ncplane_resize_internal_check(n, keepy, keepx, keepleny, keeplenx,
863 yoff, xoff, ylen, xlen,
864 &rows, &cols)){
865 return -1;
866 }
867 if(n->absy == n->absy + keepy && n->absx == n->absx + keepx &&
868 rows == ylen && cols == xlen){
869 return 0;
870 }
872 if(n->sprite){
873 sprixel_hide(n->sprite);
874 }
875 // we're good to resize. we'll need alloc up a new framebuffer, and copy in
876 // those elements we're retaining, zeroing out the rest. alternatively, if
877 // we've shrunk, we will be filling the new structure.
878 int oldarea = rows * cols;
879 int keptarea = keepleny * keeplenx;
880 int newarea = ylen * xlen;
881 size_t fbsize = sizeof(nccell) * newarea;
882 nccell* fb;
883 // there are two cases worth optimizing:
884 //
885 // * nothing is kept. we malloc() a new cellmatrix, dump the EGCpool in
886 // toto, and zero out the matrix. no copies, one memset.
887 // * old and new x dimensions match, and we're keeping the full width.
888 // we release any cells we're about to lose, realloc() the cellmatrix,
889 // and zero out any new cells. so long as the realloc() doesn't move
890 // us, there are no copies, one memset, one iteration (since this is
891 // most often due to autogrowth by a single line, the likelihood that
892 // we remain where we are is pretty high).
893 // * otherwise, we malloc() a new cellmatrix, zero out any new cells,
894 // copy over any reused cells, and release any lost cells. one
895 // gigantic iteration.
896 // we might realloc instead of mallocing, in which case we NULL out
897 // |preserved|. it must otherwise be free()d at the end.
898 nccell* preserved = n->fb;
899 if(cols == xlen && cols == keeplenx && keepleny && !keepy){
900 // we need release the cells that we're losing, lest we leak EGCpool
901 // memory. unfortunately, this means we mutate the plane on the error case.
902 // any solution would involve copying them out first. we only do this if
903 // we're keeping some, as we otherwise drop the EGCpool in toto.
904 if(n->leny > keepleny){
905 for(unsigned y = keepleny ; y < n->leny ; ++y){
906 for(unsigned x = 0 ; x < n->lenx ; ++x){
907 nccell_release(n, ncplane_cell_ref_yx(n, y, x));
908 }
909 }
910 }
911 if((fb = realloc(n->fb, fbsize)) == NULL){
912 return -1;
913 }
914 preserved = NULL;
915 }else{
916 if((fb = malloc(fbsize)) == NULL){
917 return -1;
918 }
919 }
920 if(n->tam){
921 loginfo("tam realloc to %d entries", newarea);
922 // FIXME first, free any disposed auxiliary vectors!
923 tament* tmptam = realloc(n->tam, sizeof(*tmptam) * newarea);
924 if(tmptam == NULL){
925 if(preserved){
926 free(fb);
927 }
928 return -1;
929 }
930 n->tam = tmptam;
931 if(newarea > oldarea){
932 memset(n->tam + oldarea, 0, sizeof(*n->tam) * (newarea - oldarea));
933 }
934 }
935 // update the cursor, if it would otherwise be off-plane
936 if(n->y >= ylen){
937 n->y = ylen - 1;
938 }
939 if(n->x >= xlen){
940 n->x = xlen - 1;
941 }
942 pthread_mutex_lock(&nc->stats.lock);
943 ncplane_notcurses(n)->stats.s.fbbytes -= sizeof(*fb) * (rows * cols);
944 ncplane_notcurses(n)->stats.s.fbbytes += fbsize;
945 pthread_mutex_unlock(&nc->stats.lock);
946 const int oldabsy = n->absy;
947 // go ahead and move. we can no longer fail at this point. but don't yet
948 // resize, because n->len[xy] are used in fbcellidx() in the loop below. we
949 // don't use ncplane_move_yx(), because we want to planebinding-invariant.
950 n->absy += keepy + yoff;
951 n->absx += keepx + xoff;
952//fprintf(stderr, "absx: %d keepx: %d xoff: %d\n", n->absx, keepx, xoff);
953 if(keptarea == 0){ // keep nothing, resize/move only.
954 // if we're keeping nothing, dump the old egcspool. otherwise, we go ahead
955 // and keep it. perhaps we ought compact it?
956 memset(fb, 0, sizeof(*fb) * newarea);
957 egcpool_dump(&n->pool);
958 }else if(!preserved){
959 // the x dimensions are equal, and we're keeping across the width. only the
960 // y dimension changed. if we grew, we need zero out the new cells (if we
961 // shrunk, we already released the old cells prior to the realloc).
962 unsigned tozorch = (ylen - keepleny) * xlen * sizeof(*fb);
963 if(tozorch){
964 unsigned zorchoff = keepleny * xlen;
965 memset(fb + zorchoff, 0, tozorch);
966 }
967 }else{
968 // we currently have maxy rows of maxx cells each. we will be keeping rows
969 // keepy..keepy + keepleny - 1 and columns keepx..keepx + keeplenx - 1.
970 // anything else is zerod out. itery is the row we're writing *to*, and we
971 // must write to each (and every cell in each).
972 for(unsigned itery = 0 ; itery < ylen ; ++itery){
973 int truey = itery + n->absy;
974 int sourceoffy = truey - oldabsy;
975//fprintf(stderr, "sourceoffy: %d keepy: %d ylen: %d\n", sourceoffy, keepy, ylen);
976 // if we have nothing copied to this line, zero it out in one go
977 if(sourceoffy < keepy || sourceoffy >= keepy + (int)keepleny){
978//fprintf(stderr, "writing 0s to line %d of %d\n", itery, ylen);
979 memset(fb + (itery * xlen), 0, sizeof(*fb) * xlen);
980 }else{
981 int copyoff = itery * xlen; // our target at any given time
982 // we do have something to copy, and zero, one, or two regions to zero out
983 unsigned copied = 0;
984 if(xoff < 0){
985 memset(fb + copyoff, 0, sizeof(*fb) * -xoff);
986 copyoff += -xoff;
987 copied += -xoff;
988 }
989 const int sourceidx = nfbcellidx(n, sourceoffy, keepx);
990//fprintf(stderr, "copying line %d (%d) to %d (%d)\n", sourceoffy, sourceidx, copyoff / xlen, copyoff);
991 memcpy(fb + copyoff, preserved + sourceidx, sizeof(*fb) * keeplenx);
992 copyoff += keeplenx;
993 copied += keeplenx;
994 unsigned perline = xlen - copied;
995 for(unsigned x = copyoff ; x < n->lenx ; ++x){
996 nccell_release(n, ncplane_cell_ref_yx(n, sourceoffy, x));
997 }
998 memset(fb + copyoff, 0, sizeof(*fb) * perline);
999 }
1000 }
1001 }
1002 n->fb = fb;
1003 n->lenx = xlen;
1004 n->leny = ylen;
1005 free(preserved);
1007}
int resize_callbacks_children(ncplane *n)
Definition notcurses.c:804
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_resize_marginalized()

int ncplane_resize_marginalized ( ncplane n)

Definition at line 2728 of file notcurses.c.

2728 {
2729 const ncplane* parent = ncplane_parent_const(n);
2730 // a marginalized plane cannot be larger than its oppressor plane =]
2731 unsigned maxy, maxx;
2732 if(parent == n){ // root plane, need to use pile size
2733 ncpile* p = ncplane_pile(n);
2734 maxy = p->dimy;
2735 maxx = p->dimx;
2736 }else{
2737 ncplane_dim_yx(parent, &maxy, &maxx);
2738 }
2739 if((maxy -= (n->margin_b + (n->absy - n->boundto->absy))) < 1){
2740 maxy = 1;
2741 }
2742 if((maxx -= (n->margin_r + (n->absx - n->boundto->absx))) < 1){
2743 maxx = 1;
2744 }
2745 unsigned oldy, oldx;
2746 ncplane_dim_yx(n, &oldy, &oldx); // current dimensions of 'n'
2747 unsigned keepleny = oldy > maxy ? maxy : oldy;
2748 unsigned keeplenx = oldx > maxx ? maxx : oldx;
2749 if(ncplane_resize_internal(n, 0, 0, keepleny, keeplenx, 0, 0, maxy, maxx)){
2750 return -1;
2751 }
2752 int targy = maxy - n->margin_b;
2753 int targx = maxx - n->margin_b;
2754 loginfo("marg %d/%d, pdim %d/%d, move %d/%d", n->margin_b, n->margin_r, maxy, maxx, targy, targx);
2755 return ncplane_move_yx(n, targy, targx);
2756}
int ncplane_move_yx(ncplane *n, int y, int x)
Definition notcurses.c:2417
const ncplane * ncplane_parent_const(const ncplane *n)
Definition notcurses.c:2660
Here is the call graph for this function:

◆ ncplane_resize_maximize()

int ncplane_resize_maximize ( ncplane n)

Definition at line 2758 of file notcurses.c.

2758 {
2759 const ncpile* pile = ncplane_pile(n); // FIXME should be taken against parent
2760 const unsigned rows = pile->dimy;
2761 const unsigned cols = pile->dimx;
2762 unsigned oldy, oldx;
2763 ncplane_dim_yx(n, &oldy, &oldx); // current dimensions of 'n'
2764 unsigned keepleny = oldy > rows ? rows : oldy;
2765 unsigned keeplenx = oldx > cols ? cols : oldx;
2766 return ncplane_resize_internal(n, 0, 0, keepleny, keeplenx, 0, 0, rows, cols);
2767}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_resize_placewithin()

int ncplane_resize_placewithin ( ncplane n)

Definition at line 2686 of file notcurses.c.

2686 {
2687 if(n->boundto == n){
2688 return 0;
2689 }
2690 int absy = ncplane_abs_y(n);
2691 int absx = ncplane_abs_x(n);
2692 int ret = 0;
2693 if(absy + ncplane_dim_y(n) > ncplane_dim_y(n->boundto)){
2694 const int dy = (absy + ncplane_dim_y(n)) - ncplane_dim_y(n->boundto);
2695 logdebug("moving up %d", dy);
2696 if(ncplane_move_rel(n, -dy, 0)){
2697 ret = -1;
2698 }
2699 absy = ncplane_abs_y(n);
2700 }
2701 if(absx + ncplane_dim_x(n) > ncplane_dim_x(n->boundto)){
2702 const int dx = ncplane_dim_x(n->boundto) - (absx + ncplane_dim_x(n));
2703 logdebug("moving left %d", dx);
2704 if(ncplane_move_rel(n, 0, dx)){
2705 ret = -1;
2706 }
2707 absx = ncplane_abs_x(n);
2708 }
2709 // this will prefer upper-left material if the child plane is larger than
2710 // the parent. we might want a smarter rule, one based on origin?
2711 if(absy < 0){
2712 logdebug("moving down %d", -absy);
2713 // we're at least partially above our parent
2714 if(ncplane_move_rel(n, -absy, 0)){
2715 ret = -1;
2716 }
2717 }
2718 if(absx < 0){
2719 logdebug("moving right %d", -absx);
2720 // we're at least partially to the left of our parent
2721 if(ncplane_move_rel(n, 0, -absx)){
2722 ret = -1;
2723 }
2724 }
2725 return ret;
2726}
Here is the call graph for this function:

◆ ncplane_resize_realign()

int ncplane_resize_realign ( ncplane n)

Definition at line 2769 of file notcurses.c.

2769 {
2770 const ncplane* parent = ncplane_parent_const(n);
2771 if(parent == n){
2772 logerror("can't realign a root plane");
2773 return 0;
2774 }
2775 if(n->halign == NCALIGN_UNALIGNED && n->valign == NCALIGN_UNALIGNED){
2776 logerror("passed a non-aligned plane");
2777 return -1;
2778 }
2779 int xpos = ncplane_x(n);
2780 if(n->halign != NCALIGN_UNALIGNED){
2781 xpos = ncplane_halign(parent, n->halign, ncplane_dim_x(n));
2782 }
2783 int ypos = ncplane_y(n);
2784 if(n->valign != NCALIGN_UNALIGNED){
2785 ypos = ncplane_valign(parent, n->valign, ncplane_dim_y(n));
2786 }
2787 return ncplane_move_yx(n, ypos, xpos);
2788}
int ncplane_x(const ncplane *n)
Definition notcurses.c:2447
int ncplane_y(const ncplane *n)
Definition notcurses.c:2440
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_scrolling_p()

bool ncplane_scrolling_p ( const ncplane n)

Definition at line 3004 of file notcurses.c.

3004 {
3005 return n->scrolling;
3006}
Here is the caller graph for this function:

◆ ncplane_scrollup()

int ncplane_scrollup ( ncplane n,
int  r 
)

Definition at line 1795 of file notcurses.c.

1795 {
1796 if(!ncplane_scrolling_p(n)){
1797 logerror("can't scroll %d on non-scrolling plane", r);
1798 return -1;
1799 }
1800 if(r < 0){
1801 logerror("can't scroll %d lines", r);
1802 return -1;
1803 }
1804 while(r-- > 0){
1805 scroll_down(n);
1806 }
1808 notcurses_render(ncplane_notcurses(n));
1809 }
1810 return 0;
1811}
ncplane * notcurses_stdplane(notcurses *nc)
Definition notcurses.c:702
bool ncplane_scrolling_p(const ncplane *n)
Definition notcurses.c:3004
void scroll_down(ncplane *n)
Definition notcurses.c:1761
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_scrollup_child()

int ncplane_scrollup_child ( ncplane n,
const ncplane child 
)

Definition at line 1816 of file notcurses.c.

1816 {
1817 if(!ncplane_descendant_p(child, n)){
1818 logerror("not a descendant of specified plane");
1819 return -1;
1820 }
1821 if(child->fixedbound){
1822 logerror("child plane is fixed");
1823 return -1;
1824 }
1825 int parend = ncplane_abs_y(n) + ncplane_dim_y(n) - 1; // where parent ends
1826 int chend = ncplane_abs_y(child) + ncplane_dim_y(child) - 1; // where child ends
1827 if(chend <= parend){
1828 return 0;
1829 }
1830 int r = chend - parend; // how many rows we need scroll parent
1831 ncplane_cursor_move_yx(n, ncplane_dim_y(n) - 1, 0);
1832 int ret = ncplane_scrollup(n, r);
1833 return ret;
1834}
int ncplane_scrollup(ncplane *n, int r)
Definition notcurses.c:1795
Here is the call graph for this function:

◆ ncplane_set_autogrow()

bool ncplane_set_autogrow ( ncplane n,
unsigned  growp 
)

Definition at line 3008 of file notcurses.c.

3008 {
3010 logerror("can't set the standard plane autogrow");
3011 return false;
3012 }
3013 bool old = n->autogrow;
3014 n->autogrow = growp;
3015 return old;
3016}
const ncplane * notcurses_stdplane_const(const notcurses *nc)
Definition notcurses.c:706
Here is the call graph for this function:

◆ ncplane_set_base()

int ncplane_set_base ( ncplane ncp,
const char *  egc,
uint16_t  stylemask,
uint64_t  channels 
)

Definition at line 1568 of file notcurses.c.

1568 {
1569 return nccell_prime(ncp, &ncp->basecell, egc, stylemask, channels);
1570}
Here is the caller graph for this function:

◆ ncplane_set_base_cell()

int ncplane_set_base_cell ( ncplane ncp,
const nccell c 
)

Definition at line 1561 of file notcurses.c.

1561 {
1562 if(nccell_wide_right_p(c)){
1563 return -1;
1564 }
1565 return nccell_duplicate(ncp, &ncp->basecell, c);
1566}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_set_bchannel()

uint64_t ncplane_set_bchannel ( ncplane n,
uint32_t  channel 
)

Definition at line 1533 of file notcurses.c.

1533 {
1534 return ncchannels_set_bchannel(&n->channels, channel);
1535}

◆ ncplane_set_bg_alpha()

int ncplane_set_bg_alpha ( ncplane n,
int  alpha 
)

Definition at line 1549 of file notcurses.c.

1549 {
1550 return ncchannels_set_bg_alpha(&n->channels, alpha);
1551}
Here is the caller graph for this function:

◆ ncplane_set_bg_default()

void ncplane_set_bg_default ( ncplane n)

Definition at line 1509 of file notcurses.c.

1509 {
1510 ncchannels_set_bg_default(&n->channels);
1511}
Here is the caller graph for this function:

◆ ncplane_set_bg_palindex()

int ncplane_set_bg_palindex ( ncplane n,
unsigned  idx 
)

Definition at line 1557 of file notcurses.c.

1557 {
1558 return ncchannels_set_bg_palindex(&n->channels, idx);
1559}
uint32_t idx
Definition egcpool.h:209

◆ ncplane_set_bg_rgb()

int ncplane_set_bg_rgb ( ncplane n,
unsigned  channel 
)

Definition at line 1541 of file notcurses.c.

1541 {
1542 return ncchannels_set_bg_rgb(&n->channels, channel);
1543}
Here is the caller graph for this function:

◆ ncplane_set_bg_rgb8()

int ncplane_set_bg_rgb8 ( ncplane n,
unsigned  r,
unsigned  g,
unsigned  b 
)

Definition at line 1517 of file notcurses.c.

1517 {
1518 return ncchannels_set_bg_rgb8(&n->channels, r, g, b);
1519}
Here is the caller graph for this function:

◆ ncplane_set_bg_rgb8_clipped()

void ncplane_set_bg_rgb8_clipped ( ncplane n,
int  r,
int  g,
int  b 
)

Definition at line 1513 of file notcurses.c.

1513 {
1514 ncchannels_set_bg_rgb8_clipped(&n->channels, r, g, b);
1515}
Here is the caller graph for this function:

◆ ncplane_set_channels()

void ncplane_set_channels ( ncplane n,
uint64_t  channels 
)

Definition at line 1497 of file notcurses.c.

1497 {
1498 ncchannels_set_channels(&n->channels, channels);
1499}
Here is the caller graph for this function:

◆ ncplane_set_fchannel()

uint64_t ncplane_set_fchannel ( ncplane n,
uint32_t  channel 
)

Definition at line 1537 of file notcurses.c.

1537 {
1538 return ncchannels_set_fchannel(&n->channels, channel);
1539}

◆ ncplane_set_fg_alpha()

int ncplane_set_fg_alpha ( ncplane n,
int  alpha 
)

Definition at line 1545 of file notcurses.c.

1545 {
1546 return ncchannels_set_fg_alpha(&n->channels, alpha);
1547}
Here is the caller graph for this function:

◆ ncplane_set_fg_default()

void ncplane_set_fg_default ( ncplane n)

Definition at line 1505 of file notcurses.c.

1505 {
1506 ncchannels_set_fg_default(&n->channels);
1507}
Here is the caller graph for this function:

◆ ncplane_set_fg_palindex()

int ncplane_set_fg_palindex ( ncplane n,
unsigned  idx 
)

Definition at line 1553 of file notcurses.c.

1553 {
1554 return ncchannels_set_fg_palindex(&n->channels, idx);
1555}
Here is the caller graph for this function:

◆ ncplane_set_fg_rgb()

int ncplane_set_fg_rgb ( ncplane n,
unsigned  channel 
)

Definition at line 1529 of file notcurses.c.

1529 {
1530 return ncchannels_set_fg_rgb(&n->channels, channel);
1531}
Here is the caller graph for this function:

◆ ncplane_set_fg_rgb8()

int ncplane_set_fg_rgb8 ( ncplane n,
unsigned  r,
unsigned  g,
unsigned  b 
)

Definition at line 1525 of file notcurses.c.

1525 {
1526 return ncchannels_set_fg_rgb8(&n->channels, r, g, b);
1527}
Here is the caller graph for this function:

◆ ncplane_set_fg_rgb8_clipped()

void ncplane_set_fg_rgb8_clipped ( ncplane n,
int  r,
int  g,
int  b 
)

Definition at line 1521 of file notcurses.c.

1521 {
1522 ncchannels_set_fg_rgb8_clipped(&n->channels, r, g, b);
1523}
Here is the caller graph for this function:

◆ ncplane_set_name()

int ncplane_set_name ( ncplane n,
const char *  name 
)

Definition at line 2664 of file notcurses.c.

2664 {
2665 char* copy = name ? strdup(name) : NULL;
2666 if(copy == NULL && name != NULL){
2667 return -1;
2668 }
2669 free(n->name);
2670 n->name = copy;
2671 return 0;
2672}

◆ ncplane_set_resizecb()

void ncplane_set_resizecb ( ncplane n,
int(*)(ncplane *)  resizecb 
)

Definition at line 2678 of file notcurses.c.

2678 {
2679 n->resizecb = resizecb;
2680}
Here is the caller graph for this function:

◆ ncplane_set_scrolling()

bool ncplane_set_scrolling ( ncplane n,
unsigned  scrollp 
)

Definition at line 2998 of file notcurses.c.

2998 {
2999 bool old = n->scrolling;
3000 n->scrolling = scrollp;
3001 return old;
3002}
Here is the caller graph for this function:

◆ ncplane_set_styles()

void ncplane_set_styles ( ncplane n,
unsigned  stylebits 
)

Definition at line 2077 of file notcurses.c.

2077 {
2078 n->stylemask = (stylebits & NCSTYLE_MASK);
2079}
Here is the caller graph for this function:

◆ ncplane_set_userptr()

void * ncplane_set_userptr ( ncplane n,
void *  opaque 
)

Definition at line 189 of file notcurses.c.

189 {
190 void* ret = n->userptr;
191 n->userptr = opaque;
192 return ret;
193}
Here is the caller graph for this function:

◆ ncplane_styles()

uint16_t ncplane_styles ( const ncplane n)

Definition at line 1501 of file notcurses.c.

1501 {
1502 return n->stylemask;
1503}
Here is the caller graph for this function:

◆ ncplane_translate()

void ncplane_translate ( const ncplane src,
const ncplane dst,
int *restrict  y,
int *restrict  x 
)

Definition at line 2618 of file notcurses.c.

2619 {
2620 if(dst == NULL){
2621 dst = ncplane_stdplane_const(src);
2622 }
2623 if(y){
2624 *y = src->absy - dst->absy + *y;
2625 }
2626 if(x){
2627 *x = src->absx - dst->absx + *x;
2628 }
2629}
Here is the caller graph for this function:

◆ ncplane_translate_abs()

bool ncplane_translate_abs ( const ncplane n,
int *restrict  y,
int *restrict  x 
)

Definition at line 2595 of file notcurses.c.

2595 {
2596 ncplane_translate(ncplane_stdplane_const(n), n, y, x);
2597 if(y){
2598 if(*y < 0){
2599 return false;
2600 }
2601 unsigned yval = *y;
2602 if(yval >= n->leny){
2603 return false;
2604 }
2605 }
2606 if(x){
2607 if(*x < 0){
2608 return false;
2609 }
2610 unsigned xval = *x;
2611 if(xval >= n->lenx){
2612 return false;
2613 }
2614 }
2615 return true;
2616}
void ncplane_translate(const ncplane *src, const ncplane *dst, int *restrict y, int *restrict x)
Definition notcurses.c:2618
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_userptr()

void * ncplane_userptr ( ncplane n)

Definition at line 195 of file notcurses.c.

195 {
196 return n->userptr;
197}
Here is the caller graph for this function:

◆ ncplane_userptr_const()

const void * ncplane_userptr_const ( const ncplane n)

Definition at line 199 of file notcurses.c.

199 {
200 return n->userptr;
201}

◆ ncplane_vline_interp()

int ncplane_vline_interp ( ncplane n,
const nccell c,
unsigned  len,
uint64_t  c1,
uint64_t  c2 
)

Definition at line 2215 of file notcurses.c.

2216 {
2217 if(len <= 0){
2218 logerror("passed invalid length %u", len);
2219 return -1;
2220 }
2221 unsigned ur, ug, ub;
2222 int r1, g1, b1, r2, g2, b2;
2223 int br1, bg1, bb1, br2, bg2, bb2;
2224 ncchannels_fg_rgb8(c1, &ur, &ug, &ub);
2225 r1 = ur; g1 = ug; b1 = ub;
2226 ncchannels_fg_rgb8(c2, &ur, &ug, &ub);
2227 r2 = ur; g2 = ug; b2 = ub;
2228 ncchannels_bg_rgb8(c1, &ur, &ug, &ub);
2229 br1 = ur; bg1 = ug; bb1 = ub;
2230 ncchannels_bg_rgb8(c2, &ur, &ug, &ub);
2231 br2 = ur; bg2 = ug; bb2 = ub;
2232 int deltr = (r2 - r1) / ((int)len + 1);
2233 int deltg = (g2 - g1) / ((int)len + 1);
2234 int deltb = (b2 - b1) / ((int)len + 1);
2235 int deltbr = (br2 - br1) / ((int)len + 1);
2236 int deltbg = (bg2 - bg1) / ((int)len + 1);
2237 int deltbb = (bb2 - bb1) / ((int)len + 1);
2238 unsigned ypos, xpos;
2239 unsigned ret;
2240 ncplane_cursor_yx(n, &ypos, &xpos);
2242 if(nccell_duplicate(n, &dupc, c) < 0){
2243 return -1;
2244 }
2245 bool fgdef = false, bgdef = false;
2246 if(ncchannels_fg_default_p(c1) && ncchannels_fg_default_p(c2)){
2247 fgdef = true;
2248 }
2249 if(ncchannels_bg_default_p(c1) && ncchannels_bg_default_p(c2)){
2250 bgdef = true;
2251 }
2252 for(ret = 0 ; ret < len ; ++ret){
2253 if(ncplane_cursor_move_yx(n, ypos + ret, xpos)){
2254 return -1;
2255 }
2256 r1 += deltr;
2257 g1 += deltg;
2258 b1 += deltb;
2259 br1 += deltbr;
2260 bg1 += deltbg;
2261 bb1 += deltbb;
2262 if(!fgdef){
2263 nccell_set_fg_rgb8(&dupc, r1, g1, b1);
2264 }
2265 if(!bgdef){
2266 nccell_set_bg_rgb8(&dupc, br1, bg1, bb1);
2267 }
2268 if(ncplane_putc(n, &dupc) <= 0){
2269 return -1;
2270 }
2271 }
2272 nccell_release(n, &dupc);
2273 return ret;
2274}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_vprintf_aligned()

int ncplane_vprintf_aligned ( ncplane n,
int  y,
ncalign_e  align,
const char *  format,
va_list  ap 
)

Definition at line 2131 of file notcurses.c.

2132 {
2133 char* r = ncplane_vprintf_prep(format, ap);
2134 if(r == NULL){
2135 return -1;
2136 }
2137 int ret = ncplane_putstr_aligned(n, y, align, r);
2138 free(r);
2139 return ret;
2140}
char * ncplane_vprintf_prep(const char *format, va_list ap)
Definition notcurses.c:2093
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_vprintf_prep()

char * ncplane_vprintf_prep ( const char *  format,
va_list  ap 
)

Definition at line 2093 of file notcurses.c.

2093 {
2094 const size_t size = BUFSIZ; // healthy estimate, can embiggen below
2095 char* buf = malloc(size);
2096 if(buf == NULL){
2097 return NULL;
2098 }
2099 va_list vacopy;
2100 va_copy(vacopy, ap);
2101 int ret = vsnprintf(buf, size, format, ap);
2102 if(ret < 0){
2103 free(buf);
2104 va_end(vacopy);
2105 return NULL;
2106 }
2107 if((size_t)ret >= size){
2108 char* tmp = realloc(buf, ret + 1);
2109 if(tmp == NULL){
2110 free(buf);
2111 va_end(vacopy);
2112 return NULL;
2113 }
2114 buf = tmp;
2115 vsprintf(buf, format, vacopy);
2116 }
2117 va_end(vacopy);
2118 return buf;
2119}
va_end(va)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_vprintf_stained()

int ncplane_vprintf_stained ( struct ncplane n,
const char *  format,
va_list  ap 
)

Definition at line 2142 of file notcurses.c.

2142 {
2143 char* r = ncplane_vprintf_prep(format, ap);
2144 if(r == NULL){
2145 return -1;
2146 }
2147 int ret = ncplane_putstr_stained(n, r);
2148 free(r);
2149 return ret;
2150}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_vprintf_yx()

int ncplane_vprintf_yx ( ncplane n,
int  y,
int  x,
const char *  format,
va_list  ap 
)

Definition at line 2121 of file notcurses.c.

2121 {
2122 char* r = ncplane_vprintf_prep(format, ap);
2123 if(r == NULL){
2124 return -1;
2125 }
2126 int ret = ncplane_putstr_yx(n, y, x, r);
2127 free(r);
2128 return ret;
2129}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_x()

int ncplane_x ( const ncplane n)

Definition at line 2447 of file notcurses.c.

2447 {
2448 if(n->boundto == n){
2449 return n->absx;
2450 }
2451 return n->absx - n->boundto->absx;
2452}
Here is the caller graph for this function:

◆ ncplane_y()

int ncplane_y ( const ncplane n)

Definition at line 2440 of file notcurses.c.

2440 {
2441 if(n->boundto == n){
2442 return n->absy;
2443 }
2444 return n->absy - n->boundto->absy;
2445}
Here is the caller graph for this function:

◆ ncplane_yx()

void ncplane_yx ( const ncplane n,
int *  y,
int *  x 
)

Definition at line 2454 of file notcurses.c.

2454 {
2455 if(y){
2456 *y = ncplane_y(n);
2457 }
2458 if(x){
2459 *x = ncplane_x(n);
2460 }
2461}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncstrwidth()

int ncstrwidth ( const char *  egcs,
int *  validbytes,
int *  validwidth 
)

Definition at line 3311 of file notcurses.c.

3311 {
3312 int cols;
3313 if(validwidth == NULL){
3314 validwidth = &cols;
3315 }
3316 *validwidth = 0;
3317 int bytes;
3318 if(validbytes == NULL){
3319 validbytes = &bytes;
3320 }
3321 *validbytes = 0;
3322 do{
3323 int thesecols, thesebytes;
3324 thesebytes = utf8_egc_len(egcs, &thesecols);
3325 if(thesebytes < 0){
3326 return -1;
3327 }
3328 egcs += thesebytes;
3329 *validbytes += thesebytes;
3330 *validwidth += thesecols;
3331 }while(*egcs);
3332 return *validwidth;
3333}
Here is the caller graph for this function:

◆ notcurses_capabilities()

const nccapabilities * notcurses_capabilities ( const notcurses n)

Definition at line 3376 of file notcurses.c.

3376 {
3377 return &n->tcache.caps;
3378}

◆ notcurses_check_pixel_support()

ncpixelimpl_e notcurses_check_pixel_support ( const notcurses nc)

Definition at line 1156 of file notcurses.c.

1156 {
1157 if(nc->tcache.cellpxy == 0 || nc->tcache.cellpxx == 0){
1158 return NCPIXEL_NONE;
1159 }
1160 return nc->tcache.pixel_implementation;
1161}
@ NCPIXEL_NONE
Definition notcurses.h:1673
ncpixelimpl_e pixel_implementation
Definition termdesc.h:134
unsigned cellpxx
Definition termdesc.h:117
unsigned cellpxy
Definition termdesc.h:116
Here is the caller graph for this function:

◆ notcurses_core_init()

notcurses * notcurses_core_init ( const notcurses_options opts,
FILE *  outfp 
)

Definition at line 1245 of file notcurses.c.

1245 {
1246 if(outfp == NULL){
1247 outfp = stdout;
1248 }
1249 unsigned utf8;
1250 // ret comes out entirely zero-initialized
1251 notcurses* ret = notcurses_early_init(opts, outfp, &utf8);
1252 if(ret == NULL){
1253 return NULL;
1254 }
1255 // the fbuf is needed by notcurses_stop_minimal, so this must be done
1256 // before registering fatal signal handlers.
1257 if(fbuf_init(&ret->rstate.f)){
1258 pthread_mutex_destroy(&ret->pilelock);
1259 pthread_mutex_destroy(&ret->stats.lock);
1260 free(ret);
1261 return NULL;
1262 }
1265 notcurses_stop_minimal)){
1266 fbuf_free(&ret->rstate.f);
1267 pthread_mutex_destroy(&ret->pilelock);
1268 pthread_mutex_destroy(&ret->stats.lock);
1269 free(ret);
1270 return NULL;
1271 }
1272 // don't set loglevel until we've acquired the signal handler, lest we
1273 // change the loglevel out from under a running instance
1274 loglevel = ret->loglevel;
1275 ret->rstate.logendy = -1;
1276 ret->rstate.logendx = -1;
1277 ret->rstate.x = ret->rstate.y = -1;
1278 int fakecursory = ret->rstate.logendy;
1279 int fakecursorx = ret->rstate.logendx;
1280 int* cursory = ret->flags & NCOPTION_PRESERVE_CURSOR ?
1281 &ret->rstate.logendy : &fakecursory;
1282 int* cursorx = ret->flags & NCOPTION_PRESERVE_CURSOR ?
1283 &ret->rstate.logendx : &fakecursorx;
1284 if(interrogate_terminfo(&ret->tcache, ret->ttyfp, utf8,
1287 cursory, cursorx, &ret->stats,
1288 ret->margin_l, ret->margin_t,
1289 ret->margin_r, ret->margin_b,
1290 ret->flags & NCOPTION_DRAIN_INPUT)){
1291 void* altstack;
1292 fbuf_free(&ret->rstate.f);
1293 pthread_mutex_destroy(&ret->pilelock);
1294 pthread_mutex_destroy(&ret->stats.lock);
1295 drop_signals(ret, &altstack);
1296 free(ret);
1297 free(altstack);
1298 return NULL;
1299 }
1300 if(ret->tcache.maxpaletteread > -1){
1301 memcpy(ret->palette.chans, ret->tcache.originalpalette.chans,
1302 sizeof(*ret->palette.chans) * (ret->tcache.maxpaletteread + 1));
1303 }
1304 if((ret->flags & NCOPTION_PRESERVE_CURSOR) ||
1305 (!(ret->flags & NCOPTION_SUPPRESS_BANNERS))){
1306 // the u7 led the queries so that we would get a cursor position
1307 // unaffected by any query spill (unconsumed control sequences). move
1308 // us back to that location, in case there was any such spillage.
1309 if(*cursory < 0 || *cursorx < 0){
1310 unsigned cy, cx;
1311 if(locate_cursor(&ret->tcache, &cy, &cx)){
1312 logwarn("couldn't preserve cursor");
1313 }else{
1314 *cursory = cy;
1315 *cursorx = cx;
1316 }
1317 }
1318 if(*cursory >= 0 && *cursorx >= 0){
1319 if(goto_location(ret, &ret->rstate.f, *cursory, *cursorx, NULL)){
1320 goto err;
1321 }
1322 }
1323 }
1324 unsigned dimy, dimx, cgeo, pgeo; // latter two are don't-cares
1325 if(update_term_dimensions(&dimy, &dimx, &ret->tcache, ret->margin_b, &cgeo, &pgeo)){
1326 goto err;
1327 }
1328 if(ncvisual_init(ret->loglevel)){
1329 goto err;
1330 }
1331 ret->stdplane = NULL;
1332 if((ret->stdplane = create_initial_ncplane(ret, dimy, dimx)) == NULL){
1333 logpanic("couldn't create the initial plane (bad margins?)");
1334 goto err;
1335 }
1336 if(ret->flags & NCOPTION_SCROLLING){
1337 ncplane_set_scrolling(ret->stdplane, true);
1338 }
1339 reset_term_attributes(&ret->tcache, &ret->rstate.f);
1340 const char* cinvis = get_escape(&ret->tcache, ESCAPE_CIVIS);
1341 if(cinvis && fbuf_emit(&ret->rstate.f, cinvis) < 0){
1342 free_plane(ret->stdplane);
1343 goto err;
1344 }
1345 const char* pushcolors = get_escape(&ret->tcache, ESCAPE_SAVECOLORS);
1346 if(pushcolors && fbuf_emit(&ret->rstate.f, pushcolors)){
1347 free_plane(ret->stdplane);
1348 goto err;
1349 }
1350 init_banner(ret, &ret->rstate.f);
1351 if(fbuf_flush(&ret->rstate.f, ret->ttyfp) < 0){
1352 free_plane(ret->stdplane);
1353 goto err;
1354 }
1355 if(ret->rstate.logendy >= 0){ // if either is set, both are
1356 if(!(ret->flags & NCOPTION_SUPPRESS_BANNERS) && ret->tcache.ttyfd >= 0){
1357 unsigned uendy, uendx;
1358 if(locate_cursor(&ret->tcache, &uendy, &uendx)){
1359 free_plane(ret->stdplane);
1360 goto err;
1361 }
1362 ret->rstate.logendy = uendy;
1363 ret->rstate.logendx = uendx;
1364 }
1367 }
1368 }
1369 if(!(ret->flags & NCOPTION_NO_ALTERNATE_SCREEN)){
1370 // perform an explicit clear since the alternate screen was requested
1371 // (smcup *might* clear, but who knows? and it might not have been
1372 // available in any case).
1373 if(clear_and_home(ret, &ret->tcache, &ret->rstate.f)){
1374 goto err;
1375 }
1376 // no need to reestablish a preserved cursor -- that only affects the
1377 // standard plane, not the physical cursor that was just disrupted.
1378 }
1379 // the sprite clear ought take place within the alternate screen, if it's
1380 // being used.
1381 if(!(ret->flags & NCOPTION_NO_CLEAR_BITMAPS)){
1382 if(sprite_clear_all(&ret->tcache, &ret->rstate.f)){
1383 goto err;
1384 }
1385 }
1386 if(ret->rstate.f.used){
1387 if(fbuf_flush(&ret->rstate.f, ret->ttyfp) < 0){
1388 goto err;
1389 }
1390 }
1391 return ret;
1392
1393err:{
1394 void* altstack;
1395 logpanic("alas, you will not be going to space today.");
1396 notcurses_stop_minimal(ret, &altstack, -1);
1397 fbuf_free(&ret->rstate.f);
1398 if(ret->tcache.ttyfd >= 0 && ret->tcache.tpreserved){
1399 (void)tcsetattr(ret->tcache.ttyfd, TCSAFLUSH, ret->tcache.tpreserved);
1400 free(ret->tcache.tpreserved);
1401 }
1402 del_curterm(cur_term);
1403 pthread_mutex_destroy(&ret->stats.lock);
1404 pthread_mutex_destroy(&ret->pilelock);
1405 free(ret);
1406 free(altstack);
1407 return NULL;
1408 }
1409}
int init_banner(const notcurses *nc, fbuf *f)
Definition banner.c:27
ncloglevel_e loglevel
Definition debug.c:3
int ncvisual_init(int loglevel)
Definition visual.c:23
int sprite_clear_all(const tinfo *t, fbuf *f)
Definition sprite.c:204
int clear_and_home(notcurses *nc, tinfo *ti, fbuf *f)
Definition render.c:1399
#define logpanic(fmt,...)
Definition logging.h:22
int update_term_dimensions(unsigned *rows, unsigned *cols, tinfo *tcache, int margin_b, unsigned *cgeo_changed, unsigned *pgeo_changed)
Definition notcurses.c:319
bool ncplane_set_scrolling(ncplane *n, unsigned scrollp)
Definition notcurses.c:2998
int reset_term_attributes(const tinfo *ti, fbuf *f)
Definition notcurses.c:60
#define NCOPTION_SUPPRESS_BANNERS
Definition notcurses.h:1015
#define NCOPTION_NO_CLEAR_BITMAPS
Definition notcurses.h:996
#define NCOPTION_DRAIN_INPUT
Definition notcurses.h:1030
#define NCOPTION_PRESERVE_CURSOR
Definition notcurses.h:1011
#define NCOPTION_NO_QUIT_SIGHANDLERS
Definition notcurses.h:1005
#define NCOPTION_NO_WINCH_SIGHANDLER
Definition notcurses.h:1000
#define NCOPTION_NO_ALTERNATE_SCREEN
Definition notcurses.h:1019
#define NCOPTION_NO_FONT_CHANGES
Definition notcurses.h:1025
uint64_t used
Definition fbuf.h:27
rasterstate rstate
Definition internal.h:336
int maxpaletteread
Definition termdesc.h:193
ncpalette originalpalette
Definition termdesc.h:192
struct termios * tpreserved
Definition termdesc.h:180
int ttyfd
Definition termdesc.h:109
int locate_cursor(tinfo *ti, unsigned *cursor_y, unsigned *cursor_x)
Definition termdesc.c:1581
int interrogate_terminfo(tinfo *ti, FILE *out, unsigned utf8, unsigned noaltscreen, unsigned nocbreak, unsigned nonewfonts, int *cursor_y, int *cursor_x, ncsharedstats *stats, int lmargin, int tmargin, int rmargin, int bmargin, unsigned draininput)
Definition termdesc.c:1317
@ ESCAPE_CIVIS
Definition termdesc.h:54
@ ESCAPE_SAVECOLORS
Definition termdesc.h:87
int setup_signals(void *vnc, bool no_quit_sigs, bool no_winch_sigs, int(*handler)(void *, void **, int))
Definition unixsig.c:195
int drop_signals(void *nc, void **altstack)
Definition unixsig.c:104
Here is the call graph for this function:

◆ notcurses_detected_terminal()

char * notcurses_detected_terminal ( const notcurses nc)

Definition at line 2072 of file notcurses.c.

2072 {
2073 return termdesc_longterm(&nc->tcache);
2074}
char * termdesc_longterm(const tinfo *ti)
Definition termdesc.c:1558
Here is the call graph for this function:

◆ notcurses_drop_planes()

void notcurses_drop_planes ( notcurses nc)

Definition at line 1437 of file notcurses.c.

1437 {
1438 logdebug("we have some planes");
1439 pthread_mutex_lock(&nc->pilelock);
1440 ncpile* p = ncplane_pile(nc->stdplane);
1441 ncpile* p0 = p;
1442 do{
1443 ncpile_drop(nc, &p);
1444 }while(p0 != p);
1445 pthread_mutex_unlock(&nc->pilelock);
1446 logdebug("all planes dropped");
1447}
Here is the caller graph for this function:

◆ notcurses_enter_alternate_screen()

int notcurses_enter_alternate_screen ( notcurses nc)

Definition at line 31 of file notcurses.c.

31 {
32 if(nc->tcache.ttyfd < 0){
33 return -1;
34 }
36 return -1;
37 }
39 return 0;
40}
int enter_alternate_screen(int fd, FILE *ttyfp, tinfo *ti, unsigned drain)
Definition termdesc.c:559
Here is the call graph for this function:

◆ notcurses_inputready_fd()

int notcurses_inputready_fd ( notcurses n)

Definition at line 3096 of file notcurses.c.

3096 {
3097 return inputready_fd(n->tcache.ictx);
3098}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ notcurses_leave_alternate_screen()

int notcurses_leave_alternate_screen ( notcurses nc)

Definition at line 42 of file notcurses.c.

42 {
43 if(nc->tcache.ttyfd < 0){
44 return -1;
45 }
47 &nc->tcache, nc->flags & NCOPTION_DRAIN_INPUT)){
48 return -1;
49 }
50 // move to the end of our output
51 if(nc->rstate.logendy < 0){
52 return 0;
53 }
55 return 0;
56}
int leave_alternate_screen(int fd, FILE *fp, tinfo *ti, unsigned drain)
Definition termdesc.c:611
Here is the call graph for this function:

◆ notcurses_lex_margins()

int notcurses_lex_margins ( const char *  op,
notcurses_options opts 
)

Definition at line 3072 of file notcurses.c.

3072 {
3073 char* eptr;
3074 if(lex_ulong(op, &opts->margin_t, &eptr)){
3075 return -1;
3076 }
3077 if(!*eptr){ // allow a single value to be specified for all four margins
3078 opts->margin_r = opts->margin_l = opts->margin_b = opts->margin_t;
3079 return 0;
3080 }
3081 op = ++eptr; // once here, we require four values
3082 if(lex_ulong(op, &opts->margin_r, &eptr) || !*eptr){
3083 return -1;
3084 }
3085 op = ++eptr;
3086 if(lex_ulong(op, &opts->margin_b, &eptr) || !*eptr){
3087 return -1;
3088 }
3089 op = ++eptr;
3090 if(lex_ulong(op, &opts->margin_l, &eptr) || *eptr){ // must end in NUL
3091 return -1;
3092 }
3093 return 0;
3094}
Here is the caller graph for this function:

◆ notcurses_lex_scalemode()

int notcurses_lex_scalemode ( const char *  op,
ncscale_e scalemode 
)

Definition at line 3040 of file notcurses.c.

3040 {
3041 if(strcasecmp(op, "stretch") == 0){
3042 *scalemode = NCSCALE_STRETCH;
3043 }else if(strcasecmp(op, "scalehi") == 0){
3044 *scalemode = NCSCALE_SCALE_HIRES;
3045 }else if(strcasecmp(op, "hires") == 0){
3046 *scalemode = NCSCALE_NONE_HIRES;
3047 }else if(strcasecmp(op, "scale") == 0){
3048 *scalemode = NCSCALE_SCALE;
3049 }else if(strcasecmp(op, "none") == 0){
3050 *scalemode = NCSCALE_NONE;
3051 }else{
3052 return -1;
3053 }
3054 return 0;
3055}
@ 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
Here is the caller graph for this function:

◆ notcurses_mice_enable()

int notcurses_mice_enable ( notcurses n,
unsigned  eventmask 
)

Definition at line 2561 of file notcurses.c.

2561 {
2562 if(mouse_setup(&n->tcache, eventmask)){
2563 return -1;
2564 }
2565 return 0;
2566}
int mouse_setup(tinfo *ti, unsigned eventmask)
Definition mice.c:3
Here is the call graph for this function:
Here is the caller graph for this function:

◆ notcurses_palette_size()

unsigned notcurses_palette_size ( const notcurses nc)

Definition at line 2068 of file notcurses.c.

2068 {
2069 return nc->tcache.caps.colors;
2070}
unsigned colors
Definition notcurses.h:1637
nccapabilities caps
Definition termdesc.h:111
Here is the caller graph for this function:

◆ notcurses_stdplane()

ncplane * notcurses_stdplane ( notcurses nc)

Definition at line 702 of file notcurses.c.

702 {
703 return nc->stdplane;
704}
Here is the caller graph for this function:

◆ notcurses_stdplane_const()

const ncplane * notcurses_stdplane_const ( const notcurses nc)

Definition at line 706 of file notcurses.c.

706 {
707 return nc->stdplane;
708}
Here is the caller graph for this function:

◆ notcurses_stop()

int notcurses_stop ( notcurses nc)

Definition at line 1449 of file notcurses.c.

1449 {
1450 logdebug("stopping notcurses");
1451//notcurses_debug(nc, stderr);
1452 int ret = 0;
1453 if(nc){
1454 void* altstack;
1455 ret |= notcurses_stop_minimal(nc, &altstack, 0);
1456 // if we were not using the alternate screen, our cursor's wherever we last
1457 // wrote. move it to the furthest place to which it advanced.
1458 if(!get_escape(&nc->tcache, ESCAPE_SMCUP)){
1459 fbuf_reset(&nc->rstate.f);
1460//fprintf(stderr, "CLOSING TO %d/%d\n", nc->rstate.logendy, nc->rstate.logendx);
1461 goto_location(nc, &nc->rstate.f, nc->rstate.logendy, nc->rstate.logendx, NULL);
1462//fprintf(stderr, "***"); fflush(stderr);
1463 fbuf_finalize(&nc->rstate.f, stdout);
1464 }
1465 if(nc->stdplane){
1467 free_plane(nc->stdplane);
1468 }
1469 if(nc->tcache.ttyfd >= 0){
1470 ret |= close(nc->tcache.ttyfd);
1471 }
1472 egcpool_dump(&nc->pool);
1473 free(nc->lastframe);
1474 // perhaps surprisingly, this stops the input thread
1476 // get any current stats loaded into stash_stats
1478 if(!(nc->flags & NCOPTION_SUPPRESS_BANNERS)){
1479 summarize_stats(nc);
1480 }
1481#ifndef __MINGW32__
1482 del_curterm(cur_term);
1483#endif
1484 ret |= pthread_mutex_destroy(&nc->stats.lock);
1485 ret |= pthread_mutex_destroy(&nc->pilelock);
1486 fbuf_free(&nc->rstate.f);
1487 free(nc);
1488 free(altstack);
1489 }
1490 return ret;
1491}
void summarize_stats(notcurses *nc)
Definition stats.c:166
void notcurses_drop_planes(notcurses *nc)
Definition notcurses.c:1437
void notcurses_stats_reset(notcurses *nc, ncstats *stats)
Definition stats.c:100
nccell * lastframe
Definition internal.h:341
void free_terminfo_cache(tinfo *ti)
Definition termdesc.c:197
@ ESCAPE_SMCUP
Definition termdesc.h:68
Here is the call graph for this function:

◆ notcurses_str_scalemode()

const char * notcurses_str_scalemode ( ncscale_e  scalemode)

Definition at line 3057 of file notcurses.c.

3057 {
3058 if(scalemode == NCSCALE_STRETCH){
3059 return "stretch";
3060 }else if(scalemode == NCSCALE_SCALE){
3061 return "scale";
3062 }else if(scalemode == NCSCALE_NONE){
3063 return "none";
3064 }else if(scalemode == NCSCALE_NONE_HIRES){
3065 return "hires";
3066 }else if(scalemode == NCSCALE_SCALE_HIRES){
3067 return "scalehi";
3068 }
3069 return NULL;
3070}
Here is the caller graph for this function:

◆ notcurses_supported_styles()

uint16_t notcurses_supported_styles ( const notcurses nc)

Definition at line 2064 of file notcurses.c.

2064 {
2065 return term_supported_styles(&nc->tcache);
2066}
Here is the caller graph for this function:

◆ notcurses_ucs32_to_utf8()

int notcurses_ucs32_to_utf8 ( const uint32_t *  ucs32,
unsigned  ucs32count,
unsigned char *  resultbuf,
size_t  buflen 
)

Definition at line 3303 of file notcurses.c.

3304 {
3305 if(u32_to_u8(ucs32, ucs32count, resultbuf, &buflen) == NULL){
3306 return -1;
3307 }
3308 return buflen;
3309}
Here is the caller graph for this function:

◆ notcurses_version()

const char * notcurses_version ( void  )

Definition at line 185 of file notcurses.c.

185 {
186 return NOTCURSES_VERSION;
187}
Here is the caller graph for this function:

◆ notcurses_version_components()

void notcurses_version_components ( int *  major,
int *  minor,
int *  patch,
int *  tweak 
)

Definition at line 24 of file notcurses.c.

24 {
25 *major = NOTCURSES_VERNUM_MAJOR;
26 *minor = NOTCURSES_VERNUM_MINOR;
27 *patch = NOTCURSES_VERNUM_PATCH;
28 *tweak = atoi(NOTCURSES_VERSION_TWEAK);
29}
Here is the caller graph for this function:

◆ reset_term_attributes()

int reset_term_attributes ( const tinfo ti,
fbuf f 
)

Definition at line 60 of file notcurses.c.

60 {
61 int ret = 0;
62 const char* esc;
63 if((esc = get_escape(ti, ESCAPE_OP)) && fbuf_emit(f, esc)){
64 ret = -1;
65 }
66 if((esc = get_escape(ti, ESCAPE_SGR0)) && fbuf_emit(f, esc)){
67 ret = -1;
68 }
69 return ret;
70}
@ ESCAPE_OP
Definition termdesc.h:50
@ ESCAPE_SGR0
Definition termdesc.h:53
Here is the caller graph for this function:

◆ reset_term_palette()

int reset_term_palette ( const tinfo ti,
fbuf f,
unsigned  touchedpalette 
)

Definition at line 78 of file notcurses.c.

78 {
79 int ret = 0;
80 const char* esc;
81 if((esc = get_escape(ti, ESCAPE_RESTORECOLORS))){
82 loginfo("restoring palette via xtpopcolors");
83 if(fbuf_emit(f, esc)){
84 ret = -1;
85 }
86 return ret;
87 }
88 if(!touchedpalette){
89 return 0;
90 }
91 if(ti->caps.can_change_colors && ti->maxpaletteread > -1){
92 loginfo("restoring saved palette (%d)", ti->maxpaletteread + 1);
93 esc = get_escape(ti, ESCAPE_INITC);
94 for(int z = 0 ; z < ti->maxpaletteread ; ++z){
95 unsigned r, g, b;
96 ncchannel_rgb8(ti->originalpalette.chans[z], &r, &g, &b);
97 // Need convert RGB values [0..256) to [0..1000], ugh
98 r = r * 1000 / 255;
99 g = g * 1000 / 255;
100 b = b * 1000 / 255;
101 if(fbuf_emit(f, tiparm(esc, z, r, g, b)) < 0){
102 return -1;
103 }
104 }
105 }else if((esc = get_escape(ti, ESCAPE_OC))){
106 loginfo("resetting palette");
107 if(fbuf_emit(f, esc)){
108 ret = -1;
109 }
110 }else{
111 logwarn("no method known to restore palette");
112 }
113 return ret;
114}
bool can_change_colors
Definition notcurses.h:1640
@ ESCAPE_RESTORECOLORS
Definition termdesc.h:88
@ ESCAPE_OC
Definition termdesc.h:56
@ ESCAPE_INITC
Definition termdesc.h:81

◆ resize_callbacks_children()

int resize_callbacks_children ( ncplane n)

Definition at line 804 of file notcurses.c.

804 {
805 int ret = 0;
806 for(struct ncplane* child = n->blist ; child ; child = child->bnext){
807 if(child->resizecb){
808 ret |= child->resizecb(child);
809 }
810 }
811 return ret;
812}
Here is the caller graph for this function:

◆ scroll_down()

void scroll_down ( ncplane n)

Definition at line 1761 of file notcurses.c.

1761 {
1762//fprintf(stderr, "pre-scroll: %d/%d %d/%d log: %d scrolling: %u\n", n->y, n->x, n->leny, n->lenx, n->logrow, n->scrolling);
1763 n->x = 0;
1764 if(n->y == n->leny - 1){
1765 // we're on the last line of the plane
1766 if(n->autogrow){
1767 ncplane_resize_simple(n, n->leny + 1, n->lenx);
1768 ncplane_cursor_move_yx(n, n->leny - 1, 0);
1769 return;
1770 }
1771 // we'll actually be scrolling material up and out, and making a new line.
1772 // if this is the standard plane, that means a "physical" scroll event is
1773 // called for.
1775 ncplane_pile(n)->scrolls++;
1776 }
1777 n->logrow = (n->logrow + 1) % n->leny;
1778 nccell* row = n->fb + nfbcellidx(n, n->y, 0);
1779 for(unsigned clearx = 0 ; clearx < n->lenx ; ++clearx){
1780 nccell_release(n, &row[clearx]);
1781 }
1782 memset(row, 0, sizeof(*row) * n->lenx);
1783 for(struct ncplane* c = n->blist ; c ; c = c->bnext){
1784 if(!c->fixedbound){
1785 if(ncplanes_intersect_p(n, c)){
1786 ncplane_move_rel(c, -1, 0);
1787 }
1788 }
1789 }
1790 }else{
1791 ++n->y;
1792 }
1793}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_term_dimensions()

int update_term_dimensions ( unsigned *  rows,
unsigned *  cols,
tinfo tcache,
int  margin_b,
unsigned *  cgeo_changed,
unsigned *  pgeo_changed 
)

Definition at line 319 of file notcurses.c.

320 {
321 *pgeo_changed = 0;
322 *cgeo_changed = 0;
323 // if we're not a real tty, we presumably haven't changed geometry, return
324 if(tcache->ttyfd < 0){
325 if(rows){
326 *rows = tcache->default_rows;
327 }
328 if(cols){
329 *cols = tcache->default_cols;
330 }
331 tcache->cellpxy = 0;
332 tcache->cellpxx = 0;
333 return 0;
334 }
335 unsigned rowsafe, colsafe;
336 if(rows == NULL){
337 rows = &rowsafe;
338 rowsafe = tcache->dimy;
339 }
340 if(cols == NULL){
341 cols = &colsafe;
342 colsafe = tcache->dimx;
343 }
344#ifndef __MINGW32__
345 struct winsize ws;
346 if(tiocgwinsz(tcache->ttyfd, &ws)){
347 return -1;
348 }
349 *rows = ws.ws_row;
350 *cols = ws.ws_col;
351 unsigned cpixy;
352 unsigned cpixx;
353#ifdef __linux__
354 if(tcache->linux_fb_fd >= 0){
355 get_linux_fb_pixelgeom(tcache, &tcache->pixy, &tcache->pixx);
356 cpixy = tcache->pixy / *rows;
357 cpixx = tcache->pixx / *cols;
358 }else{
359#else
360 {
361#endif
362 // we might have the pixel geometry from CSI14t, so don't override a valid
363 // earlier response with 0s from the ioctl. we do want to fire off a fresh
364 // CSI14t in this case, though FIXME.
365 if(ws.ws_ypixel){
366 tcache->pixy = ws.ws_ypixel;
367 tcache->pixx = ws.ws_xpixel;
368 }
369 // update even if we didn't get values just now, because we need set
370 // cellpx{y,x} up from an initial CSI14n, which set only pix{y,x}.
371 cpixy = ws.ws_row ? tcache->pixy / ws.ws_row : 0;
372 cpixx = ws.ws_col ? tcache->pixx / ws.ws_col : 0;
373 }
374 if(tcache->cellpxy != cpixy){
375 tcache->cellpxy = cpixy;
376 *pgeo_changed = 1;
377 }
378 if(tcache->cellpxx != cpixx){
379 tcache->cellpxx = cpixx;
380 *pgeo_changed = 1;
381 }
382 if(tcache->cellpxy == 0 || tcache->cellpxx == 0){
383 tcache->pixel_draw = NULL; // disable support
384 }
385#else
386 CONSOLE_SCREEN_BUFFER_INFO csbi;
387 // There is the buffer itself, which is similar in function to the scrollback
388 // buffer in a Linux terminal, and there is the display window, which is the
389 // visible view of that buffer. The addressable area (from a VT point of
390 // view) spans the width of the buffer, but the height of the display window.
391 //
392 // +--------------------------+ ^
393 // | | |
394 // | | |
395 // +-----+--------------+-----+ ^ w | b
396 // |XXXXX|XXXXXXXXXXXXXX|XXXXX| | i | u
397 // |XXXXX|XXXXXXXXXXXXXX|XXXXX| | n | f
398 // |XXXXX|XXXXXXXXXXXXXX|XXXXX| | d | f
399 // |XXXXX|XXXXXXXXXXXXXX|XXXXX| | o | e
400 // +-----+--------------+-----+ v w | r
401 // | | |
402 // | | |
403 // +--------------------------+ v
404 //
405 // <--- window --->
406 //
407 //<--------- buffer --------->
408 //
409 // Because the buffer extends past the bottom of the display window, a user
410 // can potentially scroll down beyond what would normally be thought of as the
411 // end of the buffer. Because the buffer can be wider than the display
412 // window, the user can scroll horizontally to view parts of the addressable
413 // area that aren't currently visible.
414 if(GetConsoleScreenBufferInfo(tcache->outhandle, &csbi)){
415 *cols = csbi.dwSize.X;
416 *rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
417 }else{
418 *rows = tcache->default_rows;
419 *cols = tcache->default_cols;
420 }
421#endif
422 if(tcache->dimy != *rows){
423 tcache->dimy = *rows;
424 *cgeo_changed = 1;
425 }
426 if(tcache->dimx != *cols){
427 tcache->dimx = *cols;
428 *cgeo_changed = 1;
429 }
430 if(tcache->sixel_maxy_pristine){
431 int sixelrows = *rows - 1;
432 // if the bottom margin is at least one row, we can draw into the last
433 // row of our visible area. we must leave the true bottom row alone.
434 if(margin_b){
435 ++sixelrows;
436 }
437 tcache->sixel_maxy = sixelrows * tcache->cellpxy;
438 if(tcache->sixel_maxy > tcache->sixel_maxy_pristine){
439 tcache->sixel_maxy = tcache->sixel_maxy_pristine;
440 }
441 }
442 return 0;
443}
int get_linux_fb_pixelgeom(tinfo *ti, unsigned *ypix, unsigned *xpix)
Definition linux.c:813
unsigned pixx
Definition termdesc.h:113
unsigned pixy
Definition termdesc.h:112
unsigned dimx
Definition termdesc.h:118
int default_rows
Definition termdesc.h:189
int(* pixel_draw)(const struct tinfo *, const struct ncpile *p, struct sprixel *s, fbuf *f, int y, int x)
Definition termdesc.h:147
unsigned dimy
Definition termdesc.h:118
unsigned sixel_maxy_pristine
Definition termdesc.h:173
int default_cols
Definition termdesc.h:190
int tiocgwinsz(int fd, struct winsize *ws)
Definition termdesc.c:1599
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ ncplane_resizecb

int(*)(ncplane *) ncplane_resizecb(const ncplane *n) ( const ncplane n)

Definition at line 2682 of file notcurses.c.

2682 {
2683 return n->resizecb;
2684}