commit 290d278f684f11448307a2871f42af67f982be46
parent 8edb0968214759b1f04f197415cbfdd0ca145340
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Fri, 29 Jul 2016 09:15:07 +0200
input: make the Ctrl+Arrow keys work on a Linux console
If this breaks your build, please send report or instructions or patch.
Diffstat:
4 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/src/global.c b/src/global.c
@@ -33,6 +33,8 @@ volatile sig_atomic_t sigwinch_counter = 0;
/* Is incremented by the handler whenever a SIGWINCH occurs. */
#endif
+bool console;
+ /* Whether we're running on a Linux VC (TRUE) or under X (FALSE). */
bool meta_key;
/* Whether the current keystroke is a Meta key. */
bool focusing = TRUE;
diff --git a/src/nano.c b/src/nano.c
@@ -2482,6 +2482,9 @@ int main(int argc, char **argv)
/* Set up the terminal state. */
terminal_init();
+ /* Check whether we're running on a Linux console. */
+ console = (getenv("DISPLAY") == NULL);
+
#ifdef DEBUG
fprintf(stderr, "Main: set up windows\n");
#endif
diff --git a/src/proto.h b/src/proto.h
@@ -30,6 +30,7 @@
extern volatile sig_atomic_t sigwinch_counter;
#endif
+extern bool console;
extern bool meta_key;
extern bool focusing;
diff --git a/src/winio.c b/src/winio.c
@@ -23,6 +23,8 @@
#include "proto.h"
#include "revision.h"
+#include <sys/ioctl.h>
+
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
@@ -502,6 +504,24 @@ int parse_kbinput(WINDOW *win)
return sc_seq_or(do_next_block, 0);
#endif
+ /* When not running under X, check for the bare arrow keys whether
+ * the Ctrl key is being held together with them. */
+ if (console && (retval == KEY_UP || retval == KEY_DOWN ||
+ retval == KEY_LEFT || retval == KEY_RIGHT)) {
+ unsigned char modifiers = 6;
+
+ if (ioctl(0, TIOCLINUX, &modifiers) >= 0 && (modifiers & 0x04)) {
+ if (retval == KEY_UP)
+ return sc_seq_or(do_prev_block, 0);
+ else if (retval == KEY_DOWN)
+ return sc_seq_or(do_next_block, 0);
+ else if (retval == KEY_LEFT)
+ return sc_seq_or(do_prev_word_void, 0);
+ else
+ return sc_seq_or(do_next_word_void, 0);
+ }
+ }
+
switch (retval) {
#ifdef KEY_SLEFT
/* Slang doesn't support KEY_SLEFT. */