aboutsummaryrefslogtreecommitdiff
path: root/TUI/module.jai
diff options
context:
space:
mode:
Diffstat (limited to 'TUI/module.jai')
-rw-r--r--TUI/module.jai61
1 files changed, 36 insertions, 25 deletions
diff --git a/TUI/module.jai b/TUI/module.jai
index 9014be7..37c0f31 100644
--- a/TUI/module.jai
+++ b/TUI/module.jai
@@ -43,11 +43,11 @@ Drawings :: struct {
}
Commands :: struct {
- StartAlternateBuffer :: "\e[?1049h";
- StartMainBuffer :: "\e[?1049l";
+ AlternateScreenBuffer :: "\e[?1049h";
+ MainScreenBuffer :: "\e[?1049l";
- StartDrawingMode :: "\e(0";
- StartNormalMode :: "\e(B";
+ DrawingMode :: "\e(0";
+ TextMode :: "\e(B";
ClearScreen :: "\e[2J";
ClearLine :: "\e[2K";
@@ -59,6 +59,10 @@ Commands :: struct {
SetUTF8 :: "\e%G"; // TODO TEST ME PLEASE
+ // WIP WIP WIP
+ // Add commands to change StyleNormal/Italic/Bold/Color/WhatNot!
+
+
// Cursor Position
SetCursorPosition :: "\e[%;%H";
@@ -92,21 +96,30 @@ Commands :: struct {
}
-// TODO Maybe make the OS_* procedures as inline?!
-
-// We wanted the Key type to represent either UTF-8 encoded characters and also keyboard keys.
-// The UTF-8 only requires up to 4 bytes, but some keyboard keys return up to 6 bytes.
-// Therefore, we rounded it up to 8 bytes to support all this and more (if needed).
+GraphicsStyle :: struct {
+ BackgroundColor : u8;
+ ForegroundColor : u8;
+ Bold : bool;
+ Italic : bool;
+ Underline : bool;
+ Blinking : bool;
+ Inverse : bool;
+ StrikeThrough : bool;
+}
+// TODO Maybe make the OS_* procedures as inline?!
/*
- In this block, we're testing having the Key as a union of both [8]u8 and u64.
- It kinda looks OK, but it may drive the users to extract info from the code while
- it should be used only for comparison.
+ We wanted the Key type to represent either UTF-8 encoded characters and also keyboard keys.
+ The UTF-8 only requires up to 4 bytes, but some keyboard keys return up to 6 bytes.
+ Therefore, we rounded it up to 8 bytes to support all this and more (if needed).
+
+ This has to be compatible with: (#char "a" == key) ... so "a" must be stored in the LSB of key
+ |-|-|-|-|-|
+ string |a|b|c|0|0|
+ key/u64 |0|0|c|b|a| -> that in memory lays as (BE:|0|0|c|b|a|) and (LE:|a|b|c|0|0|)
*/
-
-
Key :: u64;
KEY_SIZE :: #run type_info(Key).runtime_size;
@@ -125,13 +138,6 @@ Keys :: struct {
PgDown : Key : #run to_key("\e[6~");
}
-/* TODO
- This has to be compatible with: (#char "a" == key) ... so "a" must be stored in the LSB of key
- |-|-|-|-|-|
- string |a|b|c|0|0|
- key/u64 |0|0|c|b|a| -> that in memory lays as (BE:|0|0|c|b|a|) and (LE:|a|b|c|0|0|)
-*/
-
to_key :: inline (str: $T) -> Key #modify { return T == ([]u8) || T == string; } {
k: Key;
// #if DEBUG {
@@ -371,7 +377,7 @@ start :: () {
input_string.count = 0;
input_override = xx Keys.None;
- write_strings(Commands.HideCursor, Commands.SaveCursorPosition, Commands.StartAlternateBuffer, Commands.SetUTF8);
+ write_strings(Commands.HideCursor, Commands.SaveCursorPosition, Commands.AlternateScreenBuffer, Commands.SetUTF8);
OS_prepare_terminal();
initialized = true;
@@ -382,13 +388,18 @@ stop :: () {
initialized = false;
OS_reset_terminal();
- write_strings(Commands.StartMainBuffer, Commands.RestoreCursorPosition, Commands.ShowCursor);
+ write_strings(Commands.MainScreenBuffer, Commands.RestoreCursorPosition, Commands.ShowCursor);
}
flush_input :: () {
OS_flush_input();
}
+// WIP WIP WIP
+// set_style :: () {
+ // print("", Commands.) --
+// }
+
draw_box :: (x: int, y: int, width: int, height: int) {
assert_is_initialized();
@@ -402,7 +413,7 @@ draw_box :: (x: int, y: int, width: int, height: int) {
tmp_string = tprint(Commands.SetCursorPosition, y, x);
write_strings(
- Commands.StartDrawingMode,
+ Commands.DrawingMode,
tmp_string,
Drawings.CornerTL
);
@@ -431,7 +442,7 @@ draw_box :: (x: int, y: int, width: int, height: int) {
}
write_string(Drawings.CornerBR);
- write_string(Commands.StartNormalMode);
+ write_string(Commands.TextMode);
}
// TODO Maybe rename to "clear()"