From e0c4f9c5feec4a6d7311ec1ad26cf8de3da94ec0 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Wed, 27 Apr 2016 14:37:31 +0200
Subject: [PATCH] input: give more detailed feedback when an unbound key is
 struck

---
 src/browser.c |  3 ++-
 src/help.c    |  3 ++-
 src/nano.c    | 19 +++++++++++++++++--
 src/proto.h   |  1 +
 4 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/src/browser.c b/src/browser.c
index 974b6431..194230e3 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -332,7 +332,8 @@ char *do_browser(char *path, DIR *dir)
 	} else if (func == do_exit) {
 	    /* Exit from the file browser. */
 	    break;
-	}
+	} else
+	    unbound_key(kbinput);
     }
     titlebar(NULL);
     edit_refresh();
diff --git a/src/help.c b/src/help.c
index 98066c55..28add5e5 100644
--- a/src/help.c
+++ b/src/help.c
@@ -161,7 +161,8 @@ void do_help(void)
 	} else if (func == do_exit) {
 	    /* Exit from the help viewer. */
 	    break;
-	}
+	} else
+	    unbound_key(kbinput);
     }
 
     if (old_no_help) {
diff --git a/src/nano.c b/src/nano.c
index f7ef4a1a..4492061a 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1563,6 +1563,22 @@ void terminal_init(void)
 #endif
 }
 
+/* Say that an unbound key was struck, and if possible which one. */
+void unbound_key(int code)
+{
+    if (func_key)
+	statusbar(_("Unbound key"));
+    else if (meta_key) {
+	if (0x60 < code && code < 0x7B)
+	    code -= 0x20;
+	statusbar(_("Unbound key: M-%c"), code);
+    } else if (code < 0x20)
+	statusbar(_("Unbound key: ^%c"), code + 0x40);
+    else
+	statusbar(_("Unbound key: %c"), code);
+    beep();
+}
+
 /* Read in a character, interpret it as a shortcut or toggle if
  * necessary, and return it.
  * If allow_funcs is FALSE, don't actually run any functions associated
@@ -1612,8 +1628,7 @@ int do_input(bool allow_funcs)
      * function key, and it's not a shortcut or toggle, throw it out. */
     if (!have_shortcut) {
 	if (is_ascii_cntrl_char(input) || meta_key || func_key) {
-	    statusbar(_("Unknown Command"));
-	    beep();
+	    unbound_key(input);
 	    meta_key = FALSE;
 	    func_key = FALSE;
 	    input = ERR;
diff --git a/src/proto.h b/src/proto.h
index 418a9d01..59a44c06 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -498,6 +498,7 @@ void enable_signals(void);
 void disable_flow_control(void);
 void enable_flow_control(void);
 void terminal_init(void);
+void unbound_key(int code);
 int do_input(bool allow_funcs);
 #ifndef DISABLE_MOUSE
 int do_mouse(void);
-- 
GitLab