aboutsummaryrefslogtreecommitdiff
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
parent36af624cdd9cb54454587bfae21b30096986d22e (diff)
downloadtask-time-tracker-1ae2933bcbda43d16d2583a28c3c5a74adaaa9e4.tar.zst
task-time-tracker-1ae2933bcbda43d16d2583a28c3c5a74adaaa9e4.zip
Implemented default background and foreground colors.
-rw-r--r--modules/TUI/module.jai36
-rw-r--r--ttt.jai15
2 files changed, 36 insertions, 15 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;
}
diff --git a/ttt.jai b/ttt.jai
index f3f1905..0715544 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -17,7 +17,12 @@
// - release : jai ttt.jai -quiet -x64 -release
// - debug : jai ttt.jai -quiet -x64
+DEBUG_MEMORY :: true;
+#if DEBUG_MEMORY {
#import "Basic"()(MEMORY_DEBUGGER=true); // TODO Remove after final debug sessions. This takes up ~30MB of RAM.
+} else {
+#import "Basic";
+}
#import "System";
#import "Sort";
#import "Math";
@@ -1157,8 +1162,10 @@ prompt_user_key :: (y: int, message: string) -> TUI.Key {
}
main :: () {
-
+
+#if DEBUG_MEMORY {
defer report_memory_leaks(); // TODO Remove after final debug sessions.
+}
defer free_memory();
@@ -1774,7 +1781,11 @@ main :: () {
}
assert(TUI.reset_terminal(), "Failed to reset TUI.");
-
+
+#if DEBUG_MEMORY {
+ return;
+} else {
exit(xx ifx error_saving then 1 else 0);
}
+}