terminal_state : struct { // size : ivec2; width: s32; height: s32; // cursor := ivec2.{-1, -1}; // {-1, -1} if cursor hidden x: s32 = -1; y: s32 = -1; last_mode : Graphics_Mode; } #if OS == .LINUX { #import "POSIX"; __term : My_Termios; My_Termios :: struct { c_iflag : u32; c_oflag : u32; c_cflag : u32; c_lflag : u32; unknown_pad : u8; c_cc : [32]u8; c_ispeed : u32; c_ospeed : u32; } libc :: #system_library "libc"; tcsetattr :: (fd : s32, optional_actions : s32, termios_p : *My_Termios) -> s32 #foreign libc; tcgetattr :: (fd : s32, termios_p : *My_Termios) -> s32 #foreign libc; } else { assert(false, "unsupported OS\n"); } Graphics_Mode :: struct { foreground : Color; background : Color; attr_flags : enum_flags u8 { F_BOLD :: 0x1; F_DIM :: 0x2; F_ITALIC :: 0x4; F_UNDERLINE :: 0x8; F_BLINKING :: 0x10; F_INVERSE :: 0x20; F_STRIKETHROUGH :: 0x40; } // attrs : [MAX_ATTRS]bool; // 0 - bold (on/off/keep) // 1 - dim/faint // 2 - italic // 3 - underline // 4 - blinking // 5 - inverse // 6 - strikethrough fcol256 : u8; bcol256 : u8; } Color :: enum u8 { RESET :: 0; DEFAULT :: 39; COLOR256 :: 38; BLACK :: 30; RED :: 31; GREEN :: 32; YELLOW :: 33; BLUE :: 34; MAGENTA :: 35; CYAN :: 36; WHITE :: 37; BRIGHT_BLACK :: 90; BRIGHT_RED :: 91; BRIGHT_GREEN :: 92; BRIGHT_YELLOW :: 93; BRIGHT_BLUE :: 94; BRIGHT_MAGENTA :: 95; BRIGHT_CYAN :: 96; BRIGHT_WHITE :: 97; } __old_logger : type_of(context.logger); initialize :: () { #if OS == .LINUX { tcgetattr(STDIN_FILENO, *__term); } else { assert(false, "procedure call on unsupported OS\n"); } } terminate :: () { #if OS == .LINUX { tcsetattr(STDIN_FILENO, 0, *__term); // return echo tio_write("\e[?47l"); // restore screen tio_write("\e8"); // restore cursor tio_write("\e[?25h"); // show cursor tio_write("\e[?30h"); // show scrollbar terminal_state = .{}; context.logger = __old_logger; } else { assert(false, "procedure call on unsupported OS\n"); } } tio_write :: (str : string) { #if OS == .LINUX { write(STDIN_FILENO, str.data, xx str.count); } else { assert(false, "procedure call on unsupported OS\n"); } }