From 51a86ece7b21eee33aec56c0108877ddbd3f14a9 Mon Sep 17 00:00:00 2001 From: nick black Date: Fri, 29 Nov 2019 01:22:38 -0500 Subject: [PATCH] input: print keypresses #8 --- src/input/input.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/input/input.cpp b/src/input/input.cpp index 06c6a4d29..4f3a715b7 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -12,18 +12,30 @@ int main(void){ notcurses_options opts{}; opts.outfp = stdout; struct notcurses* nc = notcurses_init(&opts); + struct ncplane* n = notcurses_stdplane(nc); if(nc == nullptr){ return EXIT_FAILURE;; } int r; cell c = CELL_TRIVIAL_INITIALIZER; + if(ncplane_fg_rgb8(n, 255, 255, 255)){ + return EXIT_FAILURE; + } while((r = notcurses_getc_blocking(nc, &c)) >= 0){ if(r == 0){ // interrupted by signal continue; } + if(ncplane_printf(n, "Got keypress: [%04x] '%c'\n", c.gcluster, c.gcluster) < 0){ + break; + } + if(notcurses_render(nc)){ + break; + } } int e = errno; notcurses_stop(nc); - std::cerr << "Error reading from terminal (" << strerror(e) << "?)\n"; + if(r < 0){ + std::cerr << "Error reading from terminal (" << strerror(e) << "?)\n"; + } return EXIT_FAILURE; }