diff options
| author | dam <devnull@localhost> | 2024-02-10 16:24:48 +0000 |
|---|---|---|
| committer | dam <devnull@localhost> | 2024-02-10 16:24:48 +0000 |
| commit | 206b56b08f334fc2fe743f91bebbe070cb72f4d5 (patch) | |
| tree | fd4cb04eb8b70e18cf52aeb366619cc751fc01a7 | |
| parent | 4aa3ae769bc079dd5cbd3419cc44b1d95986f837 (diff) | |
| download | task-time-tracker-206b56b08f334fc2fe743f91bebbe070cb72f4d5.tar.zst task-time-tracker-206b56b08f334fc2fe743f91bebbe070cb72f4d5.zip | |
Small improve on read_input search for terminators.
| -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(); } |
