From 1ae2933bcbda43d16d2583a28c3c5a74adaaa9e4 Mon Sep 17 00:00:00 2001 From: dam Date: Sun, 5 May 2024 03:22:42 +0100 Subject: Implemented default background and foreground colors. --- modules/TUI/module.jai | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'modules/TUI/module.jai') 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; } -- cgit v1.2.3