diff options
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/TUI/module.jai | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/modules/TUI/module.jai b/modules/TUI/module.jai index 2fb1233..3c40ee1 100644 --- a/modules/TUI/module.jai +++ b/modules/TUI/module.jai @@ -342,6 +342,7 @@ is_active :: inline () -> bool { return active; } +// Prepares the terminal to be used by the module. setup_terminal :: () -> success := true #must { if active == true return; @@ -367,6 +368,7 @@ setup_terminal :: () -> success := true #must { return; } +// Restores the initial terminal settings. reset_terminal :: () -> success := true #must { if active == false return; @@ -390,6 +392,12 @@ set_next_key :: inline (key: Key) { input_override = key; } +// Returns, with the following priority: +// - last key passed to set_next_key; +// - Keys.Resize if terminal was resized; +// - key pressed by user; +// - Keys.None if everything else fails after the given timeout. +// If timeout is set to -1, it will wait indefinitely by the user input. get_key :: (timeout_milliseconds: s32 = -1) -> Key { assert_is_active(); @@ -689,7 +697,7 @@ get_terminal_size :: () -> width: int, height: int { write_string(Commands.QueryWindowSizeInChars); rows, columns: int = ---; - if OS_wait_for_input(0) { + if OS_wait_for_input(1) { // Expected response format: \e[8;<r>;<c>t // where <r> is the number of rows and <c> of columns. @@ -718,16 +726,17 @@ get_terminal_size :: () -> width: int, height: int { // In such cases, measure it indirectly by the maximum possible cursor position. // (e.g.: allowWindowOps/disallowedWindowOps properties in xterm) else { - x, y := get_cursor_position(); - defer set_cursor_position(x, y); - - set_cursor_position(0xFFFF, 0xFFFF); - columns, rows = get_cursor_position(); + write_string(Commands.SaveCursorPosition); + defer write_string(Commands.RestoreCursorPosition); + + set_cursor_position(0xFFFF, 0xFFFF,, tui_output_builder = null); + columns, rows = get_cursor_position(); } return columns, rows; } +// Range between 1 and terminal size. set_cursor_position :: inline (x: int, y: int) { assert_is_active(); if context.tui_output_builder == null { @@ -738,6 +747,7 @@ set_cursor_position :: inline (x: int, y: int) { } } +// Range between 1 and terminal size. get_cursor_position :: () -> x: int, y: int { assert_is_active(); @@ -777,12 +787,14 @@ set_terminal_title :: inline (title: string) { print(Commands.SetWindowTitle, title); } +// Set the module's context string builder in the current scope context. using_builder_as_output :: (builder: *String_Builder) #expand { __builder := context.tui_output_builder; context.tui_output_builder = builder; `defer context.tui_output_builder = __builder; } +// Helper to use the module's context string builder. tui_print :: inline (format_string: string, args: .. Any) { if context.tui_output_builder == null { print(format_string, ..args, to_standard_error = false); @@ -792,6 +804,7 @@ tui_print :: inline (format_string: string, args: .. Any) { } } +// Helper to use the module's context string builder. tui_write_string :: inline (s: string) { if context.tui_output_builder == null { write_string(s, to_standard_error = false); |
