diff options
Diffstat (limited to 'ttt.jai')
| -rw-r--r-- | ttt.jai | 72 |
1 files changed, 42 insertions, 30 deletions
@@ -902,7 +902,7 @@ initialize_tui :: () { } // TODO DAM - TIO.initialize(); + TUI.start(); // stdscr = initscr(); // Start curses mode. TODO DAM // cbreak(); // Line buffering disabled; pass on everty thing to me. TODO DAM // keypad(stdscr, true); // I need those nifty F1..F12. TODO DAM @@ -956,11 +956,10 @@ draw_tui :: (db: *Database, layout: *Layout) { // Reset theme and clear screen. //attrset(A_NORMAL); TODO DAM - TIO.tui_clear_screen(); + TUI.clear_terminal(); // Draw outer border. - //box(stdscr, 0, 0); TODO DAM - // WIP + TUI.draw_box(1, 1, size_x, size_y); // Draw table grids. // TODO Maybe this could be simplified? @@ -979,13 +978,15 @@ draw_tui :: (db: *Database, layout: *Layout) { /////////////////////////////////////////////////////////////////////////// // Draw headers. - y = 0; - x = 0; + y = 1; + x = 1; // Headers : title x += 1; col = *layout.columns[L_TITLE_IDX]; //mvaddstr(xx y, xx (x + col.alignment_offset), ifx db == *archive then layout.archive_title.data else col.header.data); TODO DAM + TUI.set_cursor_position(y, x + col.alignment_offset); + write_string(ifx db == *archive then layout.archive_title else col.header); x += col.width; // Headers : days @@ -1003,6 +1004,8 @@ draw_tui :: (db: *Database, layout: *Layout) { col = *layout.columns[L_DAYS_IDX + idx]; //mvaddstr(xx y, xx (x + col.alignment_offset), col.header.data); TODO DAM + TUI.set_cursor_position(y, x + col.alignment_offset); + write_string(col.header); x += col.width; // Reset theme. @@ -1013,6 +1016,8 @@ draw_tui :: (db: *Database, layout: *Layout) { x += 1; col = *layout.columns[L_TOTAL_IDX]; //mvaddstr(xx y, xx (x + col.alignment_offset), col.header.data); TODO DAM + TUI.set_cursor_position(y, x + col.alignment_offset); + write_string(col.header); /////////////////////////////////////////////////////////////////////////// @@ -1021,7 +1026,7 @@ draw_tui :: (db: *Database, layout: *Layout) { total_time := 0; column_width: int; - y = 0; + y = 1; // Pagination based on currently selected task (show page where selected task is). idx_start := (db.selected_idx / layout_tasks_rows) * layout_tasks_rows; // Display up to rows allowed by the layout, or less if reached end of database. @@ -1030,7 +1035,7 @@ draw_tui :: (db: *Database, layout: *Layout) { auto_release_temp(); // TODO Temporary memory being trashed?! task := *db.tasks[task_idx]; y += 1; - x = 0; + x = 1; // Apply theme. if (task == active_task && task == selected_task) { @@ -1047,6 +1052,8 @@ draw_tui :: (db: *Database, layout: *Layout) { x += 1; column_width = layout.columns[L_TITLE_IDX].width; // mvprintw(xx y, xx x, "%-*.*s", column_width, column_width, temp_c_string(xx task.name)); //task.name); TODO Fix required for LLVM/Cncurses. TODO DAM + TUI.set_cursor_position(y, x); + print("%", cast(string)task.name); // TODO Needs adjustment to fit column width. x += column_width; // Task times. @@ -1072,12 +1079,16 @@ draw_tui :: (db: *Database, layout: *Layout) { /////////////////////////////////////////////////////////////////////////// // Draw selected/total tasks. + // TODO Something is wrong here... sometimes it only changes to the small format on the 1001 instead of 1000. FIXME size := 1 + count_digits(db.selected_idx + 1) + 1 + count_digits(db.tasks.count) + 1; // " XXX/YYY " + TUI.set_cursor_position(size_y, 2); if (size <= layout.columns[L_TITLE_IDX].width) { // mvprintw(size_y - 1, 1, " %td/%zd ", db.selected_idx + 1, db.tasks.count); TODO DAM + print(" %/% ", db.selected_idx + 1, db.tasks.count); } else { // mvprintw(size_y - 1, 1, "%td", db.selected_idx + 1); TODO DAM + print("%", db.selected_idx + 1); } @@ -1274,7 +1285,13 @@ main :: () { case; { TUI.set_cursor_position(3+drop_down, 2); - write_string(TUI.to_string(key)); + str := TUI.to_string(key); + for 0..str.count-1 { + if str[it] == #char "\e" { + str[it] = #char "?"; + } + } + write_string(str); drop_down += 1; } } @@ -1291,10 +1308,6 @@ main :: () { print("size(CxR): %x%\n", xcolumns, xrows); } - #if true { - return; - } - // -- -- -- Testing TUI -- STOP @@ -1481,9 +1494,9 @@ main :: () { db := *database; layout := *layouts[Layouts.COMPACT]; - - //flushinp(); TODO DAM - TIO.tui_ungetch(KEY_RESIZE); // TODO DAM + + TUI.flush_input(); + TUI.set_next_key(TUI.Keys.Resize); while (true) { if (is_terminal_too_small) { @@ -1496,8 +1509,7 @@ main :: () { } reset_temporary_storage(); - //timeout(INPUT_TIMEOUT_MS); TODO DAM - key := TIO.tui_getch(); // getch(); TODO DAM + key := TUI.get_key(INPUT_TIMEOUT_MS); if key == #char "q" || key == #char "Q" break; update_times(*database); //timeout(INPUT_AWAIT_INF); TODO DAM @@ -1518,10 +1530,11 @@ main :: () { else ifx (selected_idx < 0) then 1 else (selected_idx % layout_tasks_rows) + NUM_HEADER_ROWS; } + if key == { // When getch() times out. - case .READ_ERROR; + case TUI.Keys.None; if (is_autosave_enabled && countdown_to_autosave > 0) { countdown_to_autosave -= INPUT_TIMEOUT_MS; if (countdown_to_autosave <= 0) { @@ -1534,14 +1547,13 @@ main :: () { } // When terminal is resized. - case KEY_RESIZE; - TIO.tui_clear_screen(); + case TUI.Keys.Resize; + TUI.clear_terminal(); //getmaxyx(stdscr, *size_y, *size_x); - TIO.update_terminal_size(); // TODO DAM - size_x = TIO.terminal_state.width; - size_y = TIO.terminal_state.height; + _y, _x := TUI.get_terminal_size(); + size_y = xx _y; + size_x = xx _x; print("resize:%x%", size_x, size_y); - asd := TIO.tui_getch(); is_terminal_too_small = size_x < 60 || size_y < 3; update_layout(); layout = *layouts[ifx size_x > 100 then Layouts.NORMAL else Layouts.COMPACT]; @@ -1853,19 +1865,19 @@ main :: () { case KEY_HOME; select_task(db, 0); - case KEY_UP; + case TUI.Keys.Up; select_task_by_delta(db, -1); - case KEY_PPAGE; + case TUI.Keys.PgUp; select_task_by_delta(db, -layout_tasks_rows); case KEY_END; select_task(db, db.tasks.count-1); - case KEY_DOWN; + case TUI.Keys.Down; select_task_by_delta(db, 1); - case KEY_NPAGE; + case TUI.Keys.PgDown; select_task_by_delta(db, layout_tasks_rows); } } @@ -1892,7 +1904,7 @@ main :: () { //getch(); TODO DAM } - TIO.terminate(); // TODO DAM + TUI.stop(); exit(xx ifx error_saving then 1 else 0); } |
