From 3a949ea9f18d06bbefc73da8ca0c1051252ca96d Mon Sep 17 00:00:00 2001 From: dam Date: Wed, 20 Dec 2023 10:00:44 +0000 Subject: Trying to fix get_key to behave well when it's buffer is full. --- TUI/module.jai | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'TUI') 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(""); + 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(""); // 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; } -- cgit v1.2.3