diff options
| -rw-r--r-- | modules/TUI/module.jai | 56 | ||||
| -rw-r--r-- | ttt.jai | 4 |
2 files changed, 38 insertions, 22 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! @@ -14,8 +14,8 @@ // this program. If not, see <https://www.gnu.org/licenses/>. // Compilation commands: -// - release : jai ttt.jai -import_dir . -quiet -x64 -release -// - debug : jai ttt.jai -import_dir . -quiet -x64 +// - release : jai ttt.jai -quiet -x64 -release +// - debug : jai ttt.jai -quiet -x64 #import "Basic"()(MEMORY_DEBUGGER=true); // TODO Remove after final debug sessions. This takes up ~30MB of RAM. #import "System"; |
