aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordam <dam@gudinoff>2023-10-24 21:27:58 +0100
committerdam <dam@gudinoff>2023-10-24 21:27:58 +0100
commit70d3b82ca7817a066120ff88deb8b56e90d454ca (patch)
tree790bb209e207249a34ea55027f45c85076f181d8
parent456be46bc0d4d7a0643616c269fbcb2b6f935197 (diff)
downloadtask-time-tracker-70d3b82ca7817a066120ff88deb8b56e90d454ca.tar.zst
task-time-tracker-70d3b82ca7817a066120ff88deb8b56e90d454ca.zip
Prototype of process_input that does not block reading.
-rw-r--r--TUI/module.jai30
-rw-r--r--TUI/unix.jai4
-rw-r--r--ttt.jai7
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.
}
diff --git a/ttt.jai b/ttt.jai
index c834bf1..8edc8b4 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -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;
}