aboutsummaryrefslogtreecommitdiff
path: root/ttt.jai
diff options
context:
space:
mode:
authordam <dam@gudinoff>2024-04-07 02:46:59 +0100
committerdam <dam@gudinoff>2024-04-07 02:46:59 +0100
commit194d919eb827e6c6df03917b1732f253e5eac0b5 (patch)
tree49f0e84976b84aa3adaa40ac341e4549697b62a2 /ttt.jai
parent8016c5c04e3d452dab583b2c9c2161a5a950ea65 (diff)
downloadtask-time-tracker-194d919eb827e6c6df03917b1732f253e5eac0b5.tar.zst
task-time-tracker-194d919eb827e6c6df03917b1732f253e5eac0b5.zip
Implement error window.
Diffstat (limited to 'ttt.jai')
-rw-r--r--ttt.jai76
1 files changed, 35 insertions, 41 deletions
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;