diff options
| author | dam <dam@gudinoff> | 2023-11-21 01:59:04 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2023-11-21 01:59:04 +0000 |
| commit | 52ae0bb03c0dec13875d05b68e0f7912e5df8f23 (patch) | |
| tree | 410172758b2a937c7c418836cafb7f456ec81b97 /TUI/unix.jai | |
| parent | 06a4894c50c56dd8236c1e401bf422d0a8f47c14 (diff) | |
| download | task-time-tracker-52ae0bb03c0dec13875d05b68e0f7912e5df8f23.tar.zst task-time-tracker-52ae0bb03c0dec13875d05b68e0f7912e5df8f23.zip | |
Cleanup get_str procedure and TUI/unix.
Diffstat (limited to 'TUI/unix.jai')
| -rw-r--r-- | TUI/unix.jai | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/TUI/unix.jai b/TUI/unix.jai index 7ff1e72..fb79f86 100644 --- a/TUI/unix.jai +++ b/TUI/unix.jai @@ -133,6 +133,39 @@ initial_tio_mode: Terminal_IO_Mode; raw_tio_mode: Terminal_IO_Mode; +//////////////////////////////////////////////////////////////////////////////// +// Resize detection +resize_mutex : Mutex; +was_resized : bool; + +resize_handler :: (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; + } +} + +prepare_resize_handler :: () { + sa : sigaction_t; + sa.sa_handler = resize_handler; + sigemptyset(*(sa.sa_mask)); + sa.sa_flags = SA_RESTART; + sigaction(SIGWINCH, *sa, null); +} + +restore_resize_handler :: () { + sa : sigaction_t; + sa.sa_handler = SIG_DFL; + sigaction(SIGWINCH, null, *sa); +} + +//////////////////////////////////////////////////////////////////////////////// #scope_export @@ -154,9 +187,8 @@ OS_prepare_terminal :: () { } OS_reset_terminal :: () { - tcsetattr(STDIN_FILENO, 0, *initial_tio_mode); // TODO Log on error. - restore_resize_handler(); + tcsetattr(STDIN_FILENO, 0, *initial_tio_mode); // TODO Log on error. } OS_read_input :: (buffer: *u8, bytes_to_read: s64) -> bytes_read: s64, error: bool = false, error_message: string = "" { @@ -176,39 +208,9 @@ OS_wait_for_input :: (timeout_milliseconds: s32) -> is_input_available: bool { 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; } - -resize_handler :: (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; - } -} - -prepare_resize_handler :: () { - sa : sigaction_t; - sa.sa_handler = resize_handler; - sigemptyset(*(sa.sa_mask)); - sa.sa_flags = SA_RESTART; - sigaction(SIGWINCH, *sa, null); -} - -restore_resize_handler :: () { - sa : sigaction_t; - sa.sa_handler = SIG_DFL; - sigaction(SIGWINCH, null, *sa); -} |
