diff options
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/TUI/module.jai | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/modules/TUI/module.jai b/modules/TUI/module.jai index 9cc7e5d..796334a 100644 --- a/modules/TUI/module.jai +++ b/modules/TUI/module.jai @@ -386,11 +386,18 @@ read_input :: (count_limit: int = -1, terminators: .. u8) -> string { } } -// TODO UNTESTED read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key { + /* + Use the get_key to read user input and show it on screen. + Should allow to move the cursor left and right and to delete/backspace. + Enter should end the input, returning the input string and the Enter key. + Escape should discard the input returning an empty string and a Escape key. + Resize should discard the input returning an empty string and a Resize key. + */ + assert(count_limit >= 0, "Invalid value on count_limit parameter."); - str := alloc_string(count_limit); // TODO Alloc like a boss... + str := alloc_string(count_limit); str.count = 0; idx := 0; @@ -402,7 +409,8 @@ read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key { key := Keys.None; while true { - // TODO How to alloc/release temporary memory here? + auto_release_temp(); + key = get_key(); if key == { @@ -455,10 +463,6 @@ read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key { idx += 1; } - - // append(*builder, str); - // set_cursor_position(row, col); - // write_builder(*builder, false); if is_visible { set_cursor_position(row, col); write_string(str); @@ -469,18 +473,12 @@ read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key { for 0..str.count-1 print_character(#char "*"); for str.count..count_limit-1 print_character(#char " "); } - // print(">%<", builder_to_string(*builder,, temporary_allocator)); + set_cursor_position(row, col+idx); } write_strings(Commands.StopBlinking, Commands.DefaultShape); - /* - Use the get_key to read user input and show it on screen... should allow to move the cursor left and right and to delete/backspace. - Enter should end the input, returning the input string and the Enter key. - Escape should discard the input returning an empty string and a Escape key. - Resize should discard the input returning an empty string and a Resize key. - */ - // result := ifx key == Keys.Enter then builder_to_string(*builder) else ""; + result := ifx key == Keys.Enter then str else ""; return result, key; } |
