aboutsummaryrefslogtreecommitdiff
path: root/modules/TUI/module.jai
diff options
context:
space:
mode:
authordam <devnull@localhost>2024-04-15 12:38:18 +0100
committerdam <devnull@localhost>2024-04-15 12:38:18 +0100
commit3112131c24ede1ea343383ffd4f8ca7bc4783f47 (patch)
treeb1541d366eb42a1ea2ef5c4a889e045e8dc45119 /modules/TUI/module.jai
parent5844ab303d3d7fc396beb7c6d8a0104496608f08 (diff)
downloadtask-time-tracker-3112131c24ede1ea343383ffd4f8ca7bc4783f47.tar.zst
task-time-tracker-3112131c24ede1ea343383ffd4f8ca7bc4783f47.zip
Add module logger that switches between main/alternate screen buffers to write logs.
Diffstat (limited to 'modules/TUI/module.jai')
-rw-r--r--modules/TUI/module.jai27
1 files changed, 22 insertions, 5 deletions
diff --git a/modules/TUI/module.jai b/modules/TUI/module.jai
index 3843cd7..070161c 100644
--- a/modules/TUI/module.jai
+++ b/modules/TUI/module.jai
@@ -17,6 +17,11 @@
#import "UTF8";
#load "key_map.jai";
+#run {
+ assert(COLOR_MODE == 4 || COLOR_MODE == 8 || COLOR_MODE == 24, "Invalid COLOR_MODE. Valid values are 4, 8, or 24 (default).");
+ assert(input_buffer.count >= KEY_SIZE, "The input buffer size must be capable to hold an entire Key, which should be able to hold an UTF8 code (4 bytes) or a terminal escape code (6 bytes).");
+}
+
// Special Graphics Characters
Drawings :: struct {
Blank :: "\x5F";
@@ -271,9 +276,15 @@ input_buffer : [1024] u8;
input_string : string;
input_override : Key;
-#run {
- assert(COLOR_MODE == 4 || COLOR_MODE == 8 || COLOR_MODE == 24, "Invalid COLOR_MODE. Valid values are 4, 8, or 24 (default).");
- assert(input_buffer.count >= KEY_SIZE, "The input buffer size must be capable to hold an entire Key, which should be able to hold an UTF8 code (4 bytes) or a terminal escape code (6 bytes).");
+previous_logger : (message: string, data: *void, info: Log_Info);
+
+module_logger :: (message: string, data: *void, info: Log_Info) {
+ // print("%0%0\n%0", Commands.MainScreenBuffer, message, Commands.AlternateScreenBuffer);
+ x, y := get_cursor_position();
+ write_string(Commands.MainScreenBuffer);
+ previous_logger(message, data, info);
+ write_string(Commands.AlternateScreenBuffer);
+ set_cursor_position(x, y);
}
assert_is_active :: inline () {
@@ -444,7 +455,7 @@ read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key {
}
else {
set_cursor_position(x, y);
- for 0..chars_count print_character(#char "*");
+ for 1..chars_count print_character(#char "*");
for chars_count..count_limit-1 print_character(#char " ");
}
set_cursor_position(x+idx, y);
@@ -510,7 +521,7 @@ read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key {
start :: () {
if active == true return;
-
+
// TODO Should start() call flush_input internally?
setup_key_map(); // TODO This is being called multiple times... please fix me!
@@ -526,6 +537,9 @@ start :: () {
Commands.SetUTF8,
Commands.CursorNormalMode,
Commands.KeypadNumMode);
+
+ previous_logger = context.logger;
+ context.logger = module_logger;
OS_prepare_terminal();
@@ -538,6 +552,9 @@ stop :: () {
clear_style();
OS_reset_terminal();
+
+ context.logger = previous_logger;
+
write_strings(Commands.MainScreenBuffer, Commands.RestoreCursorPosition, Commands.ShowCursor);
}