2
3
4
5
6
7
10#define _XOPEN_SOURCE_EXTENDED 1
56const wchar_t *
bw_ra = L"\x2192";
57const wchar_t *
bw_la = L"\x2190";
58const wchar_t *
bw_ua = L"\x2191";
59const wchar_t *
bw_da = L"\x2193";
65STDRGB
std_color[] = {{0, 0, 0}, {128, 0, 0}, {0, 128, 0}, {128, 128, 0}, {0, 0, 128}, {128, 0, 128}, {0, 128, 128}, {192, 192, 192}, {128, 128, 128}, {255, 0, 0}, {0, 255, 0}, {255, 255, 0}, {0, 0, 255}, {255, 0, 255}, {0, 255, 255}, {255, 255, 255}};
68
69
78 memset(caps, 0,
sizeof(*caps));
90
91
93 setlocale(LC_ALL,
"");
94 ui = calloc(1,
sizeof(*
ui));
99 strncpy(tty_name, cfg
->tty_path,
sizeof(tty_name) - 1);
100 tty_name[
sizeof(tty_name) - 1] =
'\0';
102 if (ttyname_r(STDIN_FILENO, tty_name,
103 sizeof(tty_name)) != 0) {
116 .flags = NCOPTION_SUPPRESS_BANNERS |
117 NCOPTION_NO_QUIT_SIGHANDLERS
148 notcurses_mice_enable(
ui->nc, NCMICE_ALL_EVENTS);
150 notcurses_cursor_disable(
ui->nc);
227 notcurses_mice_disable(
ui->nc);
236
237
239UiSurface *
ui_surface_new(uint w, UiSurface *parent, uint p, uint lines, uint cols, uint y, uint x) {
242 UiSurface *s = calloc(1,
sizeof(*s));
247 ncplane_options plane_opts = {
257 if (parent && parent->mplane[p]) {
258 s->mplane[w] = ncplane_create(parent->mplane[p], &plane_opts);
261 s->mplane[w] = ncplane_create(
stdplane, &plane_opts);
271UiSurface *
ui_box_surface_new(UiSurface *parent, uint p, uint lines, uint cols, uint y, uint x,
char *wtitle) {
274 UiSurface *s = calloc(1,
sizeof(*s));
279 ncplane_options plane_opts = {
291 if (parent && parent->mplane[p]) {
292 s->mplane[
BOX] = ncplane_create(parent->mplane[p], &plane_opts);
295 s->mplane[
BOX] = ncplane_create(
stdplane, &plane_opts);
297 if (!s->mplane[
BOX]) {
301 ncplane_set_base(s->mplane[
BOX],
313 ncplane_dim_yx(s->mplane[p], &plines, &pcols);
314 pcols =
min(pcols, cols);
315 plines =
min(plines, lines);
316 ncplane_options plane_opts = {
327 s->mplane[w] = ncplane_create(s->mplane[p], &plane_opts);
340 ncplane_options plane_opts = {
351 s->mplane[w] = ncplane_create(s->mplane[p], &plane_opts);
367 if (s->mplane[w] != NULL) {
368 ncplane_erase(s->mplane[w]);
369 ncplane_destroy(s->mplane[w]);
378
379
384 ncplane_set_scrolling(s->mplane[w], enable);
413
414
420 notcurses_mice_enable(
ui->nc, mask);
422 notcurses_mice_enable(
ui->nc, NCMICE_ALL_EVENTS);
428 notcurses_mice_enable(
ui->nc, mask);
430 notcurses_mice_enable(
ui->nc, NCMICE_ALL_EVENTS);
437 unsigned int r = 0, c = 0;
438 notcurses_stddim_yx(
ui->nc, &r, &c);
461 notcurses_leave_alternate_screen(
ui->nc);
468 notcurses_enter_alternate_screen(
ui->nc);
478 notcurses_cursor_disable(
ui->nc);
482 notcurses_cursor_yx(
ui->nc, &y, &x);
483 int rc = notcurses_cursor_enable(
ui->nc, y, x);
489
490
491
497 notcurses_cursor_disable(
ui->nc);
500 ncplane_abs_yx(s->mplane[w], &yy, &xx);
504 int rc = notcurses_cursor_enable(
ui->nc, y, x);
510
511
517 notcurses_cursor_disable(
ui->nc);
520 ncplane_cursor_yx(s->mplane[w], &y, &x);
522 ncplane_abs_yx(s->mplane[w], &yy, &xx);
526 return notcurses_cursor_enable(
ui->nc, y, x) == 0 ? 0 : -1;
531
532
539 return ncplane_move_yx(s->mplane[w], y, x) == 0 ? 0 : -1;
546 return ncplane_resize_simple(s->mplane[w], (
unsigned int)lines,
547 (
unsigned int)cols) == 0
555 ncplane_erase_region(
stdplane, 0, 0, 0, 0);
561 ncplane_erase_region(
stdplane, 0, 0, 0, 0);
567 ncplane_erase_region(s->mplane[w], 0, 0, 0, 0);
573 ncplane_erase_region(s->mplane[w], 0, 0, 0, 0);
593 ncplane_move_yx(s->mplane[w], -s
->meta[w]
.lines - 1, 0);
598int ui_wmove(UiSurface *s, uint w, uint y, uint x) {
601 if (ncplane_cursor_move_yx(s->mplane[w], y, x) != 0)
608 if (ncplane_cursor_move_yx(s->mplane[w], y, x) != 0)
612void ui_getyx(UiSurface *s, uint w, uint *y, uint *x) {
615 ncplane_cursor_yx(s->mplane[w], y, x);
620 ncplane_dim_yx(s->mplane[w], y, x);
626 ncplane_dim_yx(s->mplane[w], &y, &x);
633 ncplane_dim_yx(s->mplane[w], &y, &x);
639 ncplane_scrollup(s->mplane[w], r);
656
657
661 if (!uic || !wc || !style || !pair)
671 rgb.r = channels.f_r;
672 rgb.g = channels.f_g;
673 rgb.b = channels.f_b;
676 rgb.r = channels.b_r;
677 rgb.g = channels.b_g;
678 rgb.b = channels.b_b;
686int ui_setcchar(
UiCell *cell,
const wchar_t *wstr,
const uint16_t style, ushort pair,
const void *opts) {
692 gc
->u16[0] = wstr[0];
693 gc
->u16[1] = wstr[1];
694 cell
->width = wcwidth((wchar_t)*wstr);
695 nccell_set_styles(cell, style);
696 UiChannels *chan = (UiChannels *)&cell
->channels;
708 GCluster *gc = (GCluster *)&cell
.gcluster;
709 wchar_t wstr[2] = {ucp[0], L'\0'};
711 cell
.width = wcwidth(wstr[0]);
713 unicode_to_utf8_gcluster(wstr[0], gc);
715 UiChannels *chan = (UiChannels *)&cell
.channels;
718 chan->b_a = chan->f_a = 0x40;
723
724
732 if (rgb->r == tmp.r && rgb->g == tmp.g && rgb->b == tmp.b)
761 return (EXIT_FAILURE);
781 UiChannels ui_channels = {0};
784 ui_channels.f_a = 0x40;
790 ui_channels.b_a = 0x40;
794 return ui_channels
.fb;
824 sscanf(s,
"#%02hhX%02hhX%02hhX", &rgb.r, &rgb.g, &rgb.b);
868 if (color_idx < 16) {
879
880
887 ncplane_set_base(s->mplane[w],
" ",
896 ncplane_set_channels(s->mplane[w], cell
->channels);
904 ncplane_set_channels(s->mplane[w], cell
->channels);
905 ncplane_set_base(s->mplane[w],
" ",
914 ncplane_set_channels(s->mplane[w], cell
->channels);
918
919
#define min(x, y)
min macro evaluates two expressions, returning least result
int ui_cursor_move(UiSurface *s, uint w, uint y, uint x)
UiRuntime * ui_init(const UiConfig *config)
void ui_getyx(UiSurface *s, uint w, uint *lines, uint *cols)
int ui_surface_hide(UiSurface *s, uint w)
int ui_bkgdset(UiSurface *s, uint w, const UiCell *cell)
int ui_mice_enable(int mask)
UiSurface * ui_surface_new(uint w, UiSurface *parent, uint p, uint lines, uint cols, uint y, uint x)
int ui_setscrreg(UiSurface *s, uint w, uint top, uint bottom)
int ui_scrollok(UiSurface *s, uint w, bool enable)
int ui_add_color_rgb(RGB *rgb)
int ui_wclear(UiSurface *s, uint w)
int ui_bkgd(UiSurface *s, uint w, const UiCell *cell)
struct notcurses_options NotCursesOptions
void ui_surface_destroy(UiSurface *s)
int ui_surface_move(UiSurface *s, uint w, uint y, uint x)
int ui_idlok(UiSurface *s, uint w, bool enable)
int ui_wmove(UiSurface *s, uint w, uint y, uint x)
UiSurface * ui_surface[UI_SFC_MAX]
int ui_werase(UiSurface *s, uint w)
void ui_get_screen_size(uint *lines, uint *cols)
RGB ui_hex_to_rgb(char *s)
int ui_wscrl(UiSurface *s, uint w, int rows)
int ui_mousemask(int mask)
UiCell ui_cell_from_ucp(const wchar_t *ucp, const uint32_t *fg, const uint32_t *bg)
int ui_curs_set(int visibility)
int ui_top_panel(UiSurface *s, uint w)
int ui_wnoutrefresh(UiSurface *s, uint w)
int ui_surface_resize(UiSurface *s, uint w, uint lines, uint cols)
int ui_surface_show(UiSurface *s, uint w)
UiSurface * ui_box_surface_new(UiSurface *parent, uint p, uint lines, uint cols, uint y, uint x, char *title)
int ui_keypad(UiSurface *s, uint w, bool enable)
int ui_cursor_enable(UiSurface *s, uint w, bool visible)
Disable (visible = false) or enable (visibile = true) the cursor at its current position on the surfa...
int ui_idcok(UiSurface *s, uint w, bool enable)
void ui_get_caps(UiCaps *caps)
Query the capabilities of the active backend.
UiBackend ui_get_backend()
Return which backend is powering this runtime.
int ui_surface_addpad(UiSurface *s, uint w, uint view_win, uint lines, uint cols)
void ui_getmaxyx(UiSurface *s, uint w, uint *lines, uint *cols)
int ui_cursor_enable_yx(UiSurface *s, uint w, uint y, uint x, bool visible)
Disable (visible = false) or enable (visibile = true) the cursor at a specified position on the surfa...
int ui_surface_addwin(UiSurface *s, uint w, uint p, uint lines, uint cols, uint y, uint x)
int ui_chg_color(uint16_t color_idx, uint32_t *color)
int ui_get_pair(uint16_t pair, uint *fg, uint *bg)
uint ui_init_color_hex(char *s)
struct notcurses * ui_notcurses_get_nc()
Return the raw struct notcurses* for the NotCurses session.
NcPlane * ui_notcurses_surface_get_plane(const UiSurface *s, uint w)
Return the raw struct ncplane* underlying a surface.
uint64_t ui_get_channels_from_pair(uint16_t pair)
int ui_pair_content(uint pair, uint *fg, uint *bg)
int ui_getmaxx(UiSurface *s, uint w)
int ui_bkgrndset(UiSurface *s, uint w, const UiCell *cell)
int ui_init_color(uint color, uint r, uint g, uint b)
int ui_init_pair(uint pair, uint fg, uint bg)
uint ui_add_pair(uint fg, uint bg)
int ui_getcchar(const UiCell *uc, wchar_t *wstr, attr_t *attrs, uint16_t *pair, void *opts)
int ui_color_content(uint color, uint *r, uint *g, uint *b)
int ui_getmaxy(UiSurface *s, uint w)
int ui_bkgrnd(UiSurface *s, uint w, const UiCell *cell)
int ui_setcchar(cchar_t *wch, const wchar_t *wc, const attr_t attrs, short pair, const void *opts)
int border_draw(UiSurface *sfc)
void apply_gamma(RGB *rgb)
Apply gamma correction to RGB color.
int border_title(UiSurface *sfc, char *title)
Draw a box with a title around the specified window.
int display_error(char *msg0, char *msg1, char *msg2, char *msg3)
Display an error message window or print to stderr.
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
struct UiSurface * parent
struct UiRuntime * runtime
struct UiSurfaceMeta meta[SUB_SFC_MAX]