aboutsummaryrefslogtreecommitdiff
path: root/modules/TUI/module.jai
diff options
context:
space:
mode:
Diffstat (limited to 'modules/TUI/module.jai')
-rw-r--r--modules/TUI/module.jai87
1 files changed, 66 insertions, 21 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