aboutsummaryrefslogtreecommitdiff
path: root/TUI/module.jai
diff options
context:
space:
mode:
Diffstat (limited to 'TUI/module.jai')
-rw-r--r--TUI/module.jai42
1 files changed, 24 insertions, 18 deletions
diff --git a/TUI/module.jai b/TUI/module.jai
index 18df2c5..332f7c5 100644
--- a/TUI/module.jai
+++ b/TUI/module.jai
@@ -86,24 +86,30 @@ initialized := false;
input_buffer : [64] u8;
input_string : string;
+input_override : Key;
-Key :: u8; // TODO To be improved.
-Keys :: enum u8 {
- None :: 0;
- Resize :: 1; //410; // TODO Why?!
-}
+// TODO WIP WIP WIP
+// >>>>>>>>>>>>>>>>> Decide what we'll use as Key... and start fixing the types used on the procedures.
+;
+Key :: u32;
-dam :: (msg: string) {
- print(msg, to_standard_error = true);
+Keys :: enum Key {
+ None :: 0;
+ Resize :: 0xFF000001; // TODO Using a value incompatible with UTF-8.
}
-push_key :: (key: Key) {
- // TODO
+set_next_key :: (key: Key) {
+ input_override = key;
}
get_key :: (timeout_milliseconds: s32 = -1) -> Key {
+ if input_override != xx Keys.None {
+ defer input_override = xx Keys.None;
+ return input_override;
+ }
+
if OS_was_terminal_resized() return xx Keys.Resize;
if input_string.count > 0 {
@@ -127,10 +133,10 @@ get_key :: (timeout_milliseconds: s32 = -1) -> Key {
return xx Keys.None;
}
-get_str :: (str_limit: int = -1, allocator: Allocator = temp) -> string {
+get_str :: (count_limit: int = -1, allocator: Allocator = temp) -> string {
assert(allocator.proc != null, "Argument 'allocator.proc' has invalid null value.");
-
- if str_limit < 0 {
+
+ if count_limit < 0 {
builder: String_Builder();
builder.allocator = allocator;
init_string_builder(*builder);
@@ -145,22 +151,21 @@ get_str :: (str_limit: int = -1, allocator: Allocator = temp) -> string {
return builder_to_string(*builder, allocator);
}
else {
- buffer := alloc_string(str_limit, allocator);
- buffer.count = OS_read_input(buffer.data, str_limit);
+ buffer := alloc_string(count_limit, allocator);
+ buffer.count = OS_read_input(buffer.data, count_limit);
return buffer;
}
}
-
-
start :: () {
if initialized == true return;
write_strings(Commands.HideCursor, Commands.SaveCursorPosition, Commands.EnterAlternateBuffer, Commands.SetUTF8);
OS_prepare_terminal();
- input_string.data = input_buffer.data;
- input_string.count = 0;
+ input_string.data = input_buffer.data;
+ input_string.count = 0;
+ input_override = xx Keys.None;
initialized = true;
}
@@ -259,6 +264,7 @@ get_terminal_size :: () -> rows: int, columns: int {
}
set_cursor_position :: (row: int, column: int) {
+ assert(initialized, "TUI is not ready.");
auto_release_temp();
tmp_string := tprint(Commands.SetCursorPosition, row, column);
write_string(tmp_string);