aboutsummaryrefslogtreecommitdiff
path: root/modules/TUI/module.jai
diff options
context:
space:
mode:
authordam <dam@gudinoff>2024-04-06 01:51:16 +0100
committerdam <dam@gudinoff>2024-04-06 01:51:16 +0100
commitddb3e4f4192009a47fa094aaad5e57da9b8c2711 (patch)
tree06cc1e5b66fb199267abb3c408420f8b416f86e2 /modules/TUI/module.jai
parent3ea02310f77dcf6aac26152a13a7ec848c78077f (diff)
downloadtask-time-tracker-ddb3e4f4192009a47fa094aaad5e57da9b8c2711.tar.zst
task-time-tracker-ddb3e4f4192009a47fa094aaad5e57da9b8c2711.zip
Added styles.
Diffstat (limited to 'modules/TUI/module.jai')
-rw-r--r--modules/TUI/module.jai110
1 files changed, 54 insertions, 56 deletions
diff --git a/modules/TUI/module.jai b/modules/TUI/module.jai
index 225b13e..21cd88a 100644
--- a/modules/TUI/module.jai
+++ b/modules/TUI/module.jai
@@ -1,3 +1,5 @@
+#module_parameters(COLOR_BIT_DEPTH := 24);
+
#if OS == {
case .LINUX;
#load "unix.jai";
@@ -103,84 +105,80 @@ Commands :: struct {
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.
}
-Palette_8b :: enum u8 {
- BLACK :: 0;
- MAROON :: 1;
- GREEN :: 2;
- OLIVE :: 3;
- NAVY :: 4;
- PURPLE :: 5;
- TEAL :: 6;
- SILVER :: 7;
- GRAY :: 8;
- RED :: 9;
- LIME :: 10;
- YELLOW :: 11;
- BLUE :: 12;
- MAGENTA :: 13;
- CYAN :: 14;
- WHITE :: 15;
+#if COLOR_BIT_DEPTH == 4 {
+ #load "palette_4b.jai";
+
+ set_colors :: inline (foreground: Palette, background: Palette) {
+ print(
+ #run sprint("% %", Commands.SetGraphicsRendition, Commands.SetGraphicsRendition),
+ cast(u8)foreground + 30, cast(u8)background + 40);
+ }
}
+else #if COLOR_BIT_DEPTH == 8 {
+ #load "palette_8b.jai";
-Color_24b :: struct {
- r: u8;
- g: u8;
- b: u8;
+ set_colors :: inline (foreground: Palette, background: Palette) {
+ print(
+ #run sprint(Commands.SetGraphicsRendition, "38;5;%;48;5;%"),
+ cast(u8)foreground, cast(u8)background);
+ }
}
+else {
+ #load "palette_24b.jai";
-// Fix color tables using this: https://devmemo.io/cheatsheets/terminal_escape_code/
-
-
-// TODO Maybe rename.
-set_style_colors :: (foreground: Palette_8b, background: Palette_8b) {
- print(
- #run sprint(Commands.SetGraphicsRendition, "38;5;%;48;5;%"),
- cast(u8)foreground, cast(u8)background);
-}
+ Color_24b :: struct {
+ r: u8;
+ g: u8;
+ b: u8;
+ }
-set_colors_24b :: (foreground_r: Color_24b, background: Color_24b) {
- print(
- #run sprint(Commands.SetGraphicsRendition, "38;2;%;%;%;48;2;%;%;%"),
- foreground.r, foreground.g, foreground.b,
- background.r, background.g, background.b);
+ set_colors :: inline (foreground: Color_24b, background: Color_24b) {
+ print(
+ #run sprint(Commands.SetGraphicsRendition, "38;2;%;%;%;48;2;%;%;%"),
+ foreground.r, foreground.g, foreground.b,
+ background.r, background.g, background.b);
+ }
}
-// set_colors_24b :: (foreground_r: u255) // TODO https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
+#add_context tui_style: Style;
Style :: struct {
- background: Palette_8b;
- foreground: Palette_8b;
+ #if COLOR_BIT_DEPTH == 4 || COLOR_BIT_DEPTH == 8 {
+ background: Palette = .BLACK;
+ foreground: Palette = .WHITE;
+ } else {
+ background: Color_24b;
+ foreground: Color_24b;
+ }
bold: bool;
underline: bool;
strike_through: bool;
negative: bool;
}
-test :: () {
- start();
- set_cursor_position(2, 2);
- set_style_colors(.RED, .BLACK);
- print(" RED \n");
- set_style_colors(.MAGENTA, .BLACK);
- print(" MAGENTA \n");
- set_style_colors(.TEAL, .BLACK);
- print(" TEAL \n");
- sleep_milliseconds(3000);
- stop();
+set_font_style :: inline (bold: bool, underline: bool = false, strike_through: bool = false, negative: bool = false) {
+ print(
+ #run sprint(Commands.SetGraphicsRendition, "%;%;%;%"),
+ ifx bold then 1 else 22,
+ ifx underline then 4 else 24,
+ ifx strike_through then 9 else 29,
+ ifx negative then 7 else 27);
}
+set_style :: (style: Style) {
+ set_font_style(style.bold, style.underline, style.strike_through, style.negative);
+ set_colors(style.foreground, style.background);
+ context.tui_style = style;
+}
clear_style :: () {
write_string(#run sprint(Commands.SetGraphicsRendition, "0"));
}
-set_style :: (bold: bool, underline: bool = false, strike_through: bool = false, negative: bool = false) {
- print(
- #run sprint(Commands.SetGraphicsRendition, "%;%;%;%"),
- ifx bold then 1 else 22,
- ifx underline then 4 else 24,
- ifx strike_through then 9 else 29,
- ifx negative then 7 else 27);
+using_style :: (style: Style) #expand {
+ __style := context.tui_style;
+ set_style(style);
+ `defer set_style(__style);
}
// TODO Maybe make the OS_* procedures as inline?!