2
3
4
5
6
7
8
9
10
11
13#define _XOPEN_SOURCE 700
17#include <notcurses/notcurses.h>
26typedef struct notcurses NotCurses;
27typedef struct ncplane NcPlane;
28typedef struct notcurses_options NotCursesOptions;
29typedef struct ncplane_options NcPlaneOptions;
40typedef struct NcSurface NcSurface;
56NcPlane *
plane_new(NotCurses *nc,
int rows,
int cols,
int y,
int x,
57 const char *name,
const char *title,
const char *fg,
const char *bg);
58NcSurface *
surface_new(NotCurses *,
int,
int,
int,
int,
59 const char *,
const char *,
const char *,
const char *);
64 setlocale(LC_ALL,
"");
65 NotCursesOptions nc_opts = {
66 .flags = NCOPTION_SUPPRESS_BANNERS | NCOPTION_NO_QUIT_SIGHANDLERS};
67 nc = notcurses_init(&nc_opts, NULL);
71 NcPlane *stdn = notcurses_stdplane(
nc);
78int handle_input(NotCurses *nc,
int y,
int x, ncinput *ni);
84 NcSurface *surface1 =
surface_new(nc
, 4
, 40
, 4
, 10
, "surface1", "┤ Surface 1 ├", "#00d7ff", "#1c1c1c");
94 NcSurface *surface2 =
surface_new(nc
, 4
, 40
, 12
, 10
, "surface2", "┤ Surface 2 ├", "#c0c0c0", "#000714");
102 notcurses_render(nc);
106 notcurses_mice_disable(nc);
113 int y,
int x,
const char *name,
const char *title,
114 const char *fg,
const char *bg) {
116 snprintf(plane_name,
MAXLEN - 1,
"%s_box", name);
119 unsigned int dimy, dimx;
120 notcurses_stddim_yx(nc, &dimy, &dimx);
121 NcPlaneOptions plane_opts = {
127 NcPlane *stdn = notcurses_stdplane(nc);
128 NcPlane *box = ncplane_create(stdn, &plane_opts);
135 ncplane_set_base(box,
" ", 0,
channels);
136 ncplane_set_channels(box,
channels);
137 ncplane_perimeter_rounded(box, 0,
channels, 0);
138 if (!title || strlen(title) == 0) {
139 title =
"┤ Surface ├";
141 int title_len = (
int)strlen(title);
142 int title_x = (cols - title_len) / 2;
143 ncplane_putstr_yx(box, 0, title_x, title);
146 plane_opts.rows = rows;
147 plane_opts.cols = cols;
148 snprintf(plane_name,
MAXLEN - 1,
"%s_win", name);
149 plane_opts.name = plane_name;
150 NcPlane *win = ncplane_create(box, &plane_opts);
155 ncplane_set_base(win,
" ", 0,
channels);
156 ncplane_set_channels(win,
channels);
164 int y,
int x,
const char *name,
const char *title,
165 const char *fg,
const char *bg) {
168 unsigned int dimy, dimx;
169 notcurses_stddim_yx(nc, &dimy, &dimx);
170 NcPlaneOptions plane_opts = {
176 NcPlane *stdn = notcurses_stdplane(nc);
177 NcPlane *plane = ncplane_create(stdn, &plane_opts);
182 uint64_t channels = 0;
183 ncchannels_set_fg_rgb8(&channels, rgb_fg
.r, rgb_fg
.g, rgb_fg
.b);
184 ncchannels_set_bg_rgb8(&channels, rgb_bg
.r, rgb_bg
.g, rgb_bg
.b);
185 ncplane_set_base(plane,
" ", 0, channels);
186 ncplane_set_channels(plane, channels);
187 ncplane_perimeter_rounded(plane, 0, channels, 0);
188 int title_len = (
int)strlen(title);
189 int title_x = (cols - title_len) / 2;
190 ncplane_putstr_yx(plane, 0, title_x, title);
193 plane_opts.rows = rows;
194 plane_opts.cols = cols;
206 NcPlane *stdn = notcurses_stdplane(nc);
207 notcurses_mice_enable(nc, NCMICE_ALL_EVENTS);
211 "Input Diagnostics - Notcurses");
216 notcurses_render(nc);
218 id = notcurses_get_blocking(nc, ni);
219 if (id ==
'q' || id ==
'Q')
228 notcurses_render(nc);
230 notcurses_render(nc);
232 notcurses_render(nc);
234 notcurses_render(nc);
235 if (id == NCKEY_BUTTON1)
237 else if (id == NCKEY_BUTTON2)
239 else if (id == NCKEY_RESIZE)
245 if (id >= 32 && id <= 126)
250 notcurses_render(nc);
257 notcurses_get_blocking(
nc, &ni);
265 vsnprintf(tmp_str,
MAXLEN - 1, fmt, args);
267 int l = (
int)strlen(tmp_str);
268 int dimx = ncplane_dim_x(n);
269 int dcols = dimx - x - l;
270 memset(tmp_str + l,
' ', dcols);
271 tmp_str[dimx] =
'\0';
272 ncplane_putstr_yx(n, y, x, tmp_str);
277 int dimx = ncplane_dim_x(n);
278 int dcols = dimx - x;
279 memset(tmp_str,
' ', dcols);
280 tmp_str[dcols] =
'\0';
281 ncplane_putstr_yx(n, y, x, tmp_str);
287 if (ncplane_vprintf_yx(nc, y, x, fmt, va) < 0) {
296 NcPlane *cur = ncpile_top(pile_member);
297 while (cur != NULL) {
298 int y = ni->y, x = ni->x;
299 if (ncplane_translate_abs(cur, &y, &x)) {
304 cur = ncplane_below(cur);
311 sscanf(s,
"#%02x%02x%02x", &rgb
.r, &rgb
.g, &rgb
.b);
318 strcpy(kstr,
"NCKEY_INVALID");
321 strcpy(kstr,
"NCKEY_RESIZE");
324 strcpy(kstr,
"NCKEY_UP");
327 strcpy(kstr,
"NCKEY_RIGHT");
330 strcpy(kstr,
"NCKEY_DOWN");
333 strcpy(kstr,
"NCKEY_LEFT");
336 strcpy(kstr,
"NCKEY_INS");
339 strcpy(kstr,
"NCKEY_DEL");
341 case NCKEY_BACKSPACE:
342 strcpy(kstr,
"NCKEY_BACKSPACE");
345 strcpy(kstr,
"NCKEY_PGDOWN");
348 strcpy(kstr,
"NCKEY_PGUP");
351 strcpy(kstr,
"NCKEY_HOME");
354 strcpy(kstr,
"NCKEY_END");
357 strcpy(kstr,
"NCKEY_F00");
360 strcpy(kstr,
"NCKEY_F01");
363 strcpy(kstr,
"NCKEY_F02");
366 strcpy(kstr,
"NCKEY_F03");
369 strcpy(kstr,
"NCKEY_F04");
372 strcpy(kstr,
"NCKEY_F05");
375 strcpy(kstr,
"NCKEY_F06");
378 strcpy(kstr,
"NCKEY_F07");
381 strcpy(kstr,
"NCKEY_F08");
384 strcpy(kstr,
"NCKEY_F09");
387 strcpy(kstr,
"NCKEY_F10");
390 strcpy(kstr,
"NCKEY_F11");
393 strcpy(kstr,
"NCKEY_F12");
396 strcpy(kstr,
"NCKEY_F13");
399 strcpy(kstr,
"NCKEY_F14");
402 strcpy(kstr,
"NCKEY_F15");
405 strcpy(kstr,
"NCKEY_F16");
408 strcpy(kstr,
"NCKEY_F17");
411 strcpy(kstr,
"NCKEY_F18");
414 strcpy(kstr,
"NCKEY_F19");
417 strcpy(kstr,
"NCKEY_F20");
420 strcpy(kstr,
"NCKEY_F21");
423 strcpy(kstr,
"NCKEY_F22");
426 strcpy(kstr,
"NCKEY_F23");
429 strcpy(kstr,
"NCKEY_F24");
432 strcpy(kstr,
"NCKEY_F25");
435 strcpy(kstr,
"NCKEY_F26");
438 strcpy(kstr,
"NCKEY_F27");
441 strcpy(kstr,
"NCKEY_F28");
444 strcpy(kstr,
"NCKEY_F29");
447 strcpy(kstr,
"NCKEY_F30");
450 strcpy(kstr,
"NCKEY_F31");
453 strcpy(kstr,
"NCKEY_F32");
456 strcpy(kstr,
"NCKEY_F33");
459 strcpy(kstr,
"NCKEY_F34");
462 strcpy(kstr,
"NCKEY_F35");
465 strcpy(kstr,
"NCKEY_F36");
468 strcpy(kstr,
"NCKEY_F37");
471 strcpy(kstr,
"NCKEY_F38");
474 strcpy(kstr,
"NCKEY_F39");
477 strcpy(kstr,
"NCKEY_F40");
480 strcpy(kstr,
"NCKEY_F41");
483 strcpy(kstr,
"NCKEY_F42");
486 strcpy(kstr,
"NCKEY_F43");
489 strcpy(kstr,
"NCKEY_F44");
492 strcpy(kstr,
"NCKEY_F45");
495 strcpy(kstr,
"NCKEY_F46");
498 strcpy(kstr,
"NCKEY_F47");
501 strcpy(kstr,
"NCKEY_F48");
504 strcpy(kstr,
"NCKEY_F49");
507 strcpy(kstr,
"NCKEY_F50");
510 strcpy(kstr,
"NCKEY_F51");
513 strcpy(kstr,
"NCKEY_F52");
516 strcpy(kstr,
"NCKEY_F53");
519 strcpy(kstr,
"NCKEY_F54");
522 strcpy(kstr,
"NCKEY_F55");
525 strcpy(kstr,
"NCKEY_F56");
528 strcpy(kstr,
"NCKEY_F57");
531 strcpy(kstr,
"NCKEY_F58");
534 strcpy(kstr,
"NCKEY_F59");
537 strcpy(kstr,
"NCKEY_F60");
540 strcpy(kstr,
"NCKEY_ENTER");
543 strcpy(kstr,
"NCKEY_CLS");
546 strcpy(kstr,
"NCKEY_DLEFT");
549 strcpy(kstr,
"NCKEY_DRIGHT");
552 strcpy(kstr,
"NCKEY_ULEFT");
555 strcpy(kstr,
"NCKEY_URIGHT");
558 strcpy(kstr,
"NCKEY_CENTER");
561 strcpy(kstr,
"NCKEY_BEGIN");
564 strcpy(kstr,
"NCKEY_CANCEL");
567 strcpy(kstr,
"NCKEY_CLOSE");
570 strcpy(kstr,
"NCKEY_COMMAND");
573 strcpy(kstr,
"NCKEY_COPY");
576 strcpy(kstr,
"NCKEY_EXIT");
579 strcpy(kstr,
"NCKEY_PRINT");
582 strcpy(kstr,
"NCKEY_REFRESH");
584 case NCKEY_SEPARATOR:
585 strcpy(kstr,
"NCKEY_SEPARATOR");
587 case NCKEY_CAPS_LOCK:
588 strcpy(kstr,
"NCKEY_CAPS_LOCK");
590 case NCKEY_SCROLL_LOCK:
591 strcpy(kstr,
"NCKEY_SCROLL_LOCK");
594 strcpy(kstr,
"NCKEY_NUM_LOCK");
596 case NCKEY_PRINT_SCREEN:
597 strcpy(kstr,
"NCKEY_PRINT_SCREEN");
600 strcpy(kstr,
"NCKEY_PAUSE");
603 strcpy(kstr,
"NCKEY_MENU");
605 case NCKEY_MEDIA_PLAY:
606 strcpy(kstr,
"NCKEY_MEDIA_PLAY");
608 case NCKEY_MEDIA_PAUSE:
609 strcpy(kstr,
"NCKEY_MEDIA_PAUSE");
611 case NCKEY_MEDIA_PPAUSE:
612 strcpy(kstr,
"NCKEY_MEDIA_PPAUSE");
614 case NCKEY_MEDIA_REV:
615 strcpy(kstr,
"NCKEY_MEDIA_REV");
617 case NCKEY_MEDIA_STOP:
618 strcpy(kstr,
"NCKEY_MEDIA_STOP");
621 strcpy(kstr,
"NCKEY_MEDIA_FF");
623 case NCKEY_MEDIA_REWIND:
624 strcpy(kstr,
"NCKEY_MEDIA_REWIND");
626 case NCKEY_MEDIA_NEXT:
627 strcpy(kstr,
"NCKEY_MEDIA_NEXT");
629 case NCKEY_MEDIA_PREV:
630 strcpy(kstr,
"NCKEY_MEDIA_PREV");
632 case NCKEY_MEDIA_RECORD:
633 strcpy(kstr,
"NCKEY_MEDIA_RECORD");
635 case NCKEY_MEDIA_LVOL:
636 strcpy(kstr,
"NCKEY_MEDIA_LVOL");
638 case NCKEY_MEDIA_RVOL:
639 strcpy(kstr,
"NCKEY_MEDIA_RVOL");
641 case NCKEY_MEDIA_MUTE:
642 strcpy(kstr,
"NCKEY_MEDIA_MUTE");
645 strcpy(kstr,
"NCKEY_LSHIFT");
648 strcpy(kstr,
"NCKEY_LCTRL");
651 strcpy(kstr,
"NCKEY_LALT");
654 strcpy(kstr,
"NCKEY_LSUPER");
657 strcpy(kstr,
"NCKEY_LHYPER");
660 strcpy(kstr,
"NCKEY_LMETA");
663 strcpy(kstr,
"NCKEY_RSHIFT");
666 strcpy(kstr,
"NCKEY_RCTRL");
669 strcpy(kstr,
"NCKEY_RALT");
672 strcpy(kstr,
"NCKEY_RSUPER");
675 strcpy(kstr,
"NCKEY_RHYPER");
678 strcpy(kstr,
"NCKEY_RMETA");
681 strcpy(kstr,
"NCKEY_L3SHIFT");
684 strcpy(kstr,
"NCKEY_L5SHIFT");
687 strcpy(kstr,
"NCKEY_MOTION");
690 strcpy(kstr,
"NCKEY_BUTTON1");
693 strcpy(kstr,
"NCKEY_BUTTON2");
696 strcpy(kstr,
"NCKEY_BUTTON3");
699 strcpy(kstr,
"NCKEY_BUTTON4");
702 strcpy(kstr,
"NCKEY_BUTTON5");
705 strcpy(kstr,
"NCKEY_BUTTON6");
708 strcpy(kstr,
"NCKEY_BUTTON7");
711 strcpy(kstr,
"NCKEY_BUTTON8");
714 strcpy(kstr,
"NCKEY_BUTTON9");
717 strcpy(kstr,
"NCKEY_BUTTON10");
720 strcpy(kstr,
"NCKEY_BUTTON11");
723 strcpy(kstr,
"NCKEY_SIGNAL");
726 strcpy(kstr,
"NCKEY_EOF");
729 snprintf(kstr, 32,
"NCKEY_%d", key_id);
NcPlane * ncplane_clicked(NcPlane *pile_member, ncinput *ni)
NcPlane * plane_new(NotCurses *nc, int rows, int cols, int y, int x, const char *name, const char *title, const char *fg, const char *bg)
NcSurface nc_surface[MAXSFC]
int compat_mvwprintw(struct ncplane *, int, int, const char *,...)
char * notcurses_key_str(unsigned int, char *)
RGB hex_clr_str_to_rgb(char *s)
void ncplane_move_yx_clrtoeol(NcPlane *n, int y, int x)
int handle_input(NotCurses *nc, int y, int x, ncinput *ni)
NotCurses * ui_notcurses_init()
NcSurface * surface_new(NotCurses *, int, int, int, int, const char *, const char *, const char *, const char *)
void ncplane_printf_yx_clrtoeol(NcPlane *n, int y, int x, const char *fmt,...)
int main(int argc, char **argv)
Capture the current terminal settings for later restoration.