aboutsummaryrefslogtreecommitdiff
path: root/TUI/module.jai
diff options
context:
space:
mode:
Diffstat (limited to 'TUI/module.jai')
-rw-r--r--TUI/module.jai46
1 files changed, 25 insertions, 21 deletions
diff --git a/TUI/module.jai b/TUI/module.jai
index 044fd65..bfed510 100644
--- a/TUI/module.jai
+++ b/TUI/module.jai
@@ -108,11 +108,13 @@ assert_is_initialized :: inline () {
}
set_next_key :: (key: Key) {
+ assert_is_initialized();
input_override = key;
}
get_key :: (timeout_milliseconds: s32 = -1) -> Key {
-
+ assert_is_initialized();
+
// BBBB BBBB & 1100 0000 == 10XX XXXX -> is continuation byte
is_utf8_continuation_byte :: inline (byte: u8) -> bool {
return (byte & 0xC0) == 0x80;
@@ -196,21 +198,21 @@ get_key :: (timeout_milliseconds: s32 = -1) -> Key {
/// /// /// /// /// /// /// /// ///
// DEBUG
- br, bc := get_cursor_position();
- column := 3;
- row += 1;
- nr, rc := get_terminal_size();
-
- if row >= (rc - 5) then row = 5;
-
- set_cursor_position(row, column);
- for 0..input_string.count-1 {
- print("%:% | ",
- FormatInt.{base= 2, minimum_digits = 8, value = input_string[it]},
- FormatInt.{base= 16, minimum_digits = 2, value = input_string[it]},
- ); // TODO DEBUG
- }
- set_cursor_position(br, bc);
+ // br, bc := get_cursor_position();
+ // column := 3;
+ // row += 1;
+ // nr, rc := get_terminal_size();
+ //
+ // if row >= (rc - 5) then row = 5;
+//
+ // set_cursor_position(row, column);
+ // for 0..input_string.count-1 {
+ // print("%:% | ",
+ // FormatInt.{base= 2, minimum_digits = 8, value = input_string[it]},
+ // FormatInt.{base= 16, minimum_digits = 2, value = input_string[it]},
+ // ); // TODO DEBUG
+ // }
+ // set_cursor_position(br, bc);
/// /// /// /// /// /// /// /// ///
advance(*input_string, utf8_bytes);
@@ -221,6 +223,7 @@ get_key :: (timeout_milliseconds: s32 = -1) -> Key {
}
get_str :: (count_limit: int = -1, allocator: Allocator = temp) -> string {
+ assert_is_initialized();
assert(allocator.proc != null, "Argument 'allocator.proc' has invalid null value.");
if count_limit < 0 {
@@ -270,6 +273,7 @@ flush_input :: () {
}
draw_box :: (x: int, y: int, width: int, height: int) {
+ assert_is_initialized();
// TODO Check if using a String_Builder improves performance (measure it)!
// TODO Validate input parameters against the terminal size.
@@ -315,13 +319,13 @@ draw_box :: (x: int, y: int, width: int, height: int) {
// TODO Maybe rename to "clear()"
clear_terminal :: inline () {
- assert(initialized, "TUI is not ready.");
+ assert_is_initialized();
write_string(Commands.ClearScreen);
}
// TODO Maybe rename to "get_size()"
get_terminal_size :: () -> rows: int, columns: int {
- assert(initialized, "TUI is not ready.");
+ assert_is_initialized();
rows, columns: int = ---;
#if OS == .WINDOWS {
rows, columns = OS_get_terminal_size();
@@ -359,15 +363,15 @@ get_terminal_size :: () -> rows: int, columns: int {
}
set_cursor_position :: (row: int, column: int) {
- assert(initialized, "TUI is not ready.");
+ assert_is_initialized();
auto_release_temp();
tmp_string := tprint(Commands.SetCursorPosition, row, column);
write_string(tmp_string);
}
get_cursor_position :: () -> row: int, column: int {
- assert(initialized, "TUI is not ready."); // TODO Should I use this inside each and every procedure?
-
+ assert_is_initialized();
+
auto_release_temp();
flush_input();