diff options
| author | dam <dam@gudinoff> | 2023-10-24 21:27:58 +0100 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2023-10-24 21:27:58 +0100 |
| commit | 70d3b82ca7817a066120ff88deb8b56e90d454ca (patch) | |
| tree | 790bb209e207249a34ea55027f45c85076f181d8 /TUI/module.jai | |
| parent | 456be46bc0d4d7a0643616c269fbcb2b6f935197 (diff) | |
| download | task-time-tracker-70d3b82ca7817a066120ff88deb8b56e90d454ca.tar.zst task-time-tracker-70d3b82ca7817a066120ff88deb8b56e90d454ca.zip | |
Prototype of process_input that does not block reading.
Diffstat (limited to 'TUI/module.jai')
| -rw-r--r-- | TUI/module.jai | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/TUI/module.jai b/TUI/module.jai index f113c2a..6854d59 100644 --- a/TUI/module.jai +++ b/TUI/module.jai @@ -102,6 +102,7 @@ key_semaphore: Semaphore; key_mutex: Mutex; key_input := Keys.None; key_resize := Keys.None; +key_buffer: [64] Keys; // Notes // So, the semaphore usage should indicate the items on the key_queue. @@ -111,8 +112,11 @@ dam :: (msg: string) { print(msg, to_standard_error = true); } + process_input :: (thread: *Thread) -> s64 { - char: u8; + buffer: [64] u8; + input: string; + // char: u8; dam(">START signal_input\n"); defer dam(">STOP signal_input\n"); while(true) { @@ -123,17 +127,20 @@ process_input :: (thread: *Thread) -> s64 { dam("!\n\r"); continue; } - dam("reading.."); - bytes_read := OS_read_input(*char, 1); - dam("!\n\r"); - if bytes_read > 0 { + if input.count > 0 { lock(*key_mutex); - defer unlock(*key_mutex); - key_input = xx char; - dam("signaling.."); - dam("!\n\r"); + key_input = xx input[0]; + unlock(*key_mutex); signal(*key_semaphore); + + advance(*input); + continue; } + + // dam("reading.."); + bytes_read := OS_read_input(buffer.data, buffer.count); + input.data = buffer.data; + input.count = bytes_read; } return 0; } @@ -213,9 +220,12 @@ stop :: () { restore_handler(); // TODO Move to beter place. + print(">A<"); thread_deinit(*input_process_thread); + print(">B<"); destroy(*key_semaphore); - + + print(">C<"); OS_reset_terminal(); write_strings(Commands.EnterMainBuffer, Commands.RestoreCursorPosition, Commands.ShowCursor); } |
