diff options
| author | dam <dam@gudinoff> | 2023-09-28 00:51:40 +0100 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2023-09-28 00:51:40 +0100 |
| commit | 32621b9b18a285dfd5e9e225073809bc49b14f39 (patch) | |
| tree | d033b328603df8c51bcee91cf2ce2ebd0959f4cb /TUI/windows.jai | |
| parent | aa4550e5871ca3e21942f2f612666fd41f90eadb (diff) | |
| download | task-time-tracker-32621b9b18a285dfd5e9e225073809bc49b14f39.tar.zst task-time-tracker-32621b9b18a285dfd5e9e225073809bc49b14f39.zip | |
Working read_input prototype.
Diffstat (limited to 'TUI/windows.jai')
| -rw-r--r-- | TUI/windows.jai | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/TUI/windows.jai b/TUI/windows.jai index 84dd271..85dab0b 100644 --- a/TUI/windows.jai +++ b/TUI/windows.jai @@ -1,4 +1,12 @@ +#scope_file + #import "Windows"; +#import "System"; + +// 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 +// https://github.com/MicrosoftDocs/Console-Docs/blob/main/docs/console-virtual-terminal-sequences.md + kernel32 :: #system_library "kernel32"; @@ -84,7 +92,9 @@ initial_stdout_mode: u32; default_stdout_mode: Console_Mode; - + +#scope_export + OS_prepare_terminal :: () { print("TODO TUI\n", to_standard_error = true); @@ -147,38 +157,25 @@ OS_get_terminal_size :: () -> rows: int, columns: int { return rows, columns; } -OS_read_input :: (mode: Input_Mode) -> string { - result: string = ---; - +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."); // @speed TODO Could check if was already set before applying. - + 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."); // @speed TODO Could check if was already set before applying. - if SetConsoleMode(stdin, xx unblocking_stdin_mode) == false { - print("Failed to set input mode: %.", GetLastError(), to_standard_error = true); - exit(0); - } + 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 } +} - MAX_BYTES_TO_READ :: 10; - temp : [MAX_BYTES_TO_READ] u8; - bytes_read : s32; - - if ReadConsoleA(stdin, temp.data, xx temp.count, *bytes_read) { - - // TODO If the number of bytes_read is equal to the buffer size... we may have some more data to read?! - // ---> To fix this, we should check the last read byte and see if it's a newline (at least for HUMAN mode)! - - // TODO Maybe pass the input result in the temporary memory (unless specified otherwise)?! - - result.data = alloc(bytes_read); - result.count = bytes_read; - memcpy(result.data, temp.data, bytes_read); +OS_read_input :: (buffer: *u8, bytes_to_read: s64) -> bytes_read: s64, error: bool = false, error_message: string = "" { + bytes_read: s32; + error := ReadConsoleA(stdin, buffer, bytes_to_read, *bytes_read); + if error { + _, error_message := get_error_value_and_string(); + return -1, true, error_message; } - - assert(SetConsoleMode(stdin, xx default_stdin_mode), "Failed to set default input mode."); // @speed TODO Maybe compare current mode with default one before applying?! - - return result; -}; + return bytes_read; +} |
