diff options
| author | dam <dam@gudinoff> | 2023-12-12 03:03:45 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2023-12-12 03:03:45 +0000 |
| commit | e3f4ad1b4db98f612f097ba76116ab5d85bed912 (patch) | |
| tree | 56923af600794d1ea8b06f8443d8e97149d987ed /TUI/module.jai | |
| parent | 58716ceff7f82ee8b01ea43734cc755cacff25a6 (diff) | |
| download | task-time-tracker-e3f4ad1b4db98f612f097ba76116ab5d85bed912.tar.zst task-time-tracker-e3f4ad1b4db98f612f097ba76116ab5d85bed912.zip | |
Improved tests and tried to implement tcsetattr by relying only on ioctl.
Diffstat (limited to 'TUI/module.jai')
| -rw-r--r-- | TUI/module.jai | 46 |
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(); |
