diff options
Diffstat (limited to 'ttt.jai')
| -rw-r--r-- | ttt.jai | 63 |
1 files changed, 58 insertions, 5 deletions
@@ -19,6 +19,7 @@ #import "Basic"()(MEMORY_DEBUGGER=true); // TODO Remove after final debug sessions. #import "System"; +#import "Sort"; #import "Math"; #import "POSIX"; #import "File"; @@ -122,7 +123,7 @@ print_error :: (format :string, args : .. Any) { else { waddch(error_window, CHAR_SPACE); } - vw_printw(error_window, to_c_string(format), args); + wprintw(error_window, temp_c_string(tprint(format, args))); error_time_limit = current_time_monotonic() + seconds_to_apollo(5); } } @@ -1141,19 +1142,24 @@ read_input_int :: (row: int, style: s32, message: string) -> value: int, success } // Retuns true if user presses enter, false otherwise. -read_enter_confirmation :: (row: int, style: int, message: string) -> bool { +read_input_char :: (row: int, style: int, message: string) -> s32 { assert(message.data != null, ASSERT_NOT_NULL, "message"); // TODO Improve this check? attron(xx style); move(xx row, 1); for 0..size_x-3 { - //for (int idx = 0; idx < size_x - 2; idx++) { + //for (int idx = 0; idx < size_x - 2; idx++) { // TODO check what's going on here. addch(ACS_CKBOARD); } mvaddstr(xx row, 2, message.data); attrset(A_NORMAL); - return getch() == #char "\n"; + return getch(); +} + +// Retuns true if user presses enter, false otherwise. +read_enter_confirmation :: inline (row: int, style: int, message: string) -> bool { + return read_input_char(row, style, message) == #char "\n"; } main :: () { @@ -1221,6 +1227,7 @@ main :: () { " -v, --version Output version information and exit.\n", "\n", "In app commands\n", + " w, W Archive a duplicate and reset times for all tasks.\n", " a, A Archive selected task (except if active).\n", " r, R Restore selected task from archive.\n", " t, T Select currently active task (if any).\n", @@ -1229,8 +1236,11 @@ main :: () { " m, M Move selected task to position.\n", " g, G Select task by position.\n", " i, I Invert tasks order.\n", + " s, S Sort tasks by:\n", + " n name;\n", + " t total time;\n", + " 1..7 time of Nth day of week.\n", " q, Q Save changes and exit.\n", - " w, W Archive duplicates and reset all tasks.\n", // TODO Improve message. " F2 Rename selected task.\n", " F5 Recalculate total times.\n", " TAB Toggle archive view.\n", @@ -1407,6 +1417,7 @@ main :: () { } if db.active_idx >= 0 db.active_idx = count - db.active_idx; + trigger_autosave(); case #char "n"; #through; case #char "N"; @@ -1603,6 +1614,7 @@ main :: () { delete_task(db, db.selected_idx); trigger_autosave(); + // Restore archived task. case #char "r"; #through; case #char "R"; if (db != *archive || selected_task == null) continue; @@ -1619,6 +1631,47 @@ main :: () { delete_task(db, db.selected_idx); trigger_autosave(); + // Sort by. + case #char "s"; #through; + case #char "S"; + sort_by := read_input_char(selected_task_row, action_style, " Sort by (n) name, (1..7) day, or (t) total time. "); + if sort_by == { + case #char "n"; #through; + case #char "N"; + quick_sort(db.tasks, (x, y) => compare_strings(xx x.name, xx y.name)); + + case #char "t"; #through; + case #char "T"; + compare_tasks :: (x: Task, y: Task) -> s64 { + total_x, total_y: s64; + for x.times { total_x = add_int64(total_x, it); }; + for y.times { total_y = add_int64(total_y, it); }; + return sub_int64(total_x, total_y); + }; + quick_sort(db.tasks, compare_tasks); + + case #char "1"; #through; + case #char "2"; #through; + case #char "3"; #through; + case #char "4"; #through; + case #char "5"; #through; + case #char "6"; #through; + case #char "7"; + sort_by_idx := sort_by - #char "1"; + day := (sort_by_idx + FIRST_DAY_OF_WEEK) % NUM_WEEK_DAYS; + if day == { + case 0; quick_sort(db.tasks, (x, y) => x.times[0] - y.times[0]); + case 1; quick_sort(db.tasks, (x, y) => x.times[1] - y.times[1]); + case 2; quick_sort(db.tasks, (x, y) => x.times[2] - y.times[2]); + case 3; quick_sort(db.tasks, (x, y) => x.times[3] - y.times[3]); + case 4; quick_sort(db.tasks, (x, y) => x.times[4] - y.times[4]); + case 5; quick_sort(db.tasks, (x, y) => x.times[5] - y.times[5]); + case 6; quick_sort(db.tasks, (x, y) => x.times[6] - y.times[6]); + } + } + trigger_autosave(); + + // Workspace cleanup. case #char "w"; #through; case #char "W"; if (db != *database || db.tasks.count <= 0) continue; |
