aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordam <dam@gudinoff>2024-03-31 23:47:35 +0100
committerdam <dam@gudinoff>2024-03-31 23:47:35 +0100
commit3ea02310f77dcf6aac26152a13a7ec848c78077f (patch)
tree329ffc4379672abb33d301e1dab351c5868da9b9
parentebf43b78a33c5b878b8cf600c3527c7a78dac3d2 (diff)
downloadtask-time-tracker-3ea02310f77dcf6aac26152a13a7ec848c78077f.tar.zst
task-time-tracker-3ea02310f77dcf6aac26152a13a7ec848c78077f.zip
WIP : Setup TUI styles.
-rw-r--r--modules/TUI/module.jai87
-rw-r--r--ttt.jai10
2 files changed, 73 insertions, 24 deletions
diff --git a/modules/TUI/module.jai b/modules/TUI/module.jai
index 796334a..225b13e 100644
--- a/modules/TUI/module.jai
+++ b/modules/TUI/module.jai
@@ -103,40 +103,77 @@ 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.
}
-clear_style :: () {
- write_string(#run sprint(Commands.SetGraphicsRendition, "0"));
+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;
}
-Colors8b :: struct {
- 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;
+Color_24b :: struct {
+ r: u8;
+ g: u8;
+ b: u8;
}
// Fix color tables using this: https://devmemo.io/cheatsheets/terminal_escape_code/
+
// TODO Maybe rename.
-set_style_colors :: (foreground: u8, background: u8) {
+set_style_colors :: (foreground: Palette_8b, background: Palette_8b) {
print(
#run sprint(Commands.SetGraphicsRendition, "38;5;%;48;5;%"),
- foreground, background);
+ cast(u8)foreground, cast(u8)background);
+}
+
+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_24b :: (foreground_r: u255) // TODO https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
+Style :: struct {
+ background: Palette_8b;
+ foreground: Palette_8b;
+ 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();
+}
+
+
+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, "%;%;%;%"),
@@ -386,6 +423,7 @@ read_input :: (count_limit: int = -1, terminators: .. u8) -> string {
}
}
+// TODO Provide an advanced read_input_line function that allows some styling and to set a placeholder text.
read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key {
/*
Use the get_key to read user input and show it on screen.
@@ -401,6 +439,13 @@ read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key {
str.count = 0;
idx := 0;
+ // placeholder: string = "",
+ // {
+ // copy_size := ifx placeholder.count > str.count then str.count else placeholder.count;
+ // memcpy(str.data, placeholder.data, copy_size);
+ // idx = copy_size;
+ // }
+
// TODO Some of these may be nice to have:
// > https://unix.stackexchange.com/questions/255707/what-are-the-keyboard-shortcuts-for-the-command-line
diff --git a/ttt.jai b/ttt.jai
index 5229914..35a4bc2 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -1059,7 +1059,7 @@ draw_tui :: (db: *Database, layout: *Layout) {
// Apply theme.
if (task == active_task && task == selected_task) {
// attron(COLOR_PAIR(xx Styles.ACTIVE_SELECTED) | A_BOLD); TODO DAM
- TUI.set_style_colors(TUI.Colors8b.Red, 6); // TODO TESTING COLORS
+ TUI.set_style_colors(.RED, 6); // TODO TESTING COLORS
TUI.set_style(true, true, true, false);
}
else if (task == selected_task) {
@@ -1067,7 +1067,7 @@ draw_tui :: (db: *Database, layout: *Layout) {
TUI.set_style_colors(4, 6); // TODO TESTING COLORS
}
else if (task == active_task) {
- TUI.set_style_colors(TUI.Colors8b.Red, 6); // TODO TESTING COLORS
+ TUI.set_style_colors(.RED, 6); // TODO TESTING COLORS
TUI.set_style(false, false, false, true); // TODO TESTING STYLE
// attron(COLOR_PAIR(xx Styles.ACTIVE) | A_BOLD); TODO DAM
}
@@ -1224,7 +1224,7 @@ prompt_user_key :: (row: int, style: int, message: string) -> TUI.Key {
TUI.set_cursor_position(row, 2);
write_string(TUI.Commands.DrawingMode);
- for 0..size_x-2 {
+ for 1..size_x-2 {
print(TUI.Drawings.Checkerboard);
}
write_string(TUI.Commands.TextMode);
@@ -1236,6 +1236,10 @@ prompt_user_key :: (row: int, style: int, message: string) -> TUI.Key {
main :: () {
+ TUI.test();
+ exit(0);
+
+
// -- -- -- Testing TUI -- START
perform_test := false;