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
This commit is contained in:
Martin Lund 2022-07-15 11:58:53 +02:00
parent 1c53af0681
commit 02729c10b1
9 changed files with 36 additions and 34 deletions

View file

@ -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.
```

View file

@ -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"

View file

@ -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;
}

View file

@ -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 */

View file

@ -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);

View file

@ -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");
}

View file

@ -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;

View file

@ -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;
}

View file

@ -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