curses erase char and kill char

Support user's terminal settings for erase char and for kill char.
Erase char is typically <delete> or <backspace>, both of which are
already explicitly handled so probably no effect there.  Kill char
(generally ^U these days) will be honored unless it is a printable
character (don't know whether there are any troglodytes out there
who still use '@' for that...).  The current handling for ESC works
the same if there is any input to kill, but yields 'cancelled' when
there isn't.

That's for message window getline(), which operates char-by-char.
The popup getline() uses a curses routine to get an entire string
and already honors kill char but treats ESC as input of ^[.
This commit is contained in:
PatR
2019-06-27 17:18:07 -07:00
parent fa4f9bb8ae
commit df8eac79b5
3 changed files with 26 additions and 7 deletions
+10 -6
View File
@@ -9,6 +9,10 @@
#include "cursmesg.h"
#include <ctype.h>
/* defined in sys/<foo>/<foo>tty.c or cursmain.c as last resort;
set up by curses_init_nhwindows() */
extern char erase_char, kill_char;
/*
* Note: references to "More>>" mean ">>", the curses rendition of "--More--".
*/
@@ -591,19 +595,19 @@ curses_message_win_getline(const char *prompt, char *answer, int buffer)
#else
ch = getch();
#endif
#if 0 /* [erase_char (delete one character) and kill_char (delete all
* characters) are from tty and not currently set up for curses] */
if (ch == erase_char) {
curs_set(0);
if (erase_char && ch == erase_char) {
ch = '\177'; /* match switch-case below */
/* honor kill_char if it's ^U or similar, but not if it's '@' */
} else if (ch == kill_char && (ch < ' ' || ch >= '\177')) { /*ASCII*/
} else if (kill_char && ch == kill_char
&& (ch < ' ' || ch >= '\177')) { /*ASCII*/
if (len == 0) /* nothing to kill; just start over */
continue;
ch = '\033'; /* get rid of all current input, then start over */
}
#endif
curs_set(0);
switch (ch) {
case ERR: /* should not happen */
*answer = '\0';