aboutsummaryrefslogtreecommitdiff
path: root/TUI/windows.jai
diff options
context:
space:
mode:
Diffstat (limited to 'TUI/windows.jai')
-rw-r--r--TUI/windows.jai57
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;
+}