mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Add user key-script mapping function (--keymap, Ctrl-t k)
User key-script mapping function:
You can specify the mappings as @<key-1>=<script-description-1>
@<key-2>=<script-description-2>... @<key-N>=<script-description-N>.
Script-description is script-filename or '!'script-commands.
After that,
When you press ctrl-t and <key-n>, tio executes <script-description-n>.
This user keymap takes precedence over the default settings (except for
ctrl-t q).
Example of startup option:
tio /dev/ttyUSB1 --keymap '@1=!print(tio.banner())
@2=!tio.write("test\r") @ctrl-a=!tio.write("ctrl-a\r")
@ctrl-j=test-script.tio'
Example of .tioconfig: (note: backslash escape needed.)
keymap = @1=!print(tio.banner()) @2=!tio.write("test\\r")
@ctrl-a=!tio.write("ctrl-a\\r") @ctrl-j=test-script.tio
This commit is contained in:
parent
8722b410a7
commit
60bc7e9cfe
6 changed files with 250 additions and 0 deletions
31
src/tty.c
31
src/tty.c
|
|
@ -119,6 +119,7 @@
|
|||
#define KEY_I 0x69
|
||||
#define KEY_J 0x6A
|
||||
#define KEY_SHIFT_J 0x4A
|
||||
#define KEY_K 0x6B
|
||||
#define KEY_L 0x6C
|
||||
#define KEY_SHIFT_L 0x4C
|
||||
#define KEY_M 0x6D
|
||||
|
|
@ -1099,6 +1100,26 @@ void handle_command_sequence(char input_char, char *output_char, bool *forward)
|
|||
return;
|
||||
}
|
||||
|
||||
// Handle user keymapped commands
|
||||
for (int idx = 0; idx < KEYMAP_MAX; idx++)
|
||||
{
|
||||
if ((input_char >= 0x00) && (input_char <= 0x1f))
|
||||
{
|
||||
int ctrl_key_ch = ctrl_key_char(input_char);
|
||||
if ((ctrl_key_ch >= 0) &&
|
||||
(strncmp("ctrl-", keymaps[idx].key, 5) == 0) && (keymaps[idx].key[5] == ctrl_key_ch))
|
||||
{
|
||||
script_run(keymaps[idx].func);
|
||||
goto handle_commands_end;
|
||||
}
|
||||
}
|
||||
else if (input_char == keymaps[idx].key[0] && keymaps[idx].key[1] == '\0')
|
||||
{
|
||||
script_run(keymaps[idx].func);
|
||||
goto handle_commands_end;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle commands
|
||||
switch (input_char)
|
||||
{
|
||||
|
|
@ -1128,6 +1149,7 @@ void handle_command_sequence(char input_char, char *output_char, bool *forward)
|
|||
tio_printf(" ctrl-%c x Send/Receive file via Xmodem", option.prefix_key);
|
||||
tio_printf(" ctrl-%c y Send file via Ymodem", option.prefix_key);
|
||||
tio_printf(" ctrl-%c ctrl-%c Send ctrl-%c character", option.prefix_key, option.prefix_key, option.prefix_key);
|
||||
keymaps_print("User key commands:", 1);
|
||||
break;
|
||||
|
||||
case KEY_SHIFT_L:
|
||||
|
|
@ -1203,6 +1225,7 @@ void handle_command_sequence(char input_char, char *output_char, bool *forward)
|
|||
rs485_print_config();
|
||||
}
|
||||
mappings_print();
|
||||
keymaps_print(" Keymaps:", 4);
|
||||
break;
|
||||
|
||||
case KEY_E:
|
||||
|
|
@ -1290,6 +1313,12 @@ void handle_command_sequence(char input_char, char *output_char, bool *forward)
|
|||
}
|
||||
break;
|
||||
|
||||
case KEY_K:
|
||||
/* Set keymap */
|
||||
tio_subcmd_readln("Enter keymap @<key>=<script-file>|!<script> :");
|
||||
option_parse_key_mappings(line);
|
||||
break;
|
||||
|
||||
case KEY_L:
|
||||
/* Clear screen using ANSI/VT100 escape code */
|
||||
printf("\033c");
|
||||
|
|
@ -1443,6 +1472,8 @@ void handle_command_sequence(char input_char, char *output_char, bool *forward)
|
|||
/* Ignore unknown ctrl-t escaped keys */
|
||||
break;
|
||||
}
|
||||
|
||||
handle_commands_end:
|
||||
}
|
||||
|
||||
previous_char = input_char;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue