From 8e341e1b22023d6f172fb8ed908197c232545129 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Wed, 24 May 2006 17:36:00 +0000 Subject: [PATCH] ignore unhandled meta key sequences and escape sequences, and indicate it on the statusbar when we get an unhandled shortcut or toggle, as Pico does git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3554 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 6 ++++++ src/chars.c | 7 +++++++ src/nano.c | 11 +++++++++++ src/prompt.c | 9 +++++++++ src/proto.h | 1 + src/winio.c | 6 +++--- 6 files changed, 37 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 03769664..8124feb7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -96,6 +96,12 @@ CVS code - do_page_down(), do_up(), do_scroll_up(), do_down(), do_scroll_down(), do_input(), do_search(), do_research(), and do_delete(). (DLR) + - Ignore unhandled meta key sequences and escape sequences, and + indicate it on the statusbar when we get an unhandled shortcut + or toggle, as Pico does. New function is_ascii_cntrl_char(); + changes to do_input(), do_statusbar_input(), and + parse_kbinput(). (DLR, suggested by Nick Warne and Benno + Schulenberg) - browser.c: do_browser() - Reference NANO_GOTODIR_(ALT|F)?KEY instead of diff --git a/src/chars.c b/src/chars.c index 0f78767c..5f7c3c54 100644 --- a/src/chars.c +++ b/src/chars.c @@ -120,6 +120,13 @@ bool is_blank_mbchar(const char *c) return isblank((unsigned char)*c); } +/* This function is equivalent to iscntrl(), except in that it only + * handles non-high-bit control characters. */ +bool is_ascii_cntrl_char(int c) +{ + return (0 <= c && c < 32); +} + /* This function is equivalent to iscntrl(), except in that it also * handles high-bit control characters. */ bool is_cntrl_char(int c) diff --git a/src/nano.c b/src/nano.c index 634fc968..ac6b4886 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1297,6 +1297,17 @@ int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool #endif ); + /* If we got a non-high-bit control key or a Meta key sequence, and + * it's not a shortcut or toggle, ignore it, and indicate this on + * the statusbar. */ + if (*s_or_t == FALSE) { + if (is_ascii_cntrl_char(input) || *meta_key == TRUE) { + input = ERR; + *meta_key = FALSE; + statusbar(_("Unknown Command")); + } + } + if (allow_funcs) { /* If we got a character, and it isn't a shortcut or toggle, * it's a normal text character. Display the warning if we're diff --git a/src/prompt.c b/src/prompt.c index 140d2bfd..3fa7b909 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -99,6 +99,15 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t, /* Set s_or_t to TRUE if we got a shortcut. */ *s_or_t = have_shortcut; + /* If we got a non-high-bit control key or a Meta key sequence, and + * it's not a shortcut or toggle, ignore it. */ + if (*s_or_t == FALSE) { + if (is_ascii_cntrl_char(input) || *meta_key == TRUE) { + input = ERR; + *meta_key = FALSE; + } + } + if (allow_funcs) { /* If we got a character, and it isn't a shortcut or toggle, * it's a normal text character. Display the warning if we're diff --git a/src/proto.h b/src/proto.h index 138b371a..b55e8fa9 100644 --- a/src/proto.h +++ b/src/proto.h @@ -174,6 +174,7 @@ bool niswblank(wchar_t wc); bool is_byte(int c); bool is_alnum_mbchar(const char *c); bool is_blank_mbchar(const char *c); +bool is_ascii_cntrl_char(int c); bool is_cntrl_char(int c); #ifdef ENABLE_UTF8 bool is_cntrl_wchar(wchar_t wc); diff --git a/src/winio.c b/src/winio.c index 50eb5a23..df869b55 100644 --- a/src/winio.c +++ b/src/winio.c @@ -536,10 +536,10 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key) &ignore_seq); /* If the escape sequence is unrecognized and - * not ignored, put back all of its characters - * except for the initial escape. */ + * not ignored, indicate this on the + * statusbar. */ if (retval == ERR && !ignore_seq) - unget_input(seq, seq_len); + statusbar(_("Unknown Command")); free(seq); } -- 2.39.5