diff options
| -rw-r--r-- | TUI/module.jai | 30 | ||||
| -rw-r--r-- | TUI/unix.jai | 4 | ||||
| -rw-r--r-- | ttt.jai | 7 |
3 files changed, 28 insertions, 13 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); } diff --git a/TUI/unix.jai b/TUI/unix.jai index 523aeb5..1bfa400 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] = 1; - raw_tio_mode.c_cc[Control_Chars.VTIME] = 0; + raw_tio_mode.c_cc[Control_Chars.VMIN] = 0; + raw_tio_mode.c_cc[Control_Chars.VTIME] = 1; tcsetattr(STDIN_FILENO, 0, *raw_tio_mode); // TODO Log on error. } @@ -1227,14 +1227,19 @@ main :: () { key: TUI.Key = #char "d"; while(key != #char "q") { __mark := get_temporary_storage_mark(); - sleep_milliseconds(1000); + // sleep_milliseconds(1000); key = TUI.get_key(3000); if key != xx TUI.Keys.None print_character(key); else write_string("-"); set_temporary_storage_mark(__mark); } + print("Waiting 1s.."); + sleep_milliseconds(1000); + print("!\n\r"); + print("Stoping.."); TUI.stop(); + print("!\n\r"); return; } |
