diff options
| author | dam <dam@gudinoff> | 2023-10-16 01:23:40 +0100 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2023-10-16 01:23:40 +0100 |
| commit | bdaba41cbe7f10c750c31b66dd2696e6b6ea7436 (patch) | |
| tree | 42a7d291dfe8708c67e73d885824babf72fcd441 | |
| parent | 3b9f4f990ab0e865ec8e6277381e5aff0b178665 (diff) | |
| download | task-time-tracker-bdaba41cbe7f10c750c31b66dd2696e6b6ea7436.tar.zst task-time-tracker-bdaba41cbe7f10c750c31b66dd2696e6b6ea7436.zip | |
Improved input reading to wait for event instead of pooling.
| -rw-r--r-- | TUI/module.jai | 19 | ||||
| -rw-r--r-- | TUI/unix.jai | 4 | ||||
| -rw-r--r-- | ttt.jai | 2 |
3 files changed, 6 insertions, 19 deletions
diff --git a/TUI/module.jai b/TUI/module.jai index 7a7dc54..c1f40ce 100644 --- a/TUI/module.jai +++ b/TUI/module.jai @@ -98,19 +98,10 @@ Keys :: enum u8 { Resize :: 1; //410; // TODO Why?! } -input_semaphore: Semaphore; key_semaphore: Semaphore; key_mutex: Mutex; key_input := Keys.None; key_resize := Keys.None; -// key_queue: [2] Key; // TODO Queue with size 1!? hmmm nice! -// key_queue_idx := 0; - - - -// queue_semaphore: Semaphore; -// queue_mutex: Mutex; -// queue :: Keys; // Notes // So, the semaphore usage should indicate the items on the key_queue. @@ -126,9 +117,9 @@ process_input :: (thread: *Thread) -> s64 { defer dam(">STOP signal_input\n"); while(true) { if initialized == false return 0; - if key_input != Keys.None { // TODO Reading without mutex... + if key_input != Keys.None { dam("waiting.."); - sleep_milliseconds(100); + sleep_milliseconds(100); // We could increase this value as a push-back mechanism if we're just hitting it repeateadly. dam("!\n\r"); continue; } @@ -170,7 +161,7 @@ get_key :: (wait_milliseconds: s32) -> Key { defer key_resize = Keys.None; return xx key_resize; } - + defer key_input = Keys.None; return xx key_input; } @@ -186,7 +177,6 @@ dam("B"); init(*input_buffer_mutex, "input_buffer_mutex"); assert(thread_init(*input_process_thread, process_input), "Failed to initialize thread."); dam("C"); - // init(*input_semaphore); init(*key_semaphore); init(*key_mutex, "key_mutex"); dam("D"); @@ -199,10 +189,7 @@ stop :: () { if initialized == false return; initialized = false; - // signal(*input_semaphore); // TODO Maybe use tcflush ??? thread_deinit(*input_process_thread); - - // destroy(*input_semaphore); destroy(*key_semaphore); OS_reset_terminal(); diff --git a/TUI/unix.jai b/TUI/unix.jai index 1bfa400..523aeb5 100644 --- a/TUI/unix.jai +++ b/TUI/unix.jai @@ -135,8 +135,8 @@ OS_prepare_terminal :: () { raw_tio_mode.c_lflag &= ~(.ECHO | .ECHONL | .ICANON | .ISIG | .IEXTEN); raw_tio_mode.c_cflag &= ~(.CSIZE | .PARENB); raw_tio_mode.c_cflag |= .CS8; - raw_tio_mode.c_cc[Control_Chars.VMIN] = 0; - raw_tio_mode.c_cc[Control_Chars.VTIME] = 1; + raw_tio_mode.c_cc[Control_Chars.VMIN] = 1; + raw_tio_mode.c_cc[Control_Chars.VTIME] = 0; tcsetattr(STDIN_FILENO, 0, *raw_tio_mode); // TODO Log on error. } @@ -1227,8 +1227,8 @@ main :: () { key: TUI.Key = #char "d"; while(key != #char "q") { __mark := get_temporary_storage_mark(); + sleep_milliseconds(1000); key = TUI.get_key(3000); - // sleep_milliseconds(10); if key != xx TUI.Keys.None print_character(key); else write_string("-"); |
