diff options
Diffstat (limited to 'TUI/windows.jai')
| -rw-r--r-- | TUI/windows.jai | 64 |
1 files changed, 33 insertions, 31 deletions
diff --git a/TUI/windows.jai b/TUI/windows.jai index 036b33b..68c2a1d 100644 --- a/TUI/windows.jai +++ b/TUI/windows.jai @@ -26,35 +26,36 @@ // https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror GetLastError :: () -> s32 #foreign kernel32; - ENABLE_VIRTUAL_TERMINAL_INPUT :: 0x0200; - - ENABLE_PROCESSED_OUTPUT :: 0x0001; - ENABLE_WRAP_AT_EOL_OUTPUT :: 0x0002; - ENABLE_VIRTUAL_TERMINAL_PROCESSING :: 0x0004; - DISABLE_NEWLINE_AUTO_RETURN :: 0x0008; - ENABLE_LVB_GRID_WORLDWIDE :: 0x0010; - - + // https://learn.microsoft.com/en-us/windows/console/setconsolemode - Console_Mode :: enum_flags u32 { + Console_Input_Mode :: enum_flags u32 { _UNUSED_0001_; - ENABLE_LINE_INPUT; // If enable, ReadFile or ReadConsole function return on CR; otherwise they return when one or more characters are available. - ENABLE_ECHO_INPUT; // Echoes input on screen. Only available if ENABLE_LINE_INPUT is set. + ENABLE_LINE_INPUT; // If enable, ReadFile or ReadConsole function return on CR; otherwise they return when one or more characters are available. + ENABLE_ECHO_INPUT; // Echoes input on screen. Only available if ENABLE_LINE_INPUT is set. _UNUSED_0008_; - ENABLE_MOUSE_INPUT; // - ENABLE_INSERT_MODE; // If enabled, text entered will be inserted at the current cursor location and all text following that location will not be overwritten. When disabled, all following text will be overwritten. - _UNSED_0040_; - _UNSED_0080_; - _UNSED_0100_; - ENABLE_VIRTUAL_TERMINAL_INPUT; // - _UNSED_0400_; - _UNSED_0800_; - _UNSED_1000_; - _UNSED_2000_; - _UNSED_4000_; - _UNSED_8000_; + ENABLE_MOUSE_INPUT; // + ENABLE_INSERT_MODE; // If enabled, text entered will be inserted at the current cursor location and all text following that location will not be overwritten. When disabled, all following text will be overwritten. + _UNUSED_0040_; + _UNUSED_0080_; + _UNUSED_0100_; + ENABLE_VIRTUAL_TERMINAL_INPUT; // + _UNUSED_0400_; + _UNUSED_0800_; + } + + // https://learn.microsoft.com/en-us/windows/console/setconsolemode + Console_Output_Mode :: enum_flags u32 { + ENABLE_PROCESSED_OUTPUT; // + ENABLE_WRAP_AT_EOL_OUTPUT; // + ENABLE_VIRTUAL_TERMINAL_PROCESSING; // + DISABLE_NEWLINE_AUTO_RETURN; // + ENABLE_LVB_GRID_WORLDWIDE; // + _UNUSED_0020_; + _UNUSED_0040_; + _UNUSED_0080_; } + // https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types SHORT :: s16; WORD :: u16; @@ -75,7 +76,6 @@ CONSOLE_SCREEN_BUFFER_INFO :: struct { dwSize : COORD; dwCursorPosition : COORD; - wAttributes : WORD; srWindow : SMALL_RECT; dwMaximumWindowSize : COORD; @@ -84,13 +84,13 @@ stdin: HANDLE; initial_stdin_mode: u32; - default_stdin_mode: Console_Mode; - blocking_stdin_mode: Console_Mode; - unblocking_stdin_mode: Console_Mode; + default_stdin_mode: Console_Input_Mode; + blocking_stdin_mode: Console_Input_Mode; + unblocking_stdin_mode: Console_Input_Mode; stdout: HANDLE; initial_stdout_mode: u32; - default_stdout_mode: Console_Mode; + default_stdout_mode: Console_Output_Mode; #scope_export @@ -109,7 +109,7 @@ OS_prepare_terminal :: () { print("Failed to get input mode.", to_standard_error = true); return; } - default_stdin_mode = (cast(Console_Mode) initial_stdin_mode) | .ENABLE_VIRTUAL_TERMINAL_INPUT; + default_stdin_mode = (cast(Console_Input_Mode) initial_stdin_mode) | .ENABLE_VIRTUAL_TERMINAL_INPUT; blocking_stdin_mode = default_stdin_mode | .ENABLE_LINE_INPUT | .ENABLE_ECHO_INPUT; unblocking_stdin_mode = default_stdin_mode & ~.ENABLE_LINE_INPUT & ~.ENABLE_ECHO_INPUT; @@ -128,7 +128,7 @@ OS_prepare_terminal :: () { print("Failed to get output mode.", to_standard_error = true); return; } - default_stdout_mode = (cast(Console_Mode) initial_stdout_mode) | ENABLE_PROCESSED_OUTPUT| ENABLE_VIRTUAL_TERMINAL_PROCESSING; + default_stdout_mode = (cast(Console_Output_Mode) initial_stdout_mode) | .ENABLE_PROCESSED_OUTPUT| .ENABLE_VIRTUAL_TERMINAL_PROCESSING; if SetConsoleMode(stdout, xx default_stdout_mode) == false { print("Failed to set output mode: %.", GetLastError(), to_standard_error = true); @@ -157,6 +157,8 @@ 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; |
