aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authordam <dam@gudinoff>2024-02-29 01:08:40 +0000
committerdam <dam@gudinoff>2024-02-29 01:08:40 +0000
commitce40906a177708e54ea1067ca157a308a185a164 (patch)
tree50a4407ab69b6cae154603074d214dec3736b96b /modules
parentc181df188164853845441c7798e8aa45f843ee65 (diff)
downloadtask-time-tracker-ce40906a177708e54ea1067ca157a308a185a164.tar.zst
task-time-tracker-ce40906a177708e54ea1067ca157a308a185a164.zip
WIP : Improving get_key to deal with escape codes.
Diffstat (limited to 'modules')
-rw-r--r--modules/TUI/module.jai56
1 files changed, 36 insertions, 20 deletions
diff --git a/modules/TUI/module.jai b/modules/TUI/module.jai
index 2f32752..3008d23 100644
--- a/modules/TUI/module.jai
+++ b/modules/TUI/module.jai
@@ -244,8 +244,6 @@ Keys :: struct #type_info_none {
...
*/
- WIP HERE
-
F1 : Key : #run to_key("\eOP");
F2 : Key : #run to_key("\eOQ");
F3 : Key : #run to_key("\eOR");
@@ -477,29 +475,47 @@ get_key :: (timeout_milliseconds: s32 = -1) -> Key {
input_string.count += bytes_read;
}
- if input_string.count > 0
- {
- utf8_bytes := count_utf8_bytes(input_string[0]);
- to_parse := input_string;
- to_parse.count = utf8_bytes;
+ if input_string.count == 0 return Keys.None;
- // Must be a terminal escape sequence.
- if utf8_bytes == 1 && input_string[0] == #char "\e" {
- 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!?
- }
+ // Assume we're parsing just a single char.
+ to_parse := input_string;
+ to_parse.count = 1;
- key := to_key(to_parse);
- advance(*input_string, to_parse.count);
- return key;
+ // Try to parse UTF8 character.
+ if is_utf8_continuation_byte(input_string[0]) {
+ to_parse.count = count_utf8_bytes(input_string[0]);
}
- // TODO try_parse_escape_code
- // {
- // assert(false, "TODO try_parse_escape_code");
- // }
+ // Try to parse escape code.
+ if input_string[0] == #char "\e" && input_string.count > 1 {
+ 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
+ // 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.
+
+ if compare(to_parse, "\e[A") == 0 {
+ advance(*input_string, to_parse.count);
+ return to_key("#UP");
+ }
+ else if compare(to_parse, "\e[B") == 0 {
+ advance(*input_string, to_parse.count);
+ return to_key("#DOWN");
+ }
+ else if compare(to_parse, "\e[C") == 0 {
+ advance(*input_string, to_parse.count);
+ return to_key("#RIGHT");
+ }
+ else if compare(to_parse, "\e[D") == 0 {
+ advance(*input_string, to_parse.count);
+ return to_key("#LEFT");
+ }
+ }
- return xx Keys.None;
+ advance(*input_string, to_parse.count);
+ return to_key(to_parse);
}
// TODO Review me!