diff options
Diffstat (limited to 'TUI/windows.jai')
| -rw-r--r-- | TUI/windows.jai | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/TUI/windows.jai b/TUI/windows.jai index 68c2a1d..ed8c996 100644 --- a/TUI/windows.jai +++ b/TUI/windows.jai @@ -1,7 +1,8 @@ #scope_file -#import "Windows"; +#import "Atomics"; #import "System"; +#import "Windows"; // https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences // https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#designate-character-set @@ -100,7 +101,7 @@ OS_prepare_terminal :: () { // stdin - stdin = GetStdHandle(STD_INPUT_HANDLE ); + stdin = GetStdHandle(STD_INPUT_HANDLE); if stdin == INVALID_HANDLE_VALUE { print("Invalid input handler.", to_standard_error = true); return; @@ -147,6 +148,15 @@ OS_reset_terminal :: () { } } +OS_flush_input :: inline () { + // TODO - https://learn.microsoft.com/en-us/windows/console/flushconsoleinputbuffer + // BOOL WINAPI FlushConsoleInputBuffer(_In_ HANDLE hConsoleInput); + /* NOTE + This API is not recommended and does not have a virtual terminal equivalent. + Attempting to empty the input queue all at once can destroy state in the queue in an unexpected manner. + */ +} + OS_get_terminal_size :: () -> rows: int, columns: int { ScreenBufferInfo: CONSOLE_SCREEN_BUFFER_INFO; @@ -157,21 +167,6 @@ OS_get_terminal_size :: () -> rows: int, columns: int { return rows, columns; } -// TODO Maybe we should use a NON-BLOCKING state by default... and only change to blocking when performing a HUMAN read...? - -OS_set_input_mode :: (mode: Input_Mode) { - if mode == { - case .HUMAN; - assert(SetConsoleMode(stdin, xx blocking_stdin_mode), "Failed to set input mode to blocking mode."); - // TODO get_error_value_and_string :: () -> (error_code: OS_Error_Code, description: string) - case .MACHINE; - assert(SetConsoleMode(stdin, xx unblocking_stdin_mode), "Failed to set input mode to unblocking mode."); - // TODO get_error_value_and_string :: () -> (error_code: OS_Error_Code, description: string) - case; - // TODO ERROR - } -} - OS_read_input :: (buffer: *u8, bytes_to_read: s64) -> bytes_read: s64, error: bool = false, error_message: string = "" { assert(bytes_to_read <= 0x7fff_ffff, "The Windows API only allows to read up to s32 bytes from the standard input."); bytes_read: s32; @@ -182,3 +177,20 @@ OS_read_input :: (buffer: *u8, bytes_to_read: s64) -> bytes_read: s64, error: bo } return bytes_read; } + +OS_wait_for_input :: (timeout_milliseconds: s32) -> is_input_available: bool { + /* TODO + Try to implement using: + https://learn.microsoft.com/en-us/windows/console/reading-input-buffer-events + https://learn.microsoft.com/en-us/windows/console/readconsoleinput + */ + 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(); // FIXME Not used. + return ifx poll_return > 0 then true else false; +} + +OS_was_terminal_resized :: () -> bool { + return atomic_swap(*was_resized, false); // TODO If the windows implementation is similar, we may push this into the main module file. +} |
