aboutsummaryrefslogtreecommitdiff
path: root/modules/TUI/module.jai
diff options
context:
space:
mode:
authordam <dam@gudinoff>2024-05-26 11:54:44 +0100
committerdam <dam@gudinoff>2024-05-26 11:54:44 +0100
commit7f8a90efed56db9f49e9d7e5167372ddd7aa1df2 (patch)
treefb41882b096d48b1c6f5f21c2e53558fbc131a12 /modules/TUI/module.jai
parent4468717c64d0fcac52f00326cff9e6b0b15917fc (diff)
downloadtask-time-tracker-7f8a90efed56db9f49e9d7e5167372ddd7aa1df2.tar.zst
task-time-tracker-7f8a90efed56db9f49e9d7e5167372ddd7aa1df2.zip
Patched TUI module.
Diffstat (limited to 'modules/TUI/module.jai')
-rw-r--r--modules/TUI/module.jai32
1 files changed, 11 insertions, 21 deletions
diff --git a/modules/TUI/module.jai b/modules/TUI/module.jai
index 3c40ee1..124b906 100644
--- a/modules/TUI/module.jai
+++ b/modules/TUI/module.jai
@@ -693,10 +693,12 @@ get_terminal_size :: () -> width: int, height: int {
auto_release_temp();
+ rows, columns: int = ---;
+
flush_input();
write_string(Commands.QueryWindowSizeInChars);
-
- rows, columns: int = ---;
+
+ // Wait a bit for a response to QueryWindowSizeInChars...
if OS_wait_for_input(1) {
// Expected response format: \e[8;<r>;<c>t
@@ -704,15 +706,9 @@ get_terminal_size :: () -> width: int, height: int {
FORMAT :: "\e[8;<r>;<c>t";
input := read_input(64, #char "t",, allocator = temporary_allocator);
- // Discard head noise.
- while input.count >= 3 && (input[0] != FORMAT[0] || input[1] != FORMAT[1] || input[2] != FORMAT[2]) {
- advance(*input);
- }
-
- // Discard tail noise.
- while input.count >= 3 && input[input.count-1] != FORMAT[FORMAT.count-1] {
- input.count -= 1;
- }
+ // Discard head noise, assuming that the response is at the end of the input (because we used a terminator character during read).
+ start_idx := find_index_from_right(input, #char "\e");
+ if start_idx > 0 then advance(*input, start_idx);
assert(input.count >= 3 &&
input[0] == FORMAT[0] && input[1] == FORMAT[1] && input[2] == FORMAT[2] && input[input.count-1] == FORMAT[FORMAT.count-1],
@@ -761,20 +757,14 @@ get_cursor_position :: () -> x: int, y: int {
FORMAT :: "\e[<r>;<c>R";
input := read_input(64, #char "R",, allocator = temporary_allocator);
- // Discard head noise.
- while input.count >= 2 && (input[0] != FORMAT[0] || input[1] != FORMAT[1]) {
- advance(*input);
- }
-
- // Discard tail noise.
- while input.count >= 2 && input[input.count-1] != FORMAT[FORMAT.count-1] {
- input.count -= 1;
- }
+ // Discard head noise, assuming that the response is at the end of the input (because we used a terminator character during read).
+ start_idx := find_index_from_right(input, #char "\e");
+ if start_idx > 0 then advance(*input, start_idx);
assert(input.count >= 2 &&
input[0] == FORMAT[0] && input[1] == FORMAT[1] && input[input.count-1] == FORMAT[FORMAT.count-1],
"Failed to query cursor position: invalid response.");
-
+
advance(*input, 2);
parts := split(input, ";",, allocator = temporary_allocator);
row := parse_int(*parts[0]);