input: print keypresses #8

pull/81/head
nick black 5 years ago
parent c76735cb2a
commit 51a86ece7b
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -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;
}

Loading…
Cancel
Save