aboutsummaryrefslogtreecommitdiff
path: root/modules/TUI/module.jai
diff options
context:
space:
mode:
authordam <dam@gudinoff>2024-05-05 03:22:42 +0100
committerdam <dam@gudinoff>2024-05-05 03:22:42 +0100
commit1ae2933bcbda43d16d2583a28c3c5a74adaaa9e4 (patch)
tree4918453917c4440c0586e94c4401e0b84a09cb85 /modules/TUI/module.jai
parent36af624cdd9cb54454587bfae21b30096986d22e (diff)
downloadtask-time-tracker-1ae2933bcbda43d16d2583a28c3c5a74adaaa9e4.tar.zst
task-time-tracker-1ae2933bcbda43d16d2583a28c3c5a74adaaa9e4.zip
Implemented default background and foreground colors.
Diffstat (limited to 'modules/TUI/module.jai')
-rw-r--r--modules/TUI/module.jai36
1 files changed, 23 insertions, 13 deletions
diff --git a/modules/TUI/module.jai b/modules/TUI/module.jai
index 07d121f..3f824a4 100644
--- a/modules/TUI/module.jai
+++ b/modules/TUI/module.jai
@@ -165,7 +165,7 @@ Style :: struct {
background = Palette.BLACK;
foreground = Palette.WHITE;
- // TODO Make this work...
+ // TODO Make this work... and now that is implemented... test it.
use_default_background_color := false;
use_default_foreground_color := false;
@@ -176,31 +176,41 @@ Style :: struct {
}
set_style :: inline (style: Style) {
- print(
- #run sprint(Commands.SetGraphicsRendition, "%;%;%;%"),
- ifx style.bold then 1 else 22,
- ifx style.underline then 4 else 24,
- ifx style.strike_through then 9 else 29,
- ifx style.negative then 7 else 27);
+ auto_release_temp();
+ builder := String_Builder.{ allocator = temporary_allocator };
+
#if COLOR_MODE_BITS == {
case 4;
- print(
+ print_to_builder(*builder,
#run sprint("%0%0", Commands.SetGraphicsRendition, Commands.SetGraphicsRendition),
- cast(u8)style.foreground + 30, cast(u8)style.background + 40);
+ cast(u8)style.foreground + 30, cast(u8)style.background + 40
+ );
case 8;
- print(
+ print_to_builder(*builder,
#run sprint(Commands.SetGraphicsRendition, "38;5;%;48;5;%"),
- cast(u8)style.foreground, cast(u8)style.background);
+ cast(u8)style.foreground, cast(u8)style.background
+ );
case 24;
- print(
+ print_to_builder(*builder,
#run sprint(Commands.SetGraphicsRendition, "38;2;%;%;%;48;2;%;%;%"),
style.foreground.r, style.foreground.g, style.foreground.b,
- style.background.r, style.background.g, style.background.b);
+ style.background.r, style.background.g, style.background.b
+ );
+ }
+
+ if style.use_default_foreground_color {
+ append(*builder, #run sprint(Commands.SetGraphicsRendition, "39"));
+ }
+
+ if style.use_default_background_color {
+ append(*builder, #run sprint(Commands.SetGraphicsRendition, "49"));
}
+ write_string(builder_to_string(*builder,, allocator = temporary_allocator));
+
context.terminal_style = style;
}