diff options
| -rw-r--r-- | TUI/module.jai | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/TUI/module.jai b/TUI/module.jai index 64567fa..0ae0398 100644 --- a/TUI/module.jai +++ b/TUI/module.jai @@ -488,10 +488,6 @@ read_input :: (count_limit: int = -1, terminators: .. u8) -> string { assert_is_initialized(); assert(count_limit >= 0 || terminators.count > 0, "Infinite loop detected, aborting."); // TODO Maybe just return!? - // if count_limit < 0 && terminators.count == 0 { - // TODO Write error to log. - // return ""; - // } if count_limit < 0 { builder: String_Builder; @@ -500,12 +496,16 @@ read_input :: (count_limit: int = -1, terminators: .. u8) -> string { while read_loop := true { buffer := get_current_buffer(*builder); buffer_data := get_buffer_data(buffer); + + previous_count := buffer.count; buffer.count += OS_read_input(buffer_data + buffer.count, buffer.allocated - buffer.count); - for 0..buffer.count-1 { + + for previous_count..buffer.count-1 { for t: terminators { if buffer_data[it] == t then break read_loop; } } + if buffer.count == buffer.allocated then expand(*builder); OS_wait_for_input(); } @@ -516,13 +516,18 @@ read_input :: (count_limit: int = -1, terminators: .. u8) -> string { buffer.count = 0; while read_loop := true { + + previous_count := buffer.count; buffer.count += OS_read_input(buffer.data + buffer.count, count_limit - buffer.count); + if buffer.count == count_limit then break; - for 0..buffer.count-1 { + + for previous_count..buffer.count-1 { for t: terminators { if buffer[it] == t then break read_loop; } } + OS_wait_for_input(); } |
