diff options
Diffstat (limited to 'TUI/module.jai')
| -rw-r--r-- | TUI/module.jai | 62 |
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; } |
