aboutsummaryrefslogtreecommitdiff
path: root/modules/TUI/module.jai
diff options
context:
space:
mode:
Diffstat (limited to 'modules/TUI/module.jai')
-rw-r--r--modules/TUI/module.jai51
1 files changed, 25 insertions, 26 deletions
diff --git a/modules/TUI/module.jai b/modules/TUI/module.jai
index 98afe3d..5fdf3b9 100644
--- a/modules/TUI/module.jai
+++ b/modules/TUI/module.jai
@@ -389,18 +389,18 @@ read_input :: (count_limit: int = -1, terminators: .. u8) -> string {
// TODO UNTESTED
read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key {
assert(count_limit >= 0, "Invalid value on count_limit parameter.");
- str := alloc_string(count_limit); // TODO Alloc like a boss...
- write_strings(Commands.StartBlinking, Commands.BlinkingUnderlineShape);
-
- row, col := get_cursor_position();
+ str := alloc_string(count_limit); // TODO Alloc like a boss...
+ str.count = 0;
idx := 0;
- key := Keys.None;
-
// TODO Some of these may be nice to have:
// > https://unix.stackexchange.com/questions/255707/what-are-the-keyboard-shortcuts-for-the-command-line
+ row, col := get_cursor_position();
+ write_strings(Commands.StartBlinking, Commands.BlinkingUnderlineShape);
+
+ key := Keys.None;
while true {
// TODO How to alloc/release temporary memory here?
key = get_key();
@@ -412,29 +412,24 @@ read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key {
break;
case Keys.Left;
- if idx == 0 continue;
- idx -= 1;
+ if idx > 0 then idx -= 1;
+
+ case Keys.Right;
+ if idx < str.count then 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;
- while str[idx] == 0 && idx > 0 {
- idx -= 1;
- }
- idx += 1;
+ idx = str.count;
case Keys.Delete;
- if idx == str.count-1 continue;
+ if idx == str.count continue;
for idx..str.count-2 {
str.data[it] = str.data[it+1];
}
str.data[str.count-1] = 0;
+ str.count -= 1;
case Keys.Backspace;
if idx == 0 continue;
@@ -443,17 +438,21 @@ read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key {
str.data[it] = str.data[it+1];
}
str.data[str.count-1] = 0;
+ str.count -= 1;
case;
- if idx >= str.count continue;
- if !is_escape_code(key) {
- key_str := to_string(key);
- for < str.count-1..idx {
- str.data[it] = str.data[it-1];
- }
- str.data[idx] = key_str.data[0];
- idx += 1;
+ if idx >= count_limit continue;
+ if is_escape_code(key) continue;
+
+ for < count_limit..idx+1 {
+ str.data[it] = str.data[it-1];
}
+
+ key_str := to_string(key);
+ str.data[idx] = key_str.data[0];
+
+ if str.count < count_limit then str.count += 1;
+ idx += 1;
}