From e885d87d1a62a68bb1d183752a90e961b19df6e0 Mon Sep 17 00:00:00 2001 From: nick black Date: Thu, 15 Oct 2020 07:28:22 -0400 Subject: [PATCH] introduce NCKEY_ESC, use it everywhere --- include/notcurses/nckeys.h | 3 +++ src/input/input.cpp | 2 +- src/lib/direct.cpp | 2 +- src/lib/input.c | 8 +++----- src/lib/menu.c | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/notcurses/nckeys.h b/include/notcurses/nckeys.h index 8ce5fd8fc..a3866acc0 100644 --- a/include/notcurses/nckeys.h +++ b/include/notcurses/nckeys.h @@ -119,6 +119,9 @@ extern "C" { #define NCKEY_SCROLL_DOWN NCKEY_BUTTON5 #define NCKEY_RETURN NCKEY_ENTER +// Just aliases, ma'am, from the 128 characters common to ASCII+UTF8 +#define NCKEY_ESC 0x1b + #ifdef __cplusplus } // extern "C" #endif diff --git a/src/input/input.cpp b/src/input/input.cpp index 48ad70927..688c80c90 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -142,7 +142,7 @@ const char* nckeystr(char32_t spkey){ // Print the utf8 Control Pictures for otherwise unprintable ASCII char32_t printutf8(char32_t kp){ - if(kp <= 27){ + if(kp <= NCKEY_ESC){ return 0x2400 + kp; } return kp; diff --git a/src/lib/direct.cpp b/src/lib/direct.cpp index deeb6e2ee..5ddd65e7f 100644 --- a/src/lib/direct.cpp +++ b/src/lib/direct.cpp @@ -153,7 +153,7 @@ cursor_yx_get(int ttyfd, int* y, int* x){ while(read(ttyfd, &in, 1) == 1){ bool valid = false; switch(state){ - case CURSOR_ESC: valid = (in == '\x1b'); state = CURSOR_LSQUARE; break; + case CURSOR_ESC: valid = (in == NCKEY_ESC); state = CURSOR_LSQUARE; break; case CURSOR_LSQUARE: valid = (in == '['); state = CURSOR_ROW; break; case CURSOR_ROW: if(isdigit(in)){ diff --git a/src/lib/input.c b/src/lib/input.c index 053799c1c..34cc0adea 100644 --- a/src/lib/input.c +++ b/src/lib/input.c @@ -12,8 +12,6 @@ #define CSIPREFIX "\x1b[<" static const char32_t NCKEY_CSI = 1; -static const unsigned char ESC = 0x1b; // 27 - static sig_atomic_t resize_seen; void sigwinch_handler(int signo){ @@ -75,7 +73,7 @@ void input_free_esctrie(esctrie** eptr){ static int ncinputlayer_add_input_escape(ncinputlayer* nc, const char* esc, char32_t special){ - if(esc[0] != ESC || strlen(esc) < 2){ // assume ESC prefix + content + if(esc[0] != NCKEY_ESC || strlen(esc) < 2){ // assume ESC prefix + content fprintf(stderr, "Not an escape: %s (0x%x)\n", esc, special); return -1; } @@ -205,7 +203,7 @@ handle_getc(ncinputlayer* nc, int kpress, ncinput* ni, int leftmargin, int topma if(kpress < 0){ return -1; } - if(kpress == ESC){ + if(kpress == NCKEY_ESC){ const esctrie* esc = nc->inputescapes; int candidate = 0; while(esc && esc->special == NCKEY_INVALID && nc->inputbuf_occupied){ @@ -524,7 +522,7 @@ int prep_special_keys(ncinputlayer* nc){ //fprintf(stderr, "no support for terminfo's %s\n", k->tinfo); continue; } - if(seq[0] != ESC){ + if(seq[0] != NCKEY_ESC){ //fprintf(stderr, "Terminfo's %s is not an escape sequence (%zub)\n", k->tinfo, strlen(seq)); continue; } diff --git a/src/lib/menu.c b/src/lib/menu.c index 6fbf97a9a..b49cca9dc 100644 --- a/src/lib/menu.c +++ b/src/lib/menu.c @@ -609,7 +609,7 @@ bool ncmenu_offer_input(ncmenu* n, const ncinput* nc){ return false; } return true; - }else if(nc->id == 0x1b){ + }else if(nc->id == NCKEY_ESC){ ncmenu_rollup(n); return true; }