aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/TUI/module.jai32
-rw-r--r--ttt.jai76
2 files changed, 51 insertions, 57 deletions
diff --git a/modules/TUI/module.jai b/modules/TUI/module.jai
index fbf2dd9..764effe 100644
--- a/modules/TUI/module.jai
+++ b/modules/TUI/module.jai
@@ -264,7 +264,7 @@ Keys :: struct #type_info_none {
F12 : Key : #run to_key("#f12");
}
-initialized := false;
+active := false;
//input_buffer : [64] u8; // TODO FIXME Input buffer is too small!!!
input_buffer : [8] u8; // TODO FIXME Input buffer is too small!!!
@@ -277,17 +277,17 @@ input_override : Key;
assert(input_buffer.count >= KEY_SIZE, "The input buffer size must be capable to hold an entire terminal (6 bytes) or UTF8 (4 bytes) code.");
}
-assert_is_initialized :: inline () {
- assert(initialized, "TUI is not ready.");
+assert_is_active :: inline () {
+ assert(active, "TUI is not ready.");
}
set_next_key :: (key: Key) {
- assert_is_initialized();
+ assert_is_active();
input_override = key;
}
get_key :: (timeout_milliseconds: s32 = -1) -> Key {
- assert_is_initialized();
+ assert_is_active();
// BBBB BBBB & 1100 0000 == 10XX XXXX -> is continuation byte
is_utf8_continuation_byte :: inline (byte: u8) -> bool {
@@ -371,7 +371,7 @@ get_key :: (timeout_milliseconds: s32 = -1) -> Key {
// TODO Review me!
read_input :: (count_limit: int = -1, terminators: .. u8) -> string {
- assert_is_initialized();
+ assert_is_active();
assert(count_limit >= 0 || terminators.count > 0, "Infinite loop detected, aborting."); // TODO Maybe just return!?
@@ -533,7 +533,7 @@ read_input_line :: (count_limit: int, is_visible: bool = true) -> string, Key {
}
start :: () {
- if initialized == true return;
+ if active == true return;
setup_key_map(); // TODO This is being called multiple times... please fix me!
@@ -551,12 +551,12 @@ start :: () {
OS_prepare_terminal();
- initialized = true;
+ active = true;
}
stop :: () {
- if initialized == false return;
- initialized = false;
+ if active == false return;
+ active = false;
OS_reset_terminal();
write_strings(Commands.MainScreenBuffer, Commands.RestoreCursorPosition, Commands.ShowCursor);
@@ -574,7 +574,7 @@ flush_input :: () {
// }
draw_box :: (x: int, y: int, width: int, height: int) {
- assert_is_initialized();
+ assert_is_active();
// TODO Check if using a String_Builder improves performance (measure it)!
// TODO Validate input parameters against the terminal size.
@@ -620,13 +620,13 @@ draw_box :: (x: int, y: int, width: int, height: int) {
// TODO Maybe rename to "clear()"
clear_terminal :: inline () {
- assert_is_initialized();
+ assert_is_active();
write_string(Commands.ClearScreen);
}
// TODO Maybe rename to "get_size()"
get_terminal_size :: () -> rows: int, columns: int {
- assert_is_initialized();
+ assert_is_active();
auto_release_temp();
@@ -674,13 +674,13 @@ get_terminal_size :: () -> rows: int, columns: int {
}
set_cursor_position :: (row: int, column: int) {
- assert_is_initialized();
+ assert_is_active();
auto_release_temp();
print(Commands.SetCursorPosition, row, column);
}
get_cursor_position :: () -> row: int, column: int {
- assert_is_initialized();
+ assert_is_active();
auto_release_temp();
@@ -714,7 +714,7 @@ get_cursor_position :: () -> row: int, column: int {
}
set_terminal_title :: (title: string) {
- assert_is_initialized();
+ assert_is_active();
print(Commands.SetWindowTitle, title);
}
diff --git a/ttt.jai b/ttt.jai
index 9fa62d3..2bf3d28 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -114,59 +114,53 @@ Layouts :: enum u8 {
COMPACT;
}
-// TODO NEXT Implement error window!
-error_time_limit := Apollo_Time.{0, 0};
+error_message: string;
+
+error_time_limit := Apollo_Time.{0, 0};
print_error :: (format :string, args : .. Any) {
- // if stdscr == null { // || isendwin() == true { // Not in ncurses mode? TODO DAM
- // print(format, ..args);
- // print("\n");
- // }
- // else {
- // CHAR_SPACE :: #char " ";
- // w_size_x: int = ifx size_x > 120 then 120 else size_x - 2;
- // w_size_y: int = 4;
- // if (error_window == null) {
- //error_window = newwin(w_size_y, w_size_x, (size_y - w_size_y) / 2, (size_x - w_size_x) / 2); TODO DAM
- //wattron(error_window, COLOR_PAIR(xx Styles.ERROR)); TODO DAM
- //wborder(error_window, CHAR_SPACE, CHAR_SPACE, 0, 0, ACS_HLINE, ACS_HLINE, ACS_HLINE, ACS_HLINE); TODO DAM
- //mvwprintw(error_window, 0, 1, " Error "); TODO DAM
- //wmove(error_window, 1, 0); TODO DAM
- // }
- // else {
- //waddch(error_window, CHAR_SPACE); TODO DAM
- // }
- //wprintw(error_window, temp_c_string(tprint(format, args))); TODO DAM
- // error_time_limit = current_time_monotonic() + seconds_to_apollo(5);
- // }
+
+ if TUI.active == false {
+ print(format, ..args, to_standard_error = true);
+ print("\n");
+ return;
+ }
+
+ if error_message.data != null {
+ free(error_message.data);
+ }
+ error_message = sprint(format, args);
+
+ error_time_limit = current_time_monotonic() + seconds_to_apollo(5);
}
draw_error_window :: () {
- // if (error_window == null) return;
+ if error_time_limit < current_time_monotonic() return;
- // Hide error window after time-limit or if terminal is shrank.
- w_size_x: s32;
- w_size_y: s32;
- //getmaxyx(error_window, *w_size_y, *w_size_x); TODO DAM
+ // Don't show error if main window is too small.
+ w_size_x: int = ifx size_x > 120 then 120 else size_x - 2;
+ w_size_y: int = 3;
if (current_time_monotonic() >= error_time_limit
|| size_x - w_size_x < 2
|| size_y - w_size_y < 2
) {
- //delwin(error_window); TODO DAM
- // error_window = null;
return;
}
- // Adjust error window position.
- pos_x := (size_x - w_size_x) / 2;
- pos_y := (size_y - w_size_y) / 2;
- //mvwin(error_window, pos_y, pos_x); TODO DAM
-
- // Avoid being overwritten by main window content.
- //refresh(); TODO DAM
- //touchwin(error_window); TODO DAM
- //wrefresh(error_window); TODO DAM
+ pos_x := 1 + (size_x - w_size_x) / 2;
+ pos_y := 1 + (size_y - w_size_y) / 2;
+
+ TUI.using_style(style_error);
+ TUI.draw_box(pos_x, pos_y, w_size_x, w_size_y);
+ TUI.set_cursor_position(pos_y, pos_x + 1);
+ write_string(" Error ");
+ TUI.set_cursor_position(pos_y + 1, pos_x + 1);
+ for 1..w_size_x-2 {
+ print_character(#char " ");
+ }
+ TUI.set_cursor_position(pos_y + 1, pos_x + 1);
+ write_string(error_message);
}
trigger_autosave :: () {
@@ -1857,8 +1851,8 @@ main :: () {
if success == false continue;
target_index := clamp(value, 1, MAX_DATABASE_TASKS) - 1;
select_task(db, target_index);
-
- // Delete.
+
+ // Duplicate.
case #char "d"; #through;
case #char "D";
if selected_task == null continue;