aboutsummaryrefslogtreecommitdiff
path: root/TUI/module.jai
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 /TUI/module.jai
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.
Diffstat (limited to 'TUI/module.jai')
-rw-r--r--TUI/module.jai29
1 files changed, 18 insertions, 11 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;
}