From d03216a1acde691ee16105a48be654329c3494c1 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Wed, 28 Jan 2004 18:21:21 +0000 Subject: [PATCH] use raw mode in get_verbatim_kbinput(), so that we don't have to deal with interrupt-generating keys there git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1638 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 22 ++++++++++++++++------ src/nano.c | 26 +++----------------------- src/winio.c | 12 ++++++++++-- 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6ab68ca9..d1ec136a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,10 @@ CVS code - - New function used to write the current marked selection to a file, split out from do_writeout(). (DLR) - nano.c: + do_verbatim_input() + - Remove the now-unneeded code to disable XON, XOFF, and + suspend, since we now go into raw mode in + get_verbatim_kbinput() and bypass them. (DLR) do_spell(), do_int_speller(), do_alt_speller() - Modify to write only the current selection from a file to the temporary file used for spell checking when the mark is on, @@ -26,7 +30,9 @@ CVS code - main() - Move the call to raw() on systems that don't define _POSIX_VDISABLE outside the main input/output loop, as it - doesn't need to be called every time through the loop. (DLR) + doesn't need to be called every time through the loop. Call it + instead of cbreak() on such systems, as it overrides cbreak() + anyway. (DLR) - search.c: do_replace_loop() - Fix segfault when doing a regex replace of a string that @@ -34,12 +40,16 @@ CVS code - anything). (David Benbennick) - winio.c: get_verbatim_kbinput() - - Set keypad() to FALSE while reading input, and set it back to - TRUE afterwards. This ensures that we don't end up reading in - extended keypad values that are outside the ASCII range. - (Also, with keypad() set to TRUE, xterm generates + - Set keypad() to FALSE and switch to raw mode while reading + input, and set it keypad() back to TRUE and go back into + cbreak mode afterwards. (Note that if _POSIX_VDISABLE isn't + defined, we don't need to change to or from raw mode since + we're already in it exclusively.) This ensures that we don't + end up reading in extended keypad values that are outside the + ASCII range or having to deal with interrupt-generating key + values. Also, with keypad() set to TRUE, xterm generates KEY_BACKSPACE when the user hits Ctrl-H, which, when cut down - to ASCII range, ends up being Ctrl-G, which can be confusing.) + to ASCII range, ends up being Ctrl-G, which can be confusing. (DLR) get_accepted_kbinput() - Don't use "kbinput = wgetch(win)" as a switch value. (DLR) diff --git a/src/nano.c b/src/nano.c index bad05acb..19efdfe9 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1003,19 +1003,8 @@ int do_verbatim_input(void) { char *verbatim_kbinput; /* Used to hold verbatim input */ int verbatim_len; /* Length of verbatim input */ - int old_preserve = ISSET(PRESERVE), old_suspend = ISSET(SUSPEND); int i; - /* Turn off Ctrl-Q (XON), Ctrl-S (XOFF), and Ctrl-Z (suspend) if - * they're on, so that we can use them to insert ^Q, ^S, and ^Z - * verbatim. */ - if (old_preserve) - UNSET(PRESERVE); - if (old_suspend) - UNSET(SUSPEND); - if (old_preserve || old_suspend) - signal_init(); - statusbar(_("Verbatim input")); verbatim_kbinput = get_verbatim_kbinput(edit, &verbatim_len, 1); @@ -1029,15 +1018,6 @@ int do_verbatim_input(void) free(verbatim_kbinput); - /* Turn Ctrl-Q, Ctrl-S, and Ctrl-Z back on if they were on - * before. */ - if (old_preserve) - SET(PRESERVE); - if (old_suspend) - SET(SUSPEND); - if (old_preserve || old_suspend) - signal_init(); - return 1; } @@ -3447,13 +3427,13 @@ int main(int argc, char *argv[]) initscr(); savetty(); nonl(); - cbreak(); - noecho(); - #ifndef _POSIX_VDISABLE /* We're going to have to do it the old way, i.e, on Cygwin. */ raw(); +#else + cbreak(); #endif + noecho(); /* Set up some global variables */ global_init(0); diff --git a/src/winio.c b/src/winio.c index fd717078..d7ae9955 100644 --- a/src/winio.c +++ b/src/winio.c @@ -61,8 +61,12 @@ char *get_verbatim_kbinput(WINDOW *win, int *kbinput_len, int kbinput; /* Turn the keypad off so that we don't get extended keypad values, - * all of which are outside the ASCII range. */ + * all of which are outside the ASCII range, and switch to raw mode + * so that we can type ^Q, ^S, and ^Z without getting interrupts. */ keypad(win, FALSE); +#ifndef _POSIX_VDISABLE + raw(); +#endif kbinput = wgetch(win); verbatim_kbinput = charalloc(1); @@ -84,8 +88,12 @@ char *get_verbatim_kbinput(WINDOW *win, int *kbinput_len, nodelay(win, FALSE); } - /* Turn the keypad back on now that we're done. */ + /* Turn the keypad back on and switch back to cbreak mode now that + * we're done. */ keypad(win, TRUE); +#ifndef _POSIX_VDISABLE + cbreak(); +#endif #ifdef DEBUG fprintf(stderr, "get_verbatim_kbinput(): verbatim_kbinput = %s\n", verbatim_kbinput);