aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordam <dam@gudinoff>2023-12-20 10:00:44 +0000
committerdam <dam@gudinoff>2023-12-20 10:00:44 +0000
commit3a949ea9f18d06bbefc73da8ca0c1051252ca96d (patch)
tree84df14797d7e608f7dc8e32d8a47cdc61c9eeba9
parent6dcfeb56e6c65724a76afc8beedc277c8f4f7171 (diff)
downloadtask-time-tracker-3a949ea9f18d06bbefc73da8ca0c1051252ca96d.tar.zst
task-time-tracker-3a949ea9f18d06bbefc73da8ca0c1051252ca96d.zip
Trying to fix get_key to behave well when it's buffer is full.
-rw-r--r--TUI/module.jai29
-rw-r--r--ttt.jai16
2 files changed, 30 insertions, 15 deletions
diff --git a/TUI/module.jai b/TUI/module.jai
index 78b7605..0e2ff22 100644
--- a/TUI/module.jai
+++ b/TUI/module.jai
@@ -111,10 +111,10 @@ Key :: u64;
KEY_SIZE :: #run type_info(Key).runtime_size;
-Keys :: enum Key {
+Keys :: struct {
// Terminal key-codes have 1 to 6 bytes, so we can signal special cases setting the edge-bytes.
- None :: 0xF0000000_0000000F;
- Resize :: 0xF0000000_0000001F;
+ None : Key : 0xF0000000_0000000F;
+ Resize : Key : 0xF0000000_0000001F;
}
/* TODO
@@ -135,7 +135,7 @@ to_key :: inline (str: $T) -> Key #modify { return T == ([]u8) || T == string; }
return k;
}
-to_string :: inline (key: Key) -> string #dump {
+to_string :: inline (key: Key) -> string {
str := talloc_string(KEY_SIZE);
str.count = 0;
while key != 0 #no_abc {
@@ -154,6 +154,7 @@ test_union :: ()
a: Key;
b: u8;
print(">%\n", a == b);
+ print(">%\n", a != Keys.None);
c: string = "";
print(">%\n", a == to_key(c));
@@ -188,7 +189,8 @@ test_union :: ()
initialized := false;
-input_buffer : [64] u8;
+// input_buffer : [64] u8; // TODO FIXME Input buffer is too small!!!
+input_buffer : [8] u8; // TODO FIXME Input buffer is too small!!!
input_string : string;
input_override : Key;
@@ -237,20 +239,25 @@ get_key :: (timeout_milliseconds: s32 = -1) -> Key {
// return input_string[0];
// }
// FIXME New version...
- if input_string.count > 0 {
+ if input_string.count > 0 #no_abc { // TODO Some trickery requires no_abc... which is not that nice in this case...
utf8_bytes := count_utf8_bytes(input_string[0]);
- // TODO We're assuming the input_buffer contains the entirety of what we need to read for the UTF8 symbols...
+ // TODO We're assuming the terminal buffer contains the entirety of what we need to read for the UTF8 symbols.
if utf8_bytes > input_string.count {
- // TODO Test this and make sure it's working...
- print("<WOW>");
+ diff := utf8_bytes - input_string.count;
+
+ // TODO Test this and make sure it's working...drop the following lines using Ctrl+V to fill the terminal buffer at once:
+ // d€€€a
+ // 1234567890123456789012345678901234567890
+ print("<WoW>");
// Copy buffered bytes to the start, and read the remaining ones from input.
- for 0..utf8_bytes-1 {
+ for 0..input_string.count-1 {
input_buffer[it] = input_string[it];
}
- OS_read_input(input_buffer.data + utf8_bytes, utf8_bytes-input_string.count); // TODO Does not check for read errors.
+ aaa := OS_read_input(input_buffer.data + input_string.count, utf8_bytes-input_string.count); // TODO Does not check for read errors.
+ assert(aaa == diff, "READ MORE THAN EXPECTED");
input_string.data = input_buffer.data;
input_string.count = utf8_bytes;
}
diff --git a/ttt.jai b/ttt.jai
index aeb5b37..80d89bf 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -1179,7 +1179,6 @@ read_enter_confirmation :: inline (row: int, style: int, message: string) -> boo
return read_input_char(row, style, message) == #char "\n";
}
-// main :: () {}
main :: () {
// -- -- -- Testing TUI -- START
@@ -1249,25 +1248,34 @@ main :: () {
print("> success\n", to_standard_error = true);
}
- #if 0 {
+ #if 1 {
print("test 5\n", to_standard_error = true);
TUI.start();
TUI.set_terminal_title("bazinga");
xcolumns, xrows: int;
key: TUI.Key = #char "d";
last_none_char := "X";
+ drop_down := 0;
while(key != #char "q") {
// __mark := get_temporary_storage_mark();
if key == {
- case xx TUI.Keys.None; {
+ case TUI.Keys.None; {
TUI.set_cursor_position(2, 2);
last_none_char = ifx last_none_char == "X" then "+" else "X";
write_string(last_none_char);
}
- case xx TUI.Keys.Resize; {
+ case TUI.Keys.Resize; #through;
+ case #char "c"; {
TUI.clear_terminal();
+ drop_down = 0;
+ }
+
+ case; {
+ TUI.set_cursor_position(3+drop_down, 2);
+ write_string(TUI.to_string(key));
+ drop_down += 1;
}
}
size_r, size_c := TUI.get_terminal_size();