C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
nckeys.c File Reference
#include <inttypes.h>
#include <locale.h>
#include <notcurses/notcurses.h>
#include <string.h>
#include <unistd.h>
Include dependency graph for nckeys.c:

Go to the source code of this file.

Data Structures

struct  RGB

Macros

#define _XOPEN_SOURCE   700
#define MAXLEN   256
#define MAXPLANE   30
#define MAXSFC   30
#define U_VE   L'\x2502'

Typedefs

typedef struct NcSurface NcSurface

Functions

int compat_mvwprintw (struct ncplane *, int, int, const char *,...)
int handle_input (NotCurses *nc, int y, int x, ncinput *ni)
RGB hex_clr_str_to_rgb (char *s)
int main (void)
NcPlanencplane_clicked (NcPlane *pile_member, ncinput *ni)
void ncplane_move_yx_clrtoeol (NcPlane *n, int y, int x)
void ncplane_printf_yx_clrtoeol (NcPlane *n, int y, int x, const char *fmt,...)
char * notcurses_key_str (unsigned int, char *)
NcPlaneplane_new (NotCurses *nc, int rows, int cols, int y, int x, const char *name, const char *title, const char *fg, const char *bg)
NcSurfacesurface_new (NotCurses *, int, int, int, int, const char *, const char *, const char *, const char *)
int ui_getch ()
NotCursesui_notcurses_init ()

Variables

uint64_t channels = 0
NotCursesnc
NcSurface nc_surface [MAXSFC]
int nc_surface_cnt = 0
int sfc_ptr = -1

Macro Definition Documentation

◆ _XOPEN_SOURCE

#define _XOPEN_SOURCE   700

Definition at line 13 of file nckeys.c.

◆ MAXLEN

#define MAXLEN   256

Definition at line 21 of file nckeys.c.

◆ MAXPLANE

#define MAXPLANE   30

Definition at line 22 of file nckeys.c.

◆ MAXSFC

#define MAXSFC   30

Definition at line 23 of file nckeys.c.

◆ U_VE

#define U_VE   L'\x2502'

vertical line

Definition at line 24 of file nckeys.c.

Typedef Documentation

◆ NcSurface

typedef struct NcSurface NcSurface

Definition at line 40 of file nckeys.c.

Function Documentation

◆ compat_mvwprintw()

int compat_mvwprintw ( struct ncplane * nc,
int y,
int x,
const char * fmt,
... )

Definition at line 284 of file nckeys.c.

284 {
285 va_list va;
286 va_start(va, fmt);
287 if (ncplane_vprintf_yx(nc, y, x, fmt, va) < 0) {
288 va_end(va);
289 return -1;
290 }
291 va_end(va);
292 return 0;
293}
NotCurses * nc
Definition nckeys.c:45

◆ handle_input()

int handle_input ( NotCurses * nc,
int y,
int x,
ncinput * ni )

Definition at line 202 of file nckeys.c.

202 {
203 uint32_t id;
204 bool running = true;
205 char kstr[MAXLEN];
206 NcPlane *stdn = notcurses_stdplane(nc);
207 notcurses_mice_enable(nc, NCMICE_ALL_EVENTS);
208 y = 0;
209 x = 10;
210 ncplane_printf_yx_clrtoeol(stdn, y + 1, x, "%s",
211 "Input Diagnostics - Notcurses");
212 y = 18;
213 x = 10;
214 ncplane_printf_yx_clrtoeol(stdn, y, x, "%s", "Press a key or exercise the mouse");
215 ncplane_printf_yx_clrtoeol(stdn, y + 1, x, "%s", "q to exit");
216 notcurses_render(nc);
217 while (running) {
218 id = notcurses_get_blocking(nc, ni);
219 if (id == 'q' || id == 'Q')
220 running = false;
221 NcPlane *plane = ncplane_clicked(stdn, ni);
222 if (plane) {
223 ncplane_printf_yx_clrtoeol(stdn, y + 2, x, "Clicked plane: %s", ncplane_name(plane));
224 } else {
225 ncplane_printf_yx_clrtoeol(stdn, y + 2, x, "Clicked plane: None");
226 }
227 ncplane_move_yx_clrtoeol(stdn, y + 4, x);
228 notcurses_render(nc);
229 ncplane_move_yx_clrtoeol(stdn, y + 5, x);
230 notcurses_render(nc);
231 ncplane_move_yx_clrtoeol(stdn, y + 6, x);
232 notcurses_render(nc);
233 ncplane_move_yx_clrtoeol(stdn, y + 7, x);
234 notcurses_render(nc);
235 if (id == NCKEY_BUTTON1)
236 ncplane_printf_yx_clrtoeol(stdn, y + 4, x, "Left Click at: X=%d, Y=%d", ni->x, ni->y);
237 else if (id == NCKEY_BUTTON2)
238 ncplane_printf_yx_clrtoeol(stdn, y + 4, x, "Button Click at: X=%d, Y=%d", ni->x, ni->y);
239 else if (id == NCKEY_RESIZE)
240 ncplane_printf_yx_clrtoeol(stdn, y + 4, x, "%s", "Terminal resized!");
241 else {
242 ncplane_printf_yx_clrtoeol(stdn, y + 4, x, " Octal: %3o", id);
243 ncplane_printf_yx_clrtoeol(stdn, y + 5, x, " Decimal: %3d", id);
244 ncplane_printf_yx_clrtoeol(stdn, y + 6, x, " Hex: %3x", id);
245 if (id >= 32 && id <= 126)
246 ncplane_printf_yx_clrtoeol(stdn, y + 7, x, " ASCII: %c", id);
247 else
248 ncplane_printf_yx_clrtoeol(stdn, y + 7, x, "Description: %s", notcurses_key_str(id, kstr));
249 }
250 notcurses_render(nc);
251 }
252 return 0;
253}
struct ncplane NcPlane
Definition ui_backend.h:251
NcPlane * ncplane_clicked(NcPlane *pile_member, ncinput *ni)
Definition nckeys.c:295
char * notcurses_key_str(unsigned int, char *)
Definition nckeys.c:315
void ncplane_move_yx_clrtoeol(NcPlane *n, int y, int x)
Definition nckeys.c:275
void ncplane_printf_yx_clrtoeol(NcPlane *n, int y, int x, const char *fmt,...)
Definition nckeys.c:261
#define MAXLEN
Definition curskeys.c:15

References ncplane_clicked(), ncplane_move_yx_clrtoeol(), ncplane_printf_yx_clrtoeol(), and notcurses_key_str().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hex_clr_str_to_rgb()

RGB hex_clr_str_to_rgb ( char * s)

Definition at line 309 of file nckeys.c.

309 {
310 RGB rgb;
311 sscanf(s, "#%02x%02x%02x", &rgb.r, &rgb.g, &rgb.b);
312 return rgb;
313}

References RGB::b, RGB::g, and RGB::r.

Referenced by plane_new(), and surface_new().

Here is the caller graph for this function:

◆ main()

int main ( void )

Definition at line 80 of file nckeys.c.

80 {
81 unsigned int y, x;
83
84 NcSurface *surface1 = surface_new(nc, 4, 40, 4, 10, "surface1", "┤ Surface 1 ├", "#00d7ff", "#1c1c1c");
85 if (!surface1) {
86 notcurses_stop(nc);
87 return 1;
88 }
89
90 ncplane_dim_yx(nc_surface[0].win, &y, &x);
91 ncplane_printf_yx_clrtoeol(nc_surface[0].win, 0, 0, "%s (y=%d, x=%d)", ncplane_name(nc_surface[0].win), y, x);
92 notcurses_render(nc);
93
94 NcSurface *surface2 = surface_new(nc, 4, 40, 12, 10, "surface2", "┤ Surface 2 ├", "#c0c0c0", "#000714");
95 if (!surface2) {
96 notcurses_stop(nc);
97 return 1;
98 }
99
100 ncplane_dim_yx(nc_surface[1].win, &y, &x);
101 ncplane_printf_yx_clrtoeol(nc_surface[1].win, 0, 0, "%s (y=%d, x=%d)", ncplane_name(nc_surface[1].win), y, x);
102 notcurses_render(nc);
103
104 ncinput ni;
105 handle_input(nc, 30, 0, &ni);
106 notcurses_mice_disable(nc);
107
108 notcurses_stop(nc);
109 return 0;
110}
struct notcurses NotCurses
Definition ui_backend.h:252
NcSurface nc_surface[MAXSFC]
Definition nckeys.c:43
struct NcSurface NcSurface
Definition nckeys.c:40
int handle_input(NotCurses *nc, int y, int x, ncinput *ni)
Definition nckeys.c:202
NotCurses * ui_notcurses_init()
Definition nckeys.c:63
NcSurface * surface_new(NotCurses *, int, int, int, int, const char *, const char *, const char *, const char *)
Definition nckeys.c:112

References handle_input(), nc_surface, ncplane_printf_yx_clrtoeol(), surface_new(), and ui_notcurses_init().

Here is the call graph for this function:

◆ ncplane_clicked()

NcPlane * ncplane_clicked ( NcPlane * pile_member,
ncinput * ni )

Definition at line 295 of file nckeys.c.

295 {
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)) {
300 ni->y = y;
301 ni->x = x;
302 return cur;
303 }
304 cur = ncplane_below(cur);
305 }
306 return NULL;
307}

Referenced by handle_input(), and ui_get_event_multi().

Here is the caller graph for this function:

◆ ncplane_move_yx_clrtoeol()

void ncplane_move_yx_clrtoeol ( NcPlane * n,
int y,
int x )

Definition at line 275 of file nckeys.c.

275 {
276 char tmp_str[MAXLEN];
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);
282}

Referenced by handle_input().

Here is the caller graph for this function:

◆ ncplane_printf_yx_clrtoeol()

void ncplane_printf_yx_clrtoeol ( NcPlane * n,
int y,
int x,
const char * fmt,
... )

Definition at line 261 of file nckeys.c.

261 {
262 char tmp_str[MAXLEN];
263 va_list args;
264 va_start(args, fmt);
265 vsnprintf(tmp_str, MAXLEN - 1, fmt, args);
266 va_end(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);
273}

Referenced by handle_input(), and main().

Here is the caller graph for this function:

◆ notcurses_key_str()

char * notcurses_key_str ( unsigned int key_id,
char * kstr )

Definition at line 315 of file nckeys.c.

315 {
316 switch (key_id) {
317 case NCKEY_INVALID:
318 strcpy(kstr, "NCKEY_INVALID");
319 break;
320 case NCKEY_RESIZE:
321 strcpy(kstr, "NCKEY_RESIZE");
322 break;
323 case NCKEY_UP:
324 strcpy(kstr, "NCKEY_UP");
325 break;
326 case NCKEY_RIGHT:
327 strcpy(kstr, "NCKEY_RIGHT");
328 break;
329 case NCKEY_DOWN:
330 strcpy(kstr, "NCKEY_DOWN");
331 break;
332 case NCKEY_LEFT:
333 strcpy(kstr, "NCKEY_LEFT");
334 break;
335 case NCKEY_INS:
336 strcpy(kstr, "NCKEY_INS");
337 break;
338 case NCKEY_DEL:
339 strcpy(kstr, "NCKEY_DEL");
340 break;
341 case NCKEY_BACKSPACE:
342 strcpy(kstr, "NCKEY_BACKSPACE");
343 break;
344 case NCKEY_PGDOWN:
345 strcpy(kstr, "NCKEY_PGDOWN");
346 break;
347 case NCKEY_PGUP:
348 strcpy(kstr, "NCKEY_PGUP");
349 break;
350 case NCKEY_HOME:
351 strcpy(kstr, "NCKEY_HOME");
352 break;
353 case NCKEY_END:
354 strcpy(kstr, "NCKEY_END");
355 break;
356 case NCKEY_F00:
357 strcpy(kstr, "NCKEY_F00");
358 break;
359 case NCKEY_F01:
360 strcpy(kstr, "NCKEY_F01");
361 break;
362 case NCKEY_F02:
363 strcpy(kstr, "NCKEY_F02");
364 break;
365 case NCKEY_F03:
366 strcpy(kstr, "NCKEY_F03");
367 break;
368 case NCKEY_F04:
369 strcpy(kstr, "NCKEY_F04");
370 break;
371 case NCKEY_F05:
372 strcpy(kstr, "NCKEY_F05");
373 break;
374 case NCKEY_F06:
375 strcpy(kstr, "NCKEY_F06");
376 break;
377 case NCKEY_F07:
378 strcpy(kstr, "NCKEY_F07");
379 break;
380 case NCKEY_F08:
381 strcpy(kstr, "NCKEY_F08");
382 break;
383 case NCKEY_F09:
384 strcpy(kstr, "NCKEY_F09");
385 break;
386 case NCKEY_F10:
387 strcpy(kstr, "NCKEY_F10");
388 break;
389 case NCKEY_F11:
390 strcpy(kstr, "NCKEY_F11");
391 break;
392 case NCKEY_F12:
393 strcpy(kstr, "NCKEY_F12");
394 break;
395 case NCKEY_F13:
396 strcpy(kstr, "NCKEY_F13");
397 break;
398 case NCKEY_F14:
399 strcpy(kstr, "NCKEY_F14");
400 break;
401 case NCKEY_F15:
402 strcpy(kstr, "NCKEY_F15");
403 break;
404 case NCKEY_F16:
405 strcpy(kstr, "NCKEY_F16");
406 break;
407 case NCKEY_F17:
408 strcpy(kstr, "NCKEY_F17");
409 break;
410 case NCKEY_F18:
411 strcpy(kstr, "NCKEY_F18");
412 break;
413 case NCKEY_F19:
414 strcpy(kstr, "NCKEY_F19");
415 break;
416 case NCKEY_F20:
417 strcpy(kstr, "NCKEY_F20");
418 break;
419 case NCKEY_F21:
420 strcpy(kstr, "NCKEY_F21");
421 break;
422 case NCKEY_F22:
423 strcpy(kstr, "NCKEY_F22");
424 break;
425 case NCKEY_F23:
426 strcpy(kstr, "NCKEY_F23");
427 break;
428 case NCKEY_F24:
429 strcpy(kstr, "NCKEY_F24");
430 break;
431 case NCKEY_F25:
432 strcpy(kstr, "NCKEY_F25");
433 break;
434 case NCKEY_F26:
435 strcpy(kstr, "NCKEY_F26");
436 break;
437 case NCKEY_F27:
438 strcpy(kstr, "NCKEY_F27");
439 break;
440 case NCKEY_F28:
441 strcpy(kstr, "NCKEY_F28");
442 break;
443 case NCKEY_F29:
444 strcpy(kstr, "NCKEY_F29");
445 break;
446 case NCKEY_F30:
447 strcpy(kstr, "NCKEY_F30");
448 break;
449 case NCKEY_F31:
450 strcpy(kstr, "NCKEY_F31");
451 break;
452 case NCKEY_F32:
453 strcpy(kstr, "NCKEY_F32");
454 break;
455 case NCKEY_F33:
456 strcpy(kstr, "NCKEY_F33");
457 break;
458 case NCKEY_F34:
459 strcpy(kstr, "NCKEY_F34");
460 break;
461 case NCKEY_F35:
462 strcpy(kstr, "NCKEY_F35");
463 break;
464 case NCKEY_F36:
465 strcpy(kstr, "NCKEY_F36");
466 break;
467 case NCKEY_F37:
468 strcpy(kstr, "NCKEY_F37");
469 break;
470 case NCKEY_F38:
471 strcpy(kstr, "NCKEY_F38");
472 break;
473 case NCKEY_F39:
474 strcpy(kstr, "NCKEY_F39");
475 break;
476 case NCKEY_F40:
477 strcpy(kstr, "NCKEY_F40");
478 break;
479 case NCKEY_F41:
480 strcpy(kstr, "NCKEY_F41");
481 break;
482 case NCKEY_F42:
483 strcpy(kstr, "NCKEY_F42");
484 break;
485 case NCKEY_F43:
486 strcpy(kstr, "NCKEY_F43");
487 break;
488 case NCKEY_F44:
489 strcpy(kstr, "NCKEY_F44");
490 break;
491 case NCKEY_F45:
492 strcpy(kstr, "NCKEY_F45");
493 break;
494 case NCKEY_F46:
495 strcpy(kstr, "NCKEY_F46");
496 break;
497 case NCKEY_F47:
498 strcpy(kstr, "NCKEY_F47");
499 break;
500 case NCKEY_F48:
501 strcpy(kstr, "NCKEY_F48");
502 break;
503 case NCKEY_F49:
504 strcpy(kstr, "NCKEY_F49");
505 break;
506 case NCKEY_F50:
507 strcpy(kstr, "NCKEY_F50");
508 break;
509 case NCKEY_F51:
510 strcpy(kstr, "NCKEY_F51");
511 break;
512 case NCKEY_F52:
513 strcpy(kstr, "NCKEY_F52");
514 break;
515 case NCKEY_F53:
516 strcpy(kstr, "NCKEY_F53");
517 break;
518 case NCKEY_F54:
519 strcpy(kstr, "NCKEY_F54");
520 break;
521 case NCKEY_F55:
522 strcpy(kstr, "NCKEY_F55");
523 break;
524 case NCKEY_F56:
525 strcpy(kstr, "NCKEY_F56");
526 break;
527 case NCKEY_F57:
528 strcpy(kstr, "NCKEY_F57");
529 break;
530 case NCKEY_F58:
531 strcpy(kstr, "NCKEY_F58");
532 break;
533 case NCKEY_F59:
534 strcpy(kstr, "NCKEY_F59");
535 break;
536 case NCKEY_F60:
537 strcpy(kstr, "NCKEY_F60");
538 break;
539 case NCKEY_ENTER:
540 strcpy(kstr, "NCKEY_ENTER");
541 break;
542 case NCKEY_CLS:
543 strcpy(kstr, "NCKEY_CLS");
544 break;
545 case NCKEY_DLEFT:
546 strcpy(kstr, "NCKEY_DLEFT");
547 break;
548 case NCKEY_DRIGHT:
549 strcpy(kstr, "NCKEY_DRIGHT");
550 break;
551 case NCKEY_ULEFT:
552 strcpy(kstr, "NCKEY_ULEFT");
553 break;
554 case NCKEY_URIGHT:
555 strcpy(kstr, "NCKEY_URIGHT");
556 break;
557 case NCKEY_CENTER:
558 strcpy(kstr, "NCKEY_CENTER");
559 break;
560 case NCKEY_BEGIN:
561 strcpy(kstr, "NCKEY_BEGIN");
562 break;
563 case NCKEY_CANCEL:
564 strcpy(kstr, "NCKEY_CANCEL");
565 break;
566 case NCKEY_CLOSE:
567 strcpy(kstr, "NCKEY_CLOSE");
568 break;
569 case NCKEY_COMMAND:
570 strcpy(kstr, "NCKEY_COMMAND");
571 break;
572 case NCKEY_COPY:
573 strcpy(kstr, "NCKEY_COPY");
574 break;
575 case NCKEY_EXIT:
576 strcpy(kstr, "NCKEY_EXIT");
577 break;
578 case NCKEY_PRINT:
579 strcpy(kstr, "NCKEY_PRINT");
580 break;
581 case NCKEY_REFRESH:
582 strcpy(kstr, "NCKEY_REFRESH");
583 break;
584 case NCKEY_SEPARATOR:
585 strcpy(kstr, "NCKEY_SEPARATOR");
586 break;
587 case NCKEY_CAPS_LOCK:
588 strcpy(kstr, "NCKEY_CAPS_LOCK");
589 break;
590 case NCKEY_SCROLL_LOCK:
591 strcpy(kstr, "NCKEY_SCROLL_LOCK");
592 break;
593 case NCKEY_NUM_LOCK:
594 strcpy(kstr, "NCKEY_NUM_LOCK");
595 break;
596 case NCKEY_PRINT_SCREEN:
597 strcpy(kstr, "NCKEY_PRINT_SCREEN");
598 break;
599 case NCKEY_PAUSE:
600 strcpy(kstr, "NCKEY_PAUSE");
601 break;
602 case NCKEY_MENU:
603 strcpy(kstr, "NCKEY_MENU");
604 break;
605 case NCKEY_MEDIA_PLAY:
606 strcpy(kstr, "NCKEY_MEDIA_PLAY");
607 break;
608 case NCKEY_MEDIA_PAUSE:
609 strcpy(kstr, "NCKEY_MEDIA_PAUSE");
610 break;
611 case NCKEY_MEDIA_PPAUSE:
612 strcpy(kstr, "NCKEY_MEDIA_PPAUSE");
613 break;
614 case NCKEY_MEDIA_REV:
615 strcpy(kstr, "NCKEY_MEDIA_REV");
616 break;
617 case NCKEY_MEDIA_STOP:
618 strcpy(kstr, "NCKEY_MEDIA_STOP");
619 break;
620 case NCKEY_MEDIA_FF:
621 strcpy(kstr, "NCKEY_MEDIA_FF");
622 break;
623 case NCKEY_MEDIA_REWIND:
624 strcpy(kstr, "NCKEY_MEDIA_REWIND");
625 break;
626 case NCKEY_MEDIA_NEXT:
627 strcpy(kstr, "NCKEY_MEDIA_NEXT");
628 break;
629 case NCKEY_MEDIA_PREV:
630 strcpy(kstr, "NCKEY_MEDIA_PREV");
631 break;
632 case NCKEY_MEDIA_RECORD:
633 strcpy(kstr, "NCKEY_MEDIA_RECORD");
634 break;
635 case NCKEY_MEDIA_LVOL:
636 strcpy(kstr, "NCKEY_MEDIA_LVOL");
637 break;
638 case NCKEY_MEDIA_RVOL:
639 strcpy(kstr, "NCKEY_MEDIA_RVOL");
640 break;
641 case NCKEY_MEDIA_MUTE:
642 strcpy(kstr, "NCKEY_MEDIA_MUTE");
643 break;
644 case NCKEY_LSHIFT:
645 strcpy(kstr, "NCKEY_LSHIFT");
646 break;
647 case NCKEY_LCTRL:
648 strcpy(kstr, "NCKEY_LCTRL");
649 break;
650 case NCKEY_LALT:
651 strcpy(kstr, "NCKEY_LALT");
652 break;
653 case NCKEY_LSUPER:
654 strcpy(kstr, "NCKEY_LSUPER");
655 break;
656 case NCKEY_LHYPER:
657 strcpy(kstr, "NCKEY_LHYPER");
658 break;
659 case NCKEY_LMETA:
660 strcpy(kstr, "NCKEY_LMETA");
661 break;
662 case NCKEY_RSHIFT:
663 strcpy(kstr, "NCKEY_RSHIFT");
664 break;
665 case NCKEY_RCTRL:
666 strcpy(kstr, "NCKEY_RCTRL");
667 break;
668 case NCKEY_RALT:
669 strcpy(kstr, "NCKEY_RALT");
670 break;
671 case NCKEY_RSUPER:
672 strcpy(kstr, "NCKEY_RSUPER");
673 break;
674 case NCKEY_RHYPER:
675 strcpy(kstr, "NCKEY_RHYPER");
676 break;
677 case NCKEY_RMETA:
678 strcpy(kstr, "NCKEY_RMETA");
679 break;
680 case NCKEY_L3SHIFT:
681 strcpy(kstr, "NCKEY_L3SHIFT");
682 break;
683 case NCKEY_L5SHIFT:
684 strcpy(kstr, "NCKEY_L5SHIFT");
685 break;
686 case NCKEY_MOTION:
687 strcpy(kstr, "NCKEY_MOTION");
688 break;
689 case NCKEY_BUTTON1:
690 strcpy(kstr, "NCKEY_BUTTON1");
691 break;
692 case NCKEY_BUTTON2:
693 strcpy(kstr, "NCKEY_BUTTON2");
694 break;
695 case NCKEY_BUTTON3:
696 strcpy(kstr, "NCKEY_BUTTON3");
697 break;
698 case NCKEY_BUTTON4:
699 strcpy(kstr, "NCKEY_BUTTON4");
700 break;
701 case NCKEY_BUTTON5:
702 strcpy(kstr, "NCKEY_BUTTON5");
703 break;
704 case NCKEY_BUTTON6:
705 strcpy(kstr, "NCKEY_BUTTON6");
706 break;
707 case NCKEY_BUTTON7:
708 strcpy(kstr, "NCKEY_BUTTON7");
709 break;
710 case NCKEY_BUTTON8:
711 strcpy(kstr, "NCKEY_BUTTON8");
712 break;
713 case NCKEY_BUTTON9:
714 strcpy(kstr, "NCKEY_BUTTON9");
715 break;
716 case NCKEY_BUTTON10:
717 strcpy(kstr, "NCKEY_BUTTON10");
718 break;
719 case NCKEY_BUTTON11:
720 strcpy(kstr, "NCKEY_BUTTON11");
721 break;
722 case NCKEY_SIGNAL:
723 strcpy(kstr, "NCKEY_SIGNAL");
724 break;
725 case NCKEY_EOF:
726 strcpy(kstr, "NCKEY_EOF");
727 break;
728 default:
729 snprintf(kstr, 32, "NCKEY_%d", key_id);
730 break;
731 }
732 return kstr;
733}

Referenced by handle_input().

Here is the caller graph for this function:

◆ plane_new()

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 )

Definition at line 163 of file nckeys.c.

165 {
166 RGB rgb_fg = hex_clr_str_to_rgb((char *)fg);
167 RGB rgb_bg = hex_clr_str_to_rgb((char *)bg);
168 unsigned int dimy, dimx;
169 notcurses_stddim_yx(nc, &dimy, &dimx);
170 NcPlaneOptions plane_opts = {
171 .y = y,
172 .x = x,
173 .rows = rows + 2,
174 .cols = cols + 2,
175 .name = name};
176 NcPlane *stdn = notcurses_stdplane(nc);
177 NcPlane *plane = ncplane_create(stdn, &plane_opts);
178 if (!plane) {
179 notcurses_stop(nc);
180 return NULL;
181 }
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);
191 plane_opts.y = 1;
192 plane_opts.x = 1;
193 plane_opts.rows = rows;
194 plane_opts.cols = cols;
195 if (!plane) {
196 notcurses_stop(nc);
197 return NULL;
198 }
199 return plane;
200}
struct ncplane_options NcPlaneOptions
Definition ui_backend.h:254
uint64_t channels
Definition nckeys.c:42
RGB hex_clr_str_to_rgb(char *s)
Definition nckeys.c:309

References RGB::b, RGB::g, hex_clr_str_to_rgb(), and RGB::r.

Here is the call graph for this function:

◆ surface_new()

NcSurface * surface_new ( NotCurses * nc,
int rows,
int cols,
int y,
int x,
const char * name,
const char * title,
const char * fg,
const char * bg )

Definition at line 112 of file nckeys.c.

114 {
115 char plane_name[MAXLEN];
116 snprintf(plane_name, MAXLEN - 1, "%s_box", name);
117 RGB rgb_fg = hex_clr_str_to_rgb((char *)fg);
118 RGB rgb_bg = hex_clr_str_to_rgb((char *)bg);
119 unsigned int dimy, dimx;
120 notcurses_stddim_yx(nc, &dimy, &dimx);
121 NcPlaneOptions plane_opts = {
122 .y = y,
123 .x = x,
124 .rows = rows + 2,
125 .cols = cols + 2,
126 .name = plane_name};
127 NcPlane *stdn = notcurses_stdplane(nc);
128 NcPlane *box = ncplane_create(stdn, &plane_opts);
129 if (!box) {
130 notcurses_stop(nc);
131 return NULL;
132 }
133 ncchannels_set_fg_rgb8(&channels, rgb_fg.r, rgb_fg.g, rgb_fg.b);
134 ncchannels_set_bg_rgb8(&channels, rgb_bg.r, rgb_bg.g, rgb_bg.b);
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 ├";
140 }
141 int title_len = (int)strlen(title);
142 int title_x = (cols - title_len) / 2;
143 ncplane_putstr_yx(box, 0, title_x, title);
144 plane_opts.y = 1;
145 plane_opts.x = 1;
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);
151 if (!win) {
152 notcurses_stop(nc);
153 return NULL;
154 }
155 ncplane_set_base(win, " ", 0, channels);
156 ncplane_set_channels(win, channels);
157 sfc_ptr++;
158 nc_surface[sfc_ptr].box = box;
159 nc_surface[sfc_ptr].win = win;
160 return &nc_surface[sfc_ptr];
161}
int sfc_ptr
Definition nckeys.c:47

References RGB::b, channels, RGB::g, hex_clr_str_to_rgb(), nc_surface, RGB::r, and sfc_ptr.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ui_getch()

int ui_getch ( )

Definition at line 255 of file nckeys.c.

255 {
256 ncinput ni;
257 notcurses_get_blocking(nc, &ni);
258 return ni.id;
259}

◆ ui_notcurses_init()

NotCurses * ui_notcurses_init ( )

Definition at line 63 of file nckeys.c.

63 {
64 setlocale(LC_ALL, "");
65 NotCursesOptions nc_opts = {
66 .flags = NCOPTION_SUPPRESS_BANNERS | NCOPTION_NO_QUIT_SIGHANDLERS};
67 nc = notcurses_init(&nc_opts, NULL);
68 if (!nc) {
69 return NULL;
70 }
71 NcPlane *stdn = notcurses_stdplane(nc);
72 ncplane_erase(stdn);
73 notcurses_render(nc);
74 int c = ui_getch();
75 return nc;
76}
struct notcurses_options NotCursesOptions
Definition ui_backend.h:253
int ui_getch()
Definition nckeys.c:255

References nc, and ui_getch().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ channels

uint64_t channels = 0

Definition at line 42 of file nckeys.c.

Referenced by surface_new().

◆ nc

NotCurses * nc

Definition at line 45 of file nckeys.c.

Referenced by ui_getch(), and ui_notcurses_init().

◆ nc_surface

NcSurface nc_surface

Definition at line 43 of file nckeys.c.

Referenced by main(), and surface_new().

◆ nc_surface_cnt

int nc_surface_cnt = 0

Definition at line 61 of file nckeys.c.

◆ sfc_ptr

int sfc_ptr = -1

Definition at line 47 of file nckeys.c.