diff --git a/src/global.c b/src/global.c index 47784fac7b684335ade7a0a73122ebbc30338afa..69c66473508d4c5996a1d02ccb697e10a73b98c6 100644 --- 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 index e5c814aff432091818562f0916a9dda2716717af..6e55f4948346324a2a809f4cd97e0e83eb7e5ede 100644 --- 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 index 039ceb7f17f2928ee495e32da2f6c8a8f4a3ec14..6396f3735127d791d778d8e0ff5347d686c0c810 100644 --- 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 index 5fe84e4feacb385d125b8c357d96132434ee3bde..bcfb8a2adf3fe595f6b78bc29ec13fc44886e129 100644 --- 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. */