diff options
Diffstat (limited to 'TUI/unix.jai')
| -rw-r--r-- | TUI/unix.jai | 56 |
1 files changed, 12 insertions, 44 deletions
diff --git a/TUI/unix.jai b/TUI/unix.jai index 1bfa400..a35a60a 100644 --- a/TUI/unix.jai +++ b/TUI/unix.jai @@ -6,6 +6,16 @@ // Required to do unlocking input. libc :: #system_library "libc"; + + // int poll(struct pollfd *fds, nfds_t nfds, int timeout); + pollfd :: struct { + fd : s32; // File descriptor. + events : s16; // Requested events. + revents : s16; // Returned events. + }; + + poll :: (fds: *pollfd, nfds: u32, timeout: s32) -> s32 #foreign libc; + // TODO Remote this. cfmakeraw :: (termios: *Terminal_IO_Mode) -> void #foreign libc; @@ -135,8 +145,8 @@ OS_prepare_terminal :: () { raw_tio_mode.c_lflag &= ~(.ECHO | .ECHONL | .ICANON | .ISIG | .IEXTEN); raw_tio_mode.c_cflag &= ~(.CSIZE | .PARENB); raw_tio_mode.c_cflag |= .CS8; - raw_tio_mode.c_cc[Control_Chars.VMIN] = 0; - raw_tio_mode.c_cc[Control_Chars.VTIME] = 1; + raw_tio_mode.c_cc[Control_Chars.VMIN] = 1; + raw_tio_mode.c_cc[Control_Chars.VTIME] = 0; tcsetattr(STDIN_FILENO, 0, *raw_tio_mode); // TODO Log on error. } @@ -144,48 +154,6 @@ OS_reset_terminal :: () { tcsetattr(STDIN_FILENO, 0, *initial_tio_mode); // TODO Log on error. } -OS_get_terminal_size :: () -> rows: int, columns: int { - - auto_release_temp(); - - flush_input(); - - // input := talloc_string(64); - write_string(Commands.QueryWindowSizeInChars); - // input.count = OS_read_input(input.data, input.count); - sleep_milliseconds(1); //TODO WHYYYY??? GOD DAMIT THREADS... - input := get_str(); - // input[0] = #char "x"; - // print(">%<", xx input); - // print("#<#"); - - // Expected message format: [8;<r>;<c>t - // where <r> is the number of rows and <c> of columns. - assert( - input[0] == #char "\e" && - input[1] == #char "[" && - input[2] == #char "8", - //input[input.count-1] == #char "t", - "Query windows size in chars returned invalid response."); - - parts := split(input, ";"); - rows := parse_int(*parts[1]); - columns := parse_int(*parts[2]); - return rows, columns; -} - -// OS_set_input_mode :: (mode: Input_Mode) { - // tio_mode: *Terminal_IO_Mode = ---; - // if mode == { - // case .HUMAN; - // tio_mode = *human_tio_mode; - // case; - // tio_mode = *cooked_tio_mode; - // } - // tcsetattr(STDIN_FILENO, 0, tio_mode); - // // TODO get_error_value_and_string :: () -> (error_code: OS_Error_Code, description: string) -// } - OS_read_input :: (buffer: *u8, bytes_to_read: s64) -> bytes_read: s64, error: bool = false, error_message: string = "" { bytes_read := read(STDIN_FILENO, buffer, xx bytes_to_read); if bytes_read < 0 { |
