diff options
| author | dam <dam@gudinoff> | 2023-12-24 14:31:34 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2023-12-24 14:31:34 +0000 |
| commit | 2a20d715b56cf60f090b856ba6f1c98a3c87fe9f (patch) | |
| tree | abc075aaec884ccee2e4c0a2346d9d87b93cf065 | |
| parent | 3d9e9a30f6ce5dee1775bdd1fbe28f07e41365b2 (diff) | |
| download | task-time-tracker-2a20d715b56cf60f090b856ba6f1c98a3c87fe9f.tar.zst task-time-tracker-2a20d715b56cf60f090b856ba6f1c98a3c87fe9f.zip | |
Starting to implement graphics styles.
| -rw-r--r-- | TUI/module.jai | 61 | ||||
| -rw-r--r-- | ttt.jai | 8 |
2 files changed, 40 insertions, 29 deletions
diff --git a/TUI/module.jai b/TUI/module.jai index 9014be7..37c0f31 100644 --- a/TUI/module.jai +++ b/TUI/module.jai @@ -43,11 +43,11 @@ Drawings :: struct { } Commands :: struct { - StartAlternateBuffer :: "\e[?1049h"; - StartMainBuffer :: "\e[?1049l"; + AlternateScreenBuffer :: "\e[?1049h"; + MainScreenBuffer :: "\e[?1049l"; - StartDrawingMode :: "\e(0"; - StartNormalMode :: "\e(B"; + DrawingMode :: "\e(0"; + TextMode :: "\e(B"; ClearScreen :: "\e[2J"; ClearLine :: "\e[2K"; @@ -59,6 +59,10 @@ Commands :: struct { SetUTF8 :: "\e%G"; // TODO TEST ME PLEASE + // WIP WIP WIP + // Add commands to change StyleNormal/Italic/Bold/Color/WhatNot! + + // Cursor Position SetCursorPosition :: "\e[%;%H"; @@ -92,21 +96,30 @@ Commands :: struct { } -// TODO Maybe make the OS_* procedures as inline?! - -// We wanted the Key type to represent either UTF-8 encoded characters and also keyboard keys. -// The UTF-8 only requires up to 4 bytes, but some keyboard keys return up to 6 bytes. -// Therefore, we rounded it up to 8 bytes to support all this and more (if needed). +GraphicsStyle :: struct { + BackgroundColor : u8; + ForegroundColor : u8; + Bold : bool; + Italic : bool; + Underline : bool; + Blinking : bool; + Inverse : bool; + StrikeThrough : bool; +} +// TODO Maybe make the OS_* procedures as inline?! /* - In this block, we're testing having the Key as a union of both [8]u8 and u64. - It kinda looks OK, but it may drive the users to extract info from the code while - it should be used only for comparison. + We wanted the Key type to represent either UTF-8 encoded characters and also keyboard keys. + The UTF-8 only requires up to 4 bytes, but some keyboard keys return up to 6 bytes. + Therefore, we rounded it up to 8 bytes to support all this and more (if needed). + + This has to be compatible with: (#char "a" == key) ... so "a" must be stored in the LSB of key + |-|-|-|-|-| + string |a|b|c|0|0| + key/u64 |0|0|c|b|a| -> that in memory lays as (BE:|0|0|c|b|a|) and (LE:|a|b|c|0|0|) */ - - Key :: u64; KEY_SIZE :: #run type_info(Key).runtime_size; @@ -125,13 +138,6 @@ Keys :: struct { PgDown : Key : #run to_key("\e[6~"); } -/* TODO - This has to be compatible with: (#char "a" == key) ... so "a" must be stored in the LSB of key - |-|-|-|-|-| - string |a|b|c|0|0| - key/u64 |0|0|c|b|a| -> that in memory lays as (BE:|0|0|c|b|a|) and (LE:|a|b|c|0|0|) -*/ - to_key :: inline (str: $T) -> Key #modify { return T == ([]u8) || T == string; } { k: Key; // #if DEBUG { @@ -371,7 +377,7 @@ start :: () { input_string.count = 0; input_override = xx Keys.None; - write_strings(Commands.HideCursor, Commands.SaveCursorPosition, Commands.StartAlternateBuffer, Commands.SetUTF8); + write_strings(Commands.HideCursor, Commands.SaveCursorPosition, Commands.AlternateScreenBuffer, Commands.SetUTF8); OS_prepare_terminal(); initialized = true; @@ -382,13 +388,18 @@ stop :: () { initialized = false; OS_reset_terminal(); - write_strings(Commands.StartMainBuffer, Commands.RestoreCursorPosition, Commands.ShowCursor); + write_strings(Commands.MainScreenBuffer, Commands.RestoreCursorPosition, Commands.ShowCursor); } flush_input :: () { OS_flush_input(); } +// WIP WIP WIP +// set_style :: () { + // print("", Commands.) -- +// } + draw_box :: (x: int, y: int, width: int, height: int) { assert_is_initialized(); @@ -402,7 +413,7 @@ draw_box :: (x: int, y: int, width: int, height: int) { tmp_string = tprint(Commands.SetCursorPosition, y, x); write_strings( - Commands.StartDrawingMode, + Commands.DrawingMode, tmp_string, Drawings.CornerTL ); @@ -431,7 +442,7 @@ draw_box :: (x: int, y: int, width: int, height: int) { } write_string(Drawings.CornerBR); - write_string(Commands.StartNormalMode); + write_string(Commands.TextMode); } // TODO Maybe rename to "clear()" @@ -17,7 +17,7 @@ // - release : jai ttt.jai -import_dir . -quiet -x64 -release // - debug : jai ttt.jai -import_dir . -quiet -x64 -#import "Basic"()(MEMORY_DEBUGGER=true); // TODO Remove after final debug sessions. +#import "Basic"()(MEMORY_DEBUGGER=true); // TODO Remove after final debug sessions. This takes up ~30MB of RAM. #import "System"; #import "Sort"; #import "Math"; @@ -48,7 +48,7 @@ WINDOW :: struct { } // TODO DAM VERSION :: "2.0"; // Use only 3 chars (to fit layouts). -YEAR :: "2023"; +YEAR :: "2024"; FIRST_DAY_OF_WEEK :: 1; // (0-6, Sunday = 0). NUM_WEEK_DAYS :: 7; // TODO This has to go - Just to be more clear about what we're looping about. NAME_SIZE :: 72; // TODO Use this instead of Task.name.count ? @@ -989,7 +989,7 @@ draw_tui :: (db: *Database, layout: *Layout) { // TODO Maybe this could be simplified? y = 1; x = 1; - write_string(TUI.Commands.StartDrawingMode); + write_string(TUI.Commands.DrawingMode); for 0..layout.columns.count-2 { column := layout.columns[it]; x += 1 + column.width; @@ -1002,7 +1002,7 @@ draw_tui :: (db: *Database, layout: *Layout) { TUI.set_cursor_position(size_y, x); write_string(TUI.Drawings.TeeB); } - write_string(TUI.Commands.StartNormalMode); + write_string(TUI.Commands.TextMode); /////////////////////////////////////////////////////////////////////////// |
