diff options
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/TUI/module.jai | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/modules/TUI/module.jai b/modules/TUI/module.jai index 6aeac68..97a520b 100644 --- a/modules/TUI/module.jai +++ b/modules/TUI/module.jai @@ -187,19 +187,9 @@ to_string :: inline (key: Key) -> string { // TODO FIXME TEMPORARY MEMORY } is_escape_code :: inline (key: Key) -> bool { - /* - TODO Check if LSB is not # but there is a `#`, then it's a escape code... or NONE... or RESIZE :S - Or...we could change the special codes and set the `#` at the end... then we could simply do: - return (key && 0x00FF) ^ # == 0 && (key && 0xFF00) == 0 - */ - - result := false; - - while key != 0 { - key >>= 8; - result |= ((key ^ #char "#") == 0); - } - return result; + beginsWithEscape := ((key & 0xFF) ^ #char "#") == 0; + hasSomethingElse := (key & (~0xFF)) != 0; + return beginsWithEscape && hasSomethingElse; } Keys :: struct #type_info_none { @@ -215,8 +205,8 @@ Keys :: struct #type_info_none { Up : Key : #run to_key("#up"); Down : Key : #run to_key("#down"); - Right : Key : #run to_key("right"); - Left : Key : #run to_key("left"); + Right : Key : #run to_key("#right"); + Left : Key : #run to_key("#left"); Home : Key : #run to_key("#home"); End : Key : #run to_key("#end"); @@ -412,11 +402,13 @@ read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key { // TODO Some of these may be nice to have: // > https://unix.stackexchange.com/questions/255707/what-are-the-keyboard-shortcuts-for-the-command-line - while key != Keys.Resize && key != Keys.Escape { + while true { // TODO How to alloc/release temporary memory here? key = get_key(); if key == { + case Keys.Resize; #through; + case Keys.Escape; #through; case Keys.Enter; break; @@ -424,10 +416,16 @@ read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key { if idx == 0 continue; idx -= 1; + case Keys.Home; + idx = 0; + case Keys.Right; if idx == str.count-1 continue; idx += 1; + case Keys.End; + idx = str.count-1; + case Keys.Delete; if idx == str.count-1 continue; for idx..str.count-2 { @@ -442,10 +440,11 @@ read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key { } case; - if is_escape_code(key) continue; // TODO NOT WORKING FIX THIS - key_str := to_string(key); - str.data[idx] = key_str.data[0]; - idx += 1; + if !is_escape_code(key) { + key_str := to_string(key); + str.data[idx] = key_str.data[0]; + idx += 1; + } } |
