From 3b2f72538e3081849d87ac6a6fcbc751b43b0e70 Mon Sep 17 00:00:00 2001 From: nick black Date: Sat, 14 Dec 2019 18:37:09 -0500 Subject: [PATCH] decode more special keys in notcurses-input #134 --- include/notcurses.h | 14 ++++++++++++++ src/input/input.cpp | 16 ++++++++++++++++ src/lib/input.c | 4 ++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/include/notcurses.h b/include/notcurses.h index f018321ce..8f69fc7b3 100644 --- a/include/notcurses.h +++ b/include/notcurses.h @@ -396,6 +396,20 @@ ncplane_putsimple_yx(struct ncplane* n, int y, int x, char c){ return ncplane_putsimple(n, c); } +// Replace the cell underneath the cursor with the provided wide char 'w'. +// Advance the cursor by the character's width as reported by wcwidth(). On +// success, returns 1. On failure, returns -1. +API int ncplane_putwc(struct ncplane* n, wchar_t w); + +// Call ncplane_putwc() after successfully moving to y, x. +static inline int +ncplane_putwc_yx(struct ncplane* n, int y, int x, wchar_t w){ + if(ncplane_cursor_move_yx(n, y, x)){ + return -1; + } + return ncplane_putwc(n, w); +} + // Replace the cell underneath the cursor with the provided EGC, using the // specified 'attr' and 'channels' for styling, and advance the cursor by the // width of the cluster (but not past the end of the plane). On success, returns diff --git a/src/input/input.cpp b/src/input/input.cpp index aa64af22a..7feca5685 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -39,6 +39,22 @@ const char* nckeystr(wchar_t spkey){ case NCKEY_F10: return "F10"; case NCKEY_F11: return "F11"; case NCKEY_F12: return "F12"; + case NCKEY_BACKSPACE: return "backspace"; + case NCKEY_CENTER: return "center"; + case NCKEY_ENTER: return "enter"; + case NCKEY_CLS: return "clear"; + case NCKEY_DLEFT: return "down+left"; + case NCKEY_DRIGHT: return "down+right"; + case NCKEY_ULEFT: return "up+left"; + case NCKEY_URIGHT: return "up+right"; + case NCKEY_BEGIN: return "begin"; + case NCKEY_CANCEL: return "cancel"; + case NCKEY_CLOSE: return "close"; + case NCKEY_COMMAND: return "command"; + case NCKEY_COPY: return "copy"; + case NCKEY_EXIT: return "exit"; + case NCKEY_PRINT: return "print"; + case NCKEY_REFRESH: return "refresh"; default: return "unknown"; } } diff --git a/src/lib/input.c b/src/lib/input.c index d35eed444..9f4ed76bb 100644 --- a/src/lib/input.c +++ b/src/lib/input.c @@ -129,8 +129,8 @@ handle_getc(notcurses* nc, int kpress){ } // FIXME ungetc on failure! walk trie backwards or something } - if(kpress == 0x04){ // ctrl-d, treated as EOF - return (wchar_t)-1; + if(kpress == 0x7f){ // ASCII del, treated as backspace + return NCKEY_BACKSPACE; } if(kpress < 0x80){ return kpress;