diff options
| -rw-r--r-- | TUI/module.jai | 8 | ||||
| -rw-r--r-- | TUI/unix.jai | 29 |
2 files changed, 22 insertions, 15 deletions
diff --git a/TUI/module.jai b/TUI/module.jai index a12b762..2774240 100644 --- a/TUI/module.jai +++ b/TUI/module.jai @@ -172,13 +172,13 @@ get_str :: (count_limit: int = -1, allocator: Allocator = temp) -> string { start :: () { if initialized == true return; - write_strings(Commands.HideCursor, Commands.SaveCursorPosition, Commands.EnterAlternateBuffer, Commands.SetUTF8); - OS_prepare_terminal(); - input_string.data = input_buffer.data; input_string.count = 0; input_override = xx Keys.None; + OS_prepare_terminal(); + write_strings(Commands.HideCursor, Commands.SaveCursorPosition, Commands.EnterAlternateBuffer, Commands.SetUTF8); + initialized = true; } @@ -186,8 +186,8 @@ stop :: () { if initialized == false return; initialized = false; - OS_reset_terminal(); write_strings(Commands.EnterMainBuffer, Commands.RestoreCursorPosition, Commands.ShowCursor); + OS_reset_terminal(); } flush_input :: () { diff --git a/TUI/unix.jai b/TUI/unix.jai index fb79f86..4aa0508 100644 --- a/TUI/unix.jai +++ b/TUI/unix.jai @@ -1,5 +1,6 @@ #scope_file +#import "Atomics"; #import "POSIX"; #import "System"; @@ -18,6 +19,19 @@ // TODO Remote this. cfmakeraw :: (termios: *Terminal_IO_Mode) -> void #foreign libc; + /* https://elixir.bootlin.com/glibc/glibc-2.28/source/termios/cfmakeraw.c#L22 + void + cfmakeraw (struct termios *t) + { + t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); + t->c_oflag &= ~OPOST; + t->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); + t->c_cflag &= ~(CSIZE|PARENB); + t->c_cflag |= CS8; + t->c_cc[VMIN] = 1; // read returns when one char is available. + t->c_cc[VTIME] = 0; + } + */ // https://codebrowser.dev/glibc/glibc/sysdeps/unix/sysv/linux/tcsetattr.c.html tcsetattr :: (fd: s32, optional_actions: s32, termios_p : *Terminal_IO_Mode) -> s32 #foreign libc; @@ -135,7 +149,6 @@ //////////////////////////////////////////////////////////////////////////////// // Resize detection -resize_mutex : Mutex; was_resized : bool; resize_handler :: (signal_code : s32) #c_call { @@ -143,11 +156,7 @@ resize_handler :: (signal_code : s32) #c_call { 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; + atomic_swap(*was_resized, true); } } @@ -182,7 +191,6 @@ OS_prepare_terminal :: () { tcsetattr(STDIN_FILENO, 0, *raw_tio_mode); // TODO Log on error. was_resized = false; - init(*resize_mutex, "resize_mutex"); prepare_resize_handler(); } @@ -208,9 +216,8 @@ OS_wait_for_input :: (timeout_milliseconds: s32) -> is_input_available: bool { return ifx poll_return > 0 then true else false; } +// TODO This procedure hides the behaviour of reseting on read. +// We should have the `was_resized` on module.jai so that we know it may be used in another thread. OS_was_terminal_resized :: () -> bool { - lock(*resize_mutex); - defer unlock(*resize_mutex); - defer was_resized = false; - return was_resized; + return atomic_swap(*was_resized, false); // TODO If the windows implementation is similar, we may push this into the main module file. } |
