diff options
| author | dam <dam@gudinoff> | 2023-12-17 02:24:39 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2023-12-17 02:24:39 +0000 |
| commit | 40b9a45a41f894cd8569104155c7456d1ef6f6bc (patch) | |
| tree | 87f6a79b4ec5f8d714c5bfd5676f5709a7a2f47f | |
| parent | 8d06729eb3353705f5d35457c5f921407f8c0f4a (diff) | |
| download | task-time-tracker-40b9a45a41f894cd8569104155c7456d1ef6f6bc.tar.zst task-time-tracker-40b9a45a41f894cd8569104155c7456d1ef6f6bc.zip | |
It seems we arrived a good compromise for the Key structure.
| -rw-r--r-- | TUI/module.jai | 153 | ||||
| -rw-r--r-- | ttt.jai | 3 |
2 files changed, 120 insertions, 36 deletions
diff --git a/TUI/module.jai b/TUI/module.jai index 48fca16..0d0f468 100644 --- a/TUI/module.jai +++ b/TUI/module.jai @@ -90,38 +90,115 @@ Commands :: struct { // The UTF-8 only requires up to 4 bytes, but some keyboard keys return up to 6 bytes. // Therefore, we rounded it up to 8 bytes to support all this and more (if needed). -Key :: union { - text: [8] u8; - code: u64; -} -to_key :: inline (value: $T) -> Key #modify { return T == u8 || T == ([]u8) || T == string; } { - k: Key; - #if T == u8 { - k.text[0] = value; +/* + In this block, we're testing having the Key as a union of both [8]u8 and u64. + It kinda looks OK, but it may drive the users to extract info from the code while + it should be used only for comparison. +*/ +test_union :: () +{ + + K :: union { + // #as text: [8] u8; + text: [8] u8; + code: u64; } - #if T == ([]u8) || T == string { - size := ifx value.count > Key.text.count then Key.text.count else value.count; - // assert(size <= Key.text.count); This is now under the user responsability. - memcpy(k.text.data, value.data, size); + + to_key :: inline (value: $T) -> K #modify { return T == u8 || T == ([]u8) || T == string; } { + k: K; + #if T == u8 { + k.text[0] = value; + } + #if T == ([]u8) || T == string { + size := ifx value.count > K.text.count then K.text.count else value.count; + // assert(size <= K.text.count); This is now under the user responsability. + memcpy(k.text.data, value.data, size); + } + return k; } - return k; -} + + operator == :: inline (a: K, b: K) -> bool { + return a.code == b.code; + } + + operator == :: inline (a: K, b: $T) -> bool { + k := to_key(b); + return a.code == k.code; + } + + + // ti := type_info(K); + print("\n---\n%\n---\n", type_info(K).*); + a: K; + b: u8; + print(">%\n", a == to_key(b)); -operator == :: inline (a: Key, b: Key) -> bool { - return a.code == b.code; -} + c: string = ""; + print(">%\n", a == to_key(c)); -operator == :: inline (a: Key, b: $T) -> bool { - k := to_key(b); - return a.code == k.code; + d: []u8 = xx ""; + print(">%\n", a == to_key(d)); + + print(">%\n", a == b); + print(">%\n", a == c); + print(">%\n", a == d); + + zed := K.{ xx "Bazinga!" }; + zed = to_key("abc"); + + print("\n- - -\n%\n- - -\n", cast(string)zed.text); + + print("$ $ $\n%\n$ $ $\n", zed == "abc"); + } +#run test_union(); + +/* + In this block, we're testing having the Key as: [8] u8 + ...WIP... +*/ +/* +test_array :: () +{ + K :: #type,distinct [8] u8; + K_count :: 8;// #run type_info(K).array_count; + // #run print("###\n%\n###\n", type_info(K).*); + // #run print("###\n%\n###\n", type_info(K).array_count); + // #run print(":%", type_info(K).*); + // #run print(":%", ; + // #run print("\n###\n"); + // #run print("%", cast(*Type_Info_Array)type_info(K).array_count); + // #run print("%", type_info(K).count); + // #run print("\n###\n"); + + to_key :: inline (value: $T) -> K #modify { return T == u8 || T == ([]u8) || T == string; } { + k: K; + #if T == u8 { + k[0] = value; + } + #if T == ([]u8) || T == string { + size := ifx value.count > K_count then K_count else value.count; + // assert(size <= K.text.count); This is now under the user responsability. + memcpy(k.data, value.data, size); + } + return k; + } + + operator == :: inline (a: K, b: K) -> bool #dump { + // return memcmp(a.data, b.data, 8) == 0; + return (cast,force(*u64)*a).* == (cast,force(*u64)*b).*; + } + + operator == :: inline (a: K, b: $T) -> bool { + k := to_key(b); + return a == k; + } -#run { - print("\n:::%\n", Key.text.count); - // ti := type_info(Key); - print("\n---\n%\n---\n", type_info(Key).*); - a: Key; + print("\n:::%\n", K_count); + // ti := type_info(K); + print("\n---\n%\n---\n", type_info(K).*); + a: K; b: u8; print(">%\n", a == to_key(b)); @@ -131,20 +208,26 @@ operator == :: inline (a: Key, b: $T) -> bool { d: []u8 = xx ""; print(">%\n", a == to_key(d)); - print(">%\n", a == b); - print(">%\n", a == c); - print(">%\n", a == d); + // print(">%\n", a == b); + // print(">%\n", a == c); + // print(">%\n", a == d); } +#run test_array(); +*/ + +// Rest of the module --- + +Key :: u32; // Terminal action codes are encoded with values incompatible with UTF-8 to avoid collisions. -Keys :: struct { - None :: #run to_key("\0"); - Resize :: #run to_key(xx 1); -} -// Keys :: enum Key { - // None :: 0xFF000000; - // Resize :: 0xFF000001; +// Keys :: struct { + // None :: #run to_key("\0"); + // Resize :: #run to_key(xx 1); // } +Keys :: enum Key { + None :: 0xFF000000; + Resize :: 0xFF000001; +} initialized := false; @@ -1179,7 +1179,8 @@ read_enter_confirmation :: inline (row: int, style: int, message: string) -> boo return read_input_char(row, style, message) == #char "\n"; } -main :: () { +main :: () {} +_main :: () { // -- -- -- Testing TUI -- START |
