From 02729c10b197d76223a68bf349aa0c0c4111c6bb Mon Sep 17 00:00:00 2001 From: Martin Lund Date: Fri, 15 Jul 2022 11:58:53 +0200 Subject: [PATCH] Add support for remapping prefix key Make it possible to remap the prefix key (default: ctrl-t) by setting the prefix-ctrl-key variable in the configuration file. Allowed values are in the range a..z. Example, to set the prefix key to ctrl-a simply do: prefix-ctrl-key = a --- README.md | 2 -- man/tio.1.in | 6 +++--- src/configfile.c | 9 +++++++++ src/main.c | 2 +- src/misc.h | 1 + src/options.c | 4 ++-- src/options.h | 2 ++ src/tty.c | 43 ++++++++++++++++++------------------------- src/tty.h | 1 - 9 files changed, 36 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 2fdfc5f..6587330 100644 --- a/README.md +++ b/README.md @@ -89,8 +89,6 @@ The command-line interface is straightforward as reflected in the output from Options and sub-configurations may be set via configuration file. - In session, press ctrl-t q to quit. - See the man page for more details. ``` diff --git a/man/tio.1.in b/man/tio.1.in index e7b5357..cea8b98 100644 --- a/man/tio.1.in +++ b/man/tio.1.in @@ -201,7 +201,7 @@ Display help. .SH "KEYS" .PP .TP 16n -In session, the following key sequences are intercepted as tio commands: +In session, the following key sequences, a prefix key (default: ctrl-t) followed by a command key, are intercepted as tio commands: .IP "\fBctrl-t ?" List available key commands .IP "\fBctrl-t b" @@ -218,8 +218,6 @@ Clear screen Quit .IP "\fBctrl-t s" Show TX/RX statistics -.IP "\fBctrl-t t" -Send ctrl-t key code .IP "\fBctrl-t L" Show line states (DTR, RTS, CTS, DSR, DCD, RI) .IP "\fBctrl-t d" @@ -315,6 +313,8 @@ Colorize tio text using ANSI color code ranging from 0 to 255 Enable hexadecimal mode .IP "\fBsocket" Set socket to redirect I/O to +.IP "\fBprefix-ctrl-key" +Set prefix ctrl key (a..z, default: t) .SH "CONFIGURATION FILE EXAMPLES" diff --git a/src/configfile.c b/src/configfile.c index 20a789d..e49fa96 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -237,6 +237,15 @@ static int data_handler(void *user, const char *section, const char *name, asprintf(&c->socket, "%s", value); option.socket = c->socket; } + else if (!strcmp(name, "prefix-ctrl-key")) + { + if (ctrl_key_code(value[0]) > 0) + { + option.prefix_code = ctrl_key_code(value[0]); + option.prefix_key = value[0]; + } + } + } return 0; } diff --git a/src/main.c b/src/main.c index d29525f..e5c99eb 100644 --- a/src/main.c +++ b/src/main.c @@ -95,7 +95,7 @@ int main(int argc, char *argv[]) tio_printf("tio v%s", VERSION); if (interactive_mode) { - tio_printf("Press ctrl-t q to quit"); + tio_printf("Press ctrl-%c q to quit", option.prefix_key); } /* Open socket */ diff --git a/src/misc.h b/src/misc.h index 734cd9b..23208a6 100644 --- a/src/misc.h +++ b/src/misc.h @@ -26,3 +26,4 @@ char * current_time(void); void delay(long ms); long string_to_long(char *string); +int ctrl_key_code(unsigned char key); diff --git a/src/options.c b/src/options.c index cc4076b..43ee530 100644 --- a/src/options.c +++ b/src/options.c @@ -67,6 +67,8 @@ struct option_t option = .map = "", .color = 15, .hex_mode = false, + .prefix_code = 20, // ctrl-t + .prefix_key = 't', }; void print_help(char *argv[]) @@ -101,8 +103,6 @@ void print_help(char *argv[]) printf("\n"); printf("Options and sub-configurations may be set via configuration file.\n"); printf("\n"); - printf("In session, press ctrl-t q to quit.\n"); - printf("\n"); printf("See the man page for more details.\n"); } diff --git a/src/options.h b/src/options.h index 3aecbe4..fadc4b9 100644 --- a/src/options.h +++ b/src/options.h @@ -60,6 +60,8 @@ struct option_t const char *socket; int color; bool hex_mode; + unsigned char prefix_code; + unsigned char prefix_key; }; extern struct option_t option; diff --git a/src/tty.c b/src/tty.c index 4d17c98..df9559f 100644 --- a/src/tty.c +++ b/src/tty.c @@ -262,7 +262,7 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c forward = &unused_bool; /* Handle escape key commands */ - if (previous_char == KEY_CTRL_T) + if (previous_char == option.prefix_code) { /* Do not forward input char to output by default */ *forward = false; @@ -271,22 +271,21 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c { case KEY_QUESTION: tio_printf("Key commands:"); - tio_printf(" ctrl-t ? List available key commands"); - tio_printf(" ctrl-t b Send break"); - tio_printf(" ctrl-t c Show configuration"); - tio_printf(" ctrl-t d Toggle DTR line"); - tio_printf(" ctrl-t D Pulse DTR line"); - tio_printf(" ctrl-t e Toggle local echo mode"); - tio_printf(" ctrl-t h Toggle hexadecimal mode"); - tio_printf(" ctrl-t l Clear screen"); - tio_printf(" ctrl-t L Show line states"); - tio_printf(" ctrl-t q Quit"); - tio_printf(" ctrl-t r Toggle RTS line"); - tio_printf(" ctrl-t s Show statistics"); - tio_printf(" ctrl-t t Send ctrl-t key code"); - tio_printf(" ctrl-t T Toggle line timestamp mode"); - tio_printf(" ctrl-t U Toggle conversion to uppercase"); - tio_printf(" ctrl-t v Show version"); + tio_printf(" ctrl-%c ? List available key commands", option.prefix_key); + tio_printf(" ctrl-%c b Send break", option.prefix_key); + tio_printf(" ctrl-%c c Show configuration", option.prefix_key); + tio_printf(" ctrl-%c d Toggle DTR line", option.prefix_key); + tio_printf(" ctrl-%c D Pulse DTR line", option.prefix_key); + tio_printf(" ctrl-%c e Toggle local echo mode", option.prefix_key); + tio_printf(" ctrl-%c h Toggle hexadecimal mode", option.prefix_key); + tio_printf(" ctrl-%c l Clear screen", option.prefix_key); + tio_printf(" ctrl-%c L Show line states", option.prefix_key); + tio_printf(" ctrl-%c q Quit", option.prefix_key); + tio_printf(" ctrl-%c r Toggle RTS line", option.prefix_key); + tio_printf(" ctrl-%c s Show statistics", option.prefix_key); + tio_printf(" ctrl-%c T Toggle line timestamp mode", option.prefix_key); + tio_printf(" ctrl-%c U Toggle conversion to uppercase", option.prefix_key); + tio_printf(" ctrl-%c v Show version", option.prefix_key); break; case KEY_SHIFT_L: @@ -364,12 +363,6 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c tio_printf(" Received %lu bytes", rx_total); break; - case KEY_T: - /* Send ctrl-t key code upon ctrl-t t sequence */ - *output_char = KEY_CTRL_T; - *forward = true; - break; - case KEY_SHIFT_T: option.timestamp += 1; switch (option.timestamp) @@ -1057,8 +1050,8 @@ int tty_connect(void) if (interactive_mode) { - /* Do not forward ctrl-t key */ - if (input_char == KEY_CTRL_T) + /* Do not forward prefix key */ + if (input_char == option.prefix_code) { forward = false; } diff --git a/src/tty.h b/src/tty.h index 416fc97..a8da42b 100644 --- a/src/tty.h +++ b/src/tty.h @@ -33,7 +33,6 @@ #define KEY_S 0x73 #define KEY_T 0x74 #define KEY_SHIFT_T 0x54 -#define KEY_CTRL_T 0x14 #define KEY_U 0x55 #define KEY_V 0x76 #define KEY_D 0x64