mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
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:
parent
1c53af0681
commit
02729c10b1
9 changed files with 36 additions and 34 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
43
src/tty.c
43
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue