diff options
| author | dam <dam@gudinoff> | 2024-03-01 02:08:36 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2024-03-01 02:08:36 +0000 |
| commit | 45e56e387b713cebd78c3789ed7c234e588fbe48 (patch) | |
| tree | ca9a3f63d2ceee83422b765e2559dfcfa6465ff4 /modules | |
| parent | ce40906a177708e54ea1067ca157a308a185a164 (diff) | |
| download | task-time-tracker-45e56e387b713cebd78c3789ed7c234e588fbe48.tar.zst task-time-tracker-45e56e387b713cebd78c3789ed7c234e588fbe48.zip | |
WIP : First attempt to use hash table on escape codes.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/TUI/module.jai | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/modules/TUI/module.jai b/modules/TUI/module.jai index 3008d23..ed3f517 100644 --- a/modules/TUI/module.jai +++ b/modules/TUI/module.jai @@ -13,6 +13,7 @@ #import "Basic"; #import "String"; #import "Thread"; +#import "Hash_Table"; // Special Graphics Characters Drawings :: struct { @@ -362,6 +363,52 @@ Keys :: struct #type_info_none { CtrlAltShiftF12 : Key : #run to_key("\e[24;8~"); } +key_map: Table(string, Key); + +setup_key_map :: () { + + table_set(*key_map, "\e[A", to_key("#UP")); + table_set(*key_map, "\e[A", to_key("#UP")); + + table_set(*key_map, "\eOQ", to_key("#F2")); + table_set(*key_map, "\e[12~", to_key("#F2")); + + table_set(*key_map, "\eO2Q", to_key("#SF2")); + table_set(*key_map, "\e[1;2Q", to_key("#SF2")); + table_set(*key_map, "\e[12;2~", to_key("#SF2")); + + table_set(*key_map, "\e\e[12~", to_key("#AF2")); + table_set(*key_map, "\e\e[24~", to_key("#AF12")); + + table_set(*key_map, "\e[12^", to_key("#CF2")); + + // A good example + table_set(*key_map, "\e[21~", to_key("#F10")); + table_set(*key_map, "\e[21;1~", to_key("#MF10")); + table_set(*key_map, "\e[21;2~", to_key("#SF10")); + table_set(*key_map, "\e[21;3~", to_key("#AF10")); + table_set(*key_map, "\e[21;4~", to_key("#SAF10")); + table_set(*key_map, "\e[21;5~", to_key("#CF10")); + table_set(*key_map, "\e[21;6~", to_key("#SCF10")); + table_set(*key_map, "\e[21;7~", to_key("#ACF10")); + table_set(*key_map, "\e[21;8~", to_key("#SACF10")); + + table_set(*key_map, "\e[24~", to_key("#F12")); + table_set(*key_map, "\e[24;2~", to_key("#SF12")); + table_set(*key_map, "\e[24;3~", to_key("#AF12")); + + // TODO Try with: + // - konsole + // - xterm + // - rxvt-unicode + // - kittyterminal + // - termux + + // F2 : Key : #run to_key("\eOQ"); + // F2 : 1b 4f 51 : ^OQ : -> \e[12~ + // Shift+ F2 : 1b 4f 32 51 : ^O2Q : -> \e[12;2~ +} + to_key :: inline (str: $T) -> Key #modify { return T == ([]u8) || T == string; } { k: Key; // #if DEBUG { @@ -491,10 +538,16 @@ get_key :: (timeout_milliseconds: s32 = -1) -> Key { assert(input_string.count <= KEY_SIZE, "Received oversized terminal sequence."); // TODO to_parse.count = ifx input_string.count > KEY_SIZE then KEY_SIZE else input_string.count; // TODO We should look into the input_string and search for the following escape sequence or somehting!? - WIP HERE + // WIP HERE // A possible way to solve this is to create a LUT, and then, grow the to_parse.count from 2 to KEY_SIZE and return as soon // as we ding a match on the LUT. // If the LUT is too big... maybe use a hash-table. + + key, success := table_find(*key_map, to_parse); + if success { + advance(*input_string, to_parse.count); + return key; + } if compare(to_parse, "\e[A") == 0 { advance(*input_string, to_parse.count); @@ -649,6 +702,8 @@ read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key { start :: () { if initialized == true return; + setup_key_map(); // TODO This is being called multiple times... please fix me! + input_string.data = input_buffer.data; input_string.count = 0; input_override = xx Keys.None; |
