diff options
| author | dam <devnull@localhost> | 2024-04-15 16:50:42 +0100 |
|---|---|---|
| committer | dam <devnull@localhost> | 2024-04-15 16:50:42 +0100 |
| commit | bb1d53daa526d734fb2e33c2090f8396f87544ec (patch) | |
| tree | 52e90e50b02cb3a46143e92e129f9525dbfdc5c4 /modules/TUI/module.jai | |
| parent | 3112131c24ede1ea343383ffd4f8ca7bc4783f47 (diff) | |
| download | task-time-tracker-bb1d53daa526d734fb2e33c2090f8396f87544ec.tar.zst task-time-tracker-bb1d53daa526d734fb2e33c2090f8396f87544ec.zip | |
Improved TUI logger; added snake example using TUI.
Diffstat (limited to 'modules/TUI/module.jai')
| -rw-r--r-- | modules/TUI/module.jai | 72 |
1 files changed, 37 insertions, 35 deletions
diff --git a/modules/TUI/module.jai b/modules/TUI/module.jai index 070161c..b5866d5 100644 --- a/modules/TUI/module.jai +++ b/modules/TUI/module.jai @@ -59,38 +59,44 @@ Drawings :: struct { } Commands :: struct { + // Screen buffers AlternateScreenBuffer :: "\e[?1049h"; - MainScreenBuffer :: "\e[?1049l"; + MainScreenBuffer :: "\e[?1049l"; + // Device. + Bell :: "\x07"; + QueryDeviceAttributes :: "\e[0c"; + + // Draw/text. DrawingMode :: "\e(0"; TextMode :: "\e(B"; ClearScreen :: "\e[2J"; ClearLine :: "\e[2K"; ClearScrollBack :: "\e[3J"; - - Bell :: "\x07"; - + SetGraphicsRendition :: "\e[%m"; + + // Character encoding. + EncodingIEC2022 :: "\e%@"; + EncodingUTF8 :: "\e%G"; + + // Window. SetWindowTitle :: "\e]0;%\e\\"; - - RefreshWindow :: "\e[7t"; // TODO Not yet tested. Is this required? + RefreshWindow :: "\e[7t"; + QueryWindowSizeInChars :: "\e[18t"; - SetIEC2022 :: "\e%@"; // TODO Remove this!? - SetUTF8 :: "\e%G"; // TODO Remove this!? - - SetGraphicsRendition :: "\e[%m"; - - // Cursor Position + // Cursor position. + SaveCursorPosition :: "\e7"; + RestoreCursorPosition :: "\e8"; SetCursorPosition :: "\e[%;%H"; - - // Cursor Visibility + QueryCursorPosition :: "\e[6n"; + + // Cursor visibility. ShowCursor :: "\e[?25h"; HideCursor :: "\e[?25l"; - StartBlinking :: "\e[?25h"; - StopBlinking :: "\e[?25l"; - SaveCursorPosition :: "\e7"; - RestoreCursorPosition :: "\e8"; - - // Cursor Shape + StartBlinking :: "\e[?12h"; + StopBlinking :: "\e[?12l"; + + // Cursor shape DefaultShape :: "\e[0 q"; BlinkingBlockShape :: "\e[1 q"; SteadyBlockShape :: "\e[2 q"; @@ -98,17 +104,12 @@ Commands :: struct { SteadyUnderlineShape :: "\e[4 q"; BlinkingBarShape :: "\e[5 q"; SteadyBarShape :: "\e[6 q"; - - // Input Mode + + // Input mode. KeypadAppMode :: "\e="; KeypadNumMode :: "\e>"; CursorAppMode :: "\e[?1h"; CursorNormalMode :: "\e[?1l"; - - // Query State - QueryCursorPosition :: "\e[6n"; // Emits the cursor position as: "ESC [ <r> ; <c> R" Where <r> = row and <c> = column. - QueryDeviceAttributes :: "\e[0c"; - QueryWindowSizeInChars :: "\e[18t"; // Emits the window size as: "ESC [ 8 <r> ; <c> t" Where <r> = row and <c> = column. TODO Does not work on windows. } #if COLOR_MODE == 4 { @@ -150,12 +151,16 @@ else { Style :: struct { #if COLOR_MODE == 4 || COLOR_MODE == 8 { - background: Palette = .BLACK; - foreground: Palette = .WHITE; + background: Palette; + foreground: Palette; } else { background: Color_24b; foreground: Color_24b; } + + background = Palette.BLACK; + foreground = Palette.WHITE; + bold: bool; underline: bool; strike_through: bool; @@ -279,12 +284,9 @@ input_override : Key; previous_logger : (message: string, data: *void, info: Log_Info); module_logger :: (message: string, data: *void, info: Log_Info) { - // print("%0%0\n%0", Commands.MainScreenBuffer, message, Commands.AlternateScreenBuffer); - x, y := get_cursor_position(); - write_string(Commands.MainScreenBuffer); + write_strings(Commands.SaveCursorPosition, Commands.MainScreenBuffer); previous_logger(message, data, info); - write_string(Commands.AlternateScreenBuffer); - set_cursor_position(x, y); + write_strings(Commands.AlternateScreenBuffer, Commands.RestoreCursorPosition); } assert_is_active :: inline () { @@ -534,7 +536,7 @@ start :: () { Commands.HideCursor, Commands.SaveCursorPosition, Commands.AlternateScreenBuffer, - Commands.SetUTF8, + Commands.EncodingUTF8, Commands.CursorNormalMode, Commands.KeypadNumMode); |
