feat: add bounded agenda view

Add a read-only 42-day occurrence agenda with keyboard navigation, six-week paging, exact return-to-grid focus, search and calendar overlays, and bounded recurrence expansion.

Keep agenda state outside persistence, document month-only mutations, and cover empty windows, filtering, overlays, navigation, rendering, and terminal restoration.
This commit is contained in:
2026-07-18 09:19:01 +01:00
parent 590db2f488
commit 8b6cf2e877
11 changed files with 609 additions and 16 deletions

View File

@@ -191,6 +191,7 @@ void test_key_decoding()
check(decode_key("d") == Action::delete_event, "d decodes as delete appointment");
check(decode_key("u") == Action::undo, "u decodes as undo");
check(decode_key("\x12") == Action::redo, "Ctrl-R decodes as redo");
check(decode_key("g") == Action::agenda, "g decodes as agenda");
}
void test_crud_preconditions_and_add()
@@ -1039,6 +1040,182 @@ void test_calendar_visibility_filters_without_partial_saves()
check(save_calls == 1, "all visibility-only interactions remain unsaved session state");
}
void test_agenda_window_order_visibility_and_bounds()
{
using namespace std::chrono;
const auto first_day = nocal::today();
const auto second_day = nocal::from_sys_days(nocal::to_sys_days(first_day) + days{1});
const auto after_window = nocal::from_sys_days(nocal::to_sys_days(first_day) + days{42});
auto series = make_event("agenda-series", "Daily standup", first_day, 9, 0,
first_day, 9, 30);
series.recurrence = nocal::RecurrenceRule{
.frequency = nocal::RecurrenceFrequency::daily,
.interval = 1,
.count = 100,
.until = std::nullopt,
.by_weekday = {},
.by_month_day = {},
.by_month = {},
};
auto hidden = make_event("hidden-agenda", "Hidden work", first_day, 7, 0,
first_day, 8, 0);
hidden.calendar_id = "work";
std::vector<nocal::Event> events{
make_event("timed", "Morning review", first_day, 8, 0, first_day, 8, 30),
make_event("all-day", "Release day", first_day, 0, 0, second_day, 0, 0, true),
series,
hidden,
make_event("outside", "Outside window", after_window, 6, 0,
after_window, 7, 0),
};
int save_calls = 0;
nocal::tui::TuiApp app{
events, [&](std::span<const nocal::Event>) { ++save_calls; }, -1, -1};
app.dispatch(nocal::tui::Action::calendars);
app.dispatch(nocal::tui::Action::down);
app.dispatch(nocal::tui::Action::select);
app.dispatch(nocal::tui::Action::back);
app.handle_input("g");
check(app.agenda_active() && app.state().agenda_start_day == first_day,
"g opens a 42-day agenda anchored at the selected day");
check(app.state().agenda_items.size() == 44,
"agenda recurrence expansion is bounded to its 42-day window");
if (app.state().agenda_items.size() == 44) {
check(app.state().agenda_items[0].focus_id == "all-day" &&
app.state().agenda_items[1].focus_id == "timed" &&
app.state().agenda_items[2].focus_id.starts_with("agenda-series@occ:"),
"agenda retains domain occurrence order with all-day items first");
check(app.state().agenda_items.back().day ==
nocal::from_sys_days(nocal::to_sys_days(first_day) + days{41}),
"agenda includes the final day inside the half-open 42-day window");
}
check(std::none_of(app.state().agenda_items.begin(), app.state().agenda_items.end(),
[&](const nocal::tui::AgendaItem& item) {
return item.focus_id == "hidden-agenda" ||
item.focus_id == "outside" ||
nocal::to_sys_days(item.day) >= nocal::to_sys_days(after_window);
}),
"agenda excludes hidden calendars and occurrences outside its window");
check(save_calls == 0, "opening and filtering agenda never saves events");
}
void test_agenda_navigation_shift_choice_and_close()
{
using namespace std::chrono;
const auto first_day = nocal::today();
auto series = make_event("choose-series", "Choose exact occurrence", first_day, 9, 0,
first_day, 10, 0);
series.recurrence = nocal::RecurrenceRule{
.frequency = nocal::RecurrenceFrequency::daily,
.interval = 1,
.count = 100,
.until = std::nullopt,
.by_weekday = {},
.by_month_day = {},
.by_month = {},
};
std::vector<nocal::Event> events{series};
int save_calls = 0;
nocal::tui::TuiApp app{
events, [&](std::span<const nocal::Event>) { ++save_calls; }, -1, -1};
const auto month_day = app.state().selected_day;
const auto month = app.state().visible_month;
app.dispatch(nocal::tui::Action::agenda);
app.handle_input("k");
check(app.state().agenda_index == 0,
"agenda navigation clamps at the first item instead of wrapping");
app.handle_input("j");
check(app.state().agenda_index == 1, "j advances agenda selection");
for (std::size_t index = 0; index < app.state().agenda_items.size() + 2; ++index) {
app.dispatch(nocal::tui::Action::down);
}
check(app.state().agenda_index + 1 == app.state().agenda_items.size(),
"agenda navigation clamps at the final item instead of wrapping");
app.handle_input("n");
check(app.state().agenda_start_day ==
nocal::from_sys_days(nocal::to_sys_days(first_day) + days{42}) &&
app.state().agenda_index == 0 && !app.state().agenda_items.empty() &&
app.state().agenda_items.front().day == app.state().agenda_start_day,
"n shifts exactly 42 days and refreshes agenda from its new start");
app.handle_input("\x1b[5~");
check(app.state().agenda_start_day == first_day && app.state().agenda_index == 0,
"Page Up shifts agenda exactly 42 days back and resets selection safely");
app.dispatch(nocal::tui::Action::down);
const auto chosen = app.state().agenda_items[app.state().agenda_index];
app.dispatch(nocal::tui::Action::select);
check(!app.agenda_active() && app.state().selected_day == chosen.day &&
app.state().visible_month == chosen.day.year() / chosen.day.month() &&
app.state().focused_event_id == std::optional{chosen.focus_id},
"Enter returns to month and focuses the exact recurring occurrence");
const auto chosen_day = app.state().selected_day;
const auto chosen_month = app.state().visible_month;
app.dispatch(nocal::tui::Action::agenda);
app.dispatch(nocal::tui::Action::next_month);
app.dispatch(nocal::tui::Action::agenda);
check(!app.agenda_active() && app.state().selected_day == chosen_day &&
app.state().visible_month == chosen_month,
"g closes agenda without changing the prior month selection");
app.dispatch(nocal::tui::Action::agenda);
app.dispatch(nocal::tui::Action::previous_month);
app.dispatch(nocal::tui::Action::back);
check(!app.agenda_active() && app.state().selected_day == chosen_day &&
app.state().visible_month == chosen_month,
"Escape closes agenda without applying its shifted window to month selection");
check(month_day == first_day && month == first_day.year() / first_day.month(),
"agenda navigation fixture starts on the controller's month selection");
check(save_calls == 0, "all agenda navigation and selection remains read-only");
std::vector<nocal::Event> empty_events;
nocal::tui::TuiApp empty{empty_events, -1, -1};
empty.dispatch(nocal::tui::Action::agenda);
empty.dispatch(nocal::tui::Action::up);
empty.dispatch(nocal::tui::Action::down);
empty.dispatch(nocal::tui::Action::select);
check(empty.agenda_active() && empty.state().agenda_items.empty() &&
empty.state().agenda_index == 0,
"empty agenda navigation and Enter are safe no-ops");
}
void test_agenda_search_and_calendar_overlays()
{
const auto day = nocal::today();
auto personal = make_event("agenda-personal", "Personal", day, 8, 0, day, 9, 0);
personal.calendar_id = "personal";
std::vector<nocal::Event> events{
make_event("agenda-default", "Default", day, 7, 0, day, 8, 0), personal};
int save_calls = 0;
nocal::tui::TuiApp app{
events, [&](std::span<const nocal::Event>) { ++save_calls; }, -1, -1};
app.dispatch(nocal::tui::Action::agenda);
app.handle_input("/");
check(app.agenda_active() && app.search_active(),
"search prompt can overlay an active agenda");
app.handle_input("\x1b");
check(app.agenda_active() && !app.search_active(),
"Escape closes search and returns to the underlying agenda");
app.handle_input("c");
check(app.agenda_active() && app.calendar_picker_active(),
"calendar picker can overlay an active agenda");
app.dispatch(nocal::tui::Action::down);
app.dispatch(nocal::tui::Action::select);
check(!app.calendars()[1].visible && app.state().agenda_items.size() == 1 &&
app.state().agenda_items.front().focus_id == "agenda-default",
"hiding a calendar immediately refreshes the agenda beneath the picker");
app.dispatch(nocal::tui::Action::back);
check(app.agenda_active() && !app.calendar_picker_active(),
"closing the picker returns to the agenda");
check(save_calls == 0, "agenda overlays and visibility changes never save events");
}
} // namespace
int main()
@@ -1067,6 +1244,9 @@ int main()
test_recurrence_grid_expansion_and_source_zone_display();
test_search_prompt_results_and_occurrence_jump();
test_calendar_visibility_filters_without_partial_saves();
test_agenda_window_order_visibility_and_bounds();
test_agenda_navigation_shift_choice_and_close();
test_agenda_search_and_calendar_overlays();
if (failures != 0) {
std::cerr << failures << " TUI focus test(s) failed\n";
return EXIT_FAILURE;

View File

@@ -43,6 +43,12 @@ void test_full_month_render()
.search_result_index = 0,
.notification = {},
.notification_is_error = false,
.show_calendar_picker = false,
.calendar_index = 0,
.show_agenda = false,
.agenda_start_day = year{1970} / January / day{1},
.agenda_items = {},
.agenda_index = 0,
};
const std::vector<nocal::tui::CalendarItem> items{
{.id = "1", .title = "Design review", .day = year{2026} / July / day{17},
@@ -65,6 +71,8 @@ void test_full_month_render()
check(frame.find("Design") != std::string::npos, "appointment appears in its day cell");
check(frame.find("Release") != std::string::npos, "all-day appointment appears in its day cell");
check(frame.find("July 2026") != std::string::npos, "month title is rendered");
check(frame.find("g agenda") != std::string::npos,
"month footer advertises the agenda view");
check(std::count(frame.begin(), frame.end(), '\n') == 29,
"renderer fills the requested height deterministically");
check(frame.find("\x1b[") == std::string::npos, "ANSI can be disabled");
@@ -91,6 +99,12 @@ void test_compact_and_input()
.search_result_index = 0,
.notification = {},
.notification_is_error = false,
.show_calendar_picker = false,
.calendar_index = 0,
.show_agenda = false,
.agenda_start_day = year{1970} / January / day{1},
.agenda_items = {},
.agenda_index = 0,
};
const auto frame = nocal::tui::render_month(std::span<const nocal::tui::CalendarItem>{}, state);
check(frame.find("July 2026") != std::string::npos, "compact mode keeps month context");
@@ -190,6 +204,89 @@ void test_search_frames()
"slash opens appointment search");
}
void test_agenda_empty_frame()
{
using namespace std::chrono;
auto state = nocal::tui::ScreenState{};
state.width = 64;
state.height = 9;
state.ansi = false;
state.show_agenda = true;
state.agenda_start_day = year{2026} / July / day{6};
const auto frame = nocal::tui::render_month(
std::span<const nocal::tui::CalendarItem>{}, state);
check(frame.find("AGENDA") != std::string::npos &&
frame.find("2026-07-06 2026-08-16 (inclusive)") != std::string::npos,
"empty agenda renders its inclusive 42-day range");
check(frame.find("No appointments in this 6-week window.") != std::string::npos,
"empty agenda explains that its window has no appointments");
check(frame.find("g/Esc close") != std::string::npos,
"agenda footer explains how to close the view");
check(std::count(frame.begin(), frame.end(), '\n') == 8,
"empty agenda fills the requested height");
check(frame.find("\x1b[") == std::string::npos,
"agenda remains readable with ANSI disabled");
}
void test_agenda_selection_and_scrolling()
{
using namespace std::chrono;
auto state = nocal::tui::ScreenState{};
state.width = 88;
state.height = 7;
state.ansi = true;
state.show_agenda = true;
state.agenda_start_day = year{2026} / July / day{6};
state.agenda_items = {
{.focus_id = "late", .title = "Release", .day = year{2026} / July / day{12},
.time_of_day = hours{14} + minutes{30}, .all_day = false,
.location = "Studio", .calendar_id = "work", .recurring = true},
{.focus_id = "early", .title = "Holiday", .day = year{2026} / July / day{7},
.time_of_day = std::nullopt, .all_day = true,
.location = {}, .calendar_id = "home", .recurring = false},
{.focus_id = "middle", .title = "Planning", .day = year{2026} / July / day{9},
.time_of_day = hours{9}, .all_day = false,
.location = {}, .calendar_id = "work", .recurring = false},
{.focus_id = "selected", .title = "Retrospective", .day = year{2026} / July / day{13},
.time_of_day = hours{16}, .all_day = false,
.location = "Room 2", .calendar_id = "work", .recurring = false},
{.focus_id = "last", .title = "Dinner", .day = year{2026} / July / day{14},
.time_of_day = hours{19}, .all_day = false,
.location = {}, .calendar_id = "home", .recurring = false},
};
state.agenda_index = 3;
const auto frame = nocal::tui::render_month(
std::span<const nocal::tui::CalendarItem>{}, state);
check(frame.find("Holiday") == std::string::npos &&
frame.find("2026-07-12 14:30 local ↻ Release — Studio") != std::string::npos,
"agenda scrolls chronologically to keep a late selection visible");
check(frame.find(" 2026-07-13 16:00 local Retrospective — Room 2") != std::string::npos,
"agenda marks the selected row and includes optional location");
check(frame.find("\x1b[7;1m") != std::string::npos,
"ANSI agenda gives the selected row visible focus");
check(std::count(frame.begin(), frame.end(), '\n') == 6,
"scrolling agenda fills the requested height");
}
void test_agenda_input_and_search_precedence()
{
auto state = nocal::tui::ScreenState{};
state.width = 50;
state.height = 6;
state.ansi = false;
state.show_agenda = true;
state.search_prompt = true;
const auto frame = nocal::tui::render_month(
std::span<const nocal::tui::CalendarItem>{}, state);
check(frame.find("SEARCH APPOINTMENTS") != std::string::npos &&
frame.find("AGENDA") == std::string::npos,
"search rendering takes precedence over agenda rendering");
check(nocal::tui::decode_key("g") == nocal::tui::Action::agenda,
"g toggles the agenda view");
}
} // namespace
int main()
@@ -199,6 +296,9 @@ int main()
test_navigation();
test_search_frames();
test_calendar_picker_frame();
test_agenda_empty_frame();
test_agenda_selection_and_scrolling();
test_agenda_input_and_search_precedence();
if (failures != 0) {
std::cerr << failures << " TUI test(s) failed\n";
return EXIT_FAILURE;