aboutsummaryrefslogtreecommitdiff
path: root/TUI/module.jai
diff options
context:
space:
mode:
authordam <devnull@localhost>2024-01-07 01:28:21 +0000
committerdam <devnull@localhost>2024-01-07 01:28:21 +0000
commite5d8eaa14407608a15a639da14bbea99dd8ef61a (patch)
treedc41da8f228531130a00e0c62e46fb4c0660a235 /TUI/module.jai
parent381e62b9128123d12294df4aeae5430cd62349e9 (diff)
downloadtask-time-tracker-e5d8eaa14407608a15a639da14bbea99dd8ef61a.tar.zst
task-time-tracker-e5d8eaa14407608a15a639da14bbea99dd8ef61a.zip
Fixed Windows raw IO modes.
Diffstat (limited to 'TUI/module.jai')
-rw-r--r--TUI/module.jai62
1 files changed, 33 insertions, 29 deletions
diff --git a/TUI/module.jai b/TUI/module.jai
index df88f0c..21f1dd7 100644
--- a/TUI/module.jai
+++ b/TUI/module.jai
@@ -667,7 +667,13 @@ start :: () {
input_string.count = 0;
input_override = xx Keys.None;
- write_strings(Commands.HideCursor, Commands.SaveCursorPosition, Commands.AlternateScreenBuffer, Commands.SetUTF8);
+ write_strings(
+ Commands.HideCursor,
+ Commands.SaveCursorPosition,
+ Commands.AlternateScreenBuffer,
+ Commands.SetUTF8,
+ Commands.CursorNormalMode,
+ Commands.KeypadNumMode);
OS_prepare_terminal();
initialized = true;
@@ -744,39 +750,37 @@ clear_terminal :: inline () {
// TODO Maybe rename to "get_size()"
get_terminal_size :: () -> rows: int, columns: int {
assert_is_initialized();
+
+ auto_release_temp();
+
rows, columns: int = ---;
- #if OS == .WINDOWS {
- rows, columns = OS_get_terminal_size();
- }
- else {
- auto_release_temp();
- flush_input();
- write_string(Commands.QueryWindowSizeInChars);
- input := get_string(64,, temporary_allocator);
-
- // Expected response format: \e[8;<r>;<c>t
- // where <r> is the number of rows and <c> of columns.
- FORMAT :: "\e[8;<r>;<c>t";
-
- // Discard head noise.
- while input.count >= 3 && (input[0] != FORMAT[0] || input[1] != FORMAT[1] || input[2] != FORMAT[2]) {
- advance(*input);
- }
+ flush_input();
+ write_string(Commands.QueryWindowSizeInChars);
+ input := get_string(64,, temporary_allocator);
- // Discard tail noise.
- while input.count >= 3 && input[input.count-1] != FORMAT[FORMAT.count-1] {
- input.count -= 1;
- }
-
- assert(input.count >= 3 &&
- input[0] == FORMAT[0] && input[1] == FORMAT[1] && input[2] == FORMAT[2] && input[input.count-1] == FORMAT[FORMAT.count-1],
- "Query window size in chars returned invalid response.");
+ // Expected response format: \e[8;<r>;<c>t
+ // where <r> is the number of rows and <c> of columns.
+ FORMAT :: "\e[8;<r>;<c>t";
+
+ // Discard head noise.
+ while input.count >= 3 && (input[0] != FORMAT[0] || input[1] != FORMAT[1] || input[2] != FORMAT[2]) {
+ advance(*input);
+ }
- parts := split(input, ";",, temporary_allocator);
- rows = parse_int(*parts[1]);
- columns = parse_int(*parts[2]);
+ // Discard tail noise.
+ while input.count >= 3 && input[input.count-1] != FORMAT[FORMAT.count-1] {
+ input.count -= 1;
}
+
+ assert(input.count >= 3 &&
+ input[0] == FORMAT[0] && input[1] == FORMAT[1] && input[2] == FORMAT[2] && input[input.count-1] == FORMAT[FORMAT.count-1],
+ "Query window size in chars returned invalid response.");
+
+ parts := split(input, ";",, temporary_allocator);
+ rows = parse_int(*parts[1]);
+ columns = parse_int(*parts[2]);
+
return rows, columns;
}