aboutsummaryrefslogtreecommitdiff
path: root/TUI/module.jai
diff options
context:
space:
mode:
authordam <dam@gudinoff>2023-11-12 00:31:44 +0000
committerdam <dam@gudinoff>2023-11-12 00:31:44 +0000
commit06a4894c50c56dd8236c1e401bf422d0a8f47c14 (patch)
treef7e3f9d7deb6e003bb3621df7ceeb4e4ed22002d /TUI/module.jai
parent90beac697609d7d4926e18a0eb0c576b9a22058b (diff)
downloadtask-time-tracker-06a4894c50c56dd8236c1e401bf422d0a8f47c14.tar.zst
task-time-tracker-06a4894c50c56dd8236c1e401bf422d0a8f47c14.zip
Moved OS dependent code.
Diffstat (limited to 'TUI/module.jai')
-rw-r--r--TUI/module.jai58
1 files changed, 2 insertions, 56 deletions
diff --git a/TUI/module.jai b/TUI/module.jai
index 6ca6f59..18df2c5 100644
--- a/TUI/module.jai
+++ b/TUI/module.jai
@@ -158,23 +158,17 @@ start :: () {
write_strings(Commands.HideCursor, Commands.SaveCursorPosition, Commands.EnterAlternateBuffer, Commands.SetUTF8);
OS_prepare_terminal();
-
- was_resized = false;
- init(*resize_mutex, "resize_mutex");
+
input_string.data = input_buffer.data;
input_string.count = 0;
initialized = true;
-
- set_handler(); // TODO Move to beter place.
}
stop :: () {
if initialized == false return;
initialized = false;
-
- restore_handler(); // TODO Move to beter place.
-
+
OS_reset_terminal();
write_strings(Commands.EnterMainBuffer, Commands.RestoreCursorPosition, Commands.ShowCursor);
}
@@ -301,52 +295,4 @@ get_cursor_position :: () -> row: int, column: int {
}
else #if OS == .LINUX || OS == .MACOS {
// Prototyping zone... keep clear!
-
- OS_wait_for_input :: (timeout_milliseconds: s32) -> is_input_available: bool {
- fds := pollfd.[ .{ fd = STDIN_FILENO, events = POLLIN, revents = 0 } ];
- nfds := fds.count;
- poll_return := poll(fds.data, xx nfds, xx timeout_milliseconds); // TODO Wait for input using poll syscall. This breaks and throws '-1 | 4 | Interrupted system call' when we resize the window while polling.
- error_code, error_message := get_error_value_and_string();
- return ifx poll_return > 0 then true else false;
- }
-
- resize_mutex : Mutex;
- was_resized : bool;
-
- OS_was_terminal_resized :: () -> bool {
- lock(*resize_mutex);
- defer unlock(*resize_mutex);
- defer was_resized = false;
- return was_resized;
- }
-
- process_resize :: (signal_code : s32) #c_call {
- new_context : Context;
- push_context new_context {
- print("SIGNAL:%", signal_code);
- if signal_code != SIGWINCH then return;
- if was_resized == true then return;
- print("RESIZE\n");
- lock(*resize_mutex);
- defer unlock(*resize_mutex);
- was_resized = true;
- }
- }
-
- // TODO Rename this procedure.
- set_handler :: () {
- sa : sigaction_t;
- sa.sa_handler = process_resize;
- sigemptyset(*(sa.sa_mask));
- sa.sa_flags = SA_RESTART;
- sigaction(SIGWINCH, *sa, null);
- }
-
- // TODO Rename this procedure.
- restore_handler :: () {
- sa : sigaction_t;
- sa.sa_handler = SIG_DFL;
- sigaction(SIGWINCH, null, *sa);
- }
-
}