feat(tui): redesign chrome with unified key hints and help overlay
Introduce one key-hint grammar across every view: bold key, dim label, priority-ordered hints that drop from the end instead of ellipsizing. The month footer becomes a single split status bar with a friendly selected date, the '?' mega-line becomes a real keyboard shortcut panel, and the editor, agenda, search, picker, detail, and delete frames share the same chips. Notifications carry check/warning marks. Adds a live PTY smoke test covering view interaction and terminal state restoration on q and Ctrl-C exits.
This commit is contained in:
@@ -48,6 +48,42 @@ bool ordered(std::string_view line, const std::vector<std::string_view>& labels)
|
||||
return true;
|
||||
}
|
||||
|
||||
// Codepoint count; every glyph used in these frames is one cell wide.
|
||||
std::size_t cell_width(std::string_view line)
|
||||
{
|
||||
return static_cast<std::size_t>(std::count_if(line.begin(), line.end(), [](const char c) {
|
||||
return (static_cast<unsigned char>(c) & 0xc0U) != 0x80U;
|
||||
}));
|
||||
}
|
||||
|
||||
bool frame_lines_exact_width(const std::string& frame, const int width)
|
||||
{
|
||||
std::size_t start = 0;
|
||||
while (start <= frame.size()) {
|
||||
const auto end = frame.find('\n', start);
|
||||
const auto line = std::string_view{frame}.substr(
|
||||
start, end == std::string::npos ? frame.size() - start : end - start);
|
||||
if (cell_width(line) != static_cast<std::size_t>(width)) return false;
|
||||
if (end == std::string::npos) break;
|
||||
start = end + 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
nocal::tui::ScreenState base_state(const int width, const int height)
|
||||
{
|
||||
using namespace std::chrono;
|
||||
auto state = nocal::tui::ScreenState{};
|
||||
state.visible_month = year{2026} / July;
|
||||
state.selected_day = year{2026} / July / day{17};
|
||||
state.today = year{2026} / July / day{17};
|
||||
state.width = width;
|
||||
state.height = height;
|
||||
state.ansi = false;
|
||||
state.week_start = Monday;
|
||||
return state;
|
||||
}
|
||||
|
||||
nocal::Event all_day_event(std::string uid, std::string title,
|
||||
nocal::Date start, nocal::Date exclusive_end)
|
||||
{
|
||||
@@ -110,12 +146,15 @@ void test_full_month_render()
|
||||
const auto frame = nocal::tui::render_month(items, state);
|
||||
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("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");
|
||||
check(frame_lines_exact_width(frame, 100), "month frame lines fill the exact width");
|
||||
check(frame.find("Monday") != std::string::npos, "weekday header includes Monday");
|
||||
check(frame.find("Tuesday") != std::string::npos, "weekday header includes Tuesday");
|
||||
}
|
||||
|
||||
void test_compact_and_input()
|
||||
@@ -352,7 +391,7 @@ void test_agenda_empty_frame()
|
||||
{
|
||||
using namespace std::chrono;
|
||||
auto state = nocal::tui::ScreenState{};
|
||||
state.width = 64;
|
||||
state.width = 72;
|
||||
state.height = 9;
|
||||
state.ansi = false;
|
||||
state.show_agenda = true;
|
||||
@@ -365,7 +404,7 @@ void test_agenda_empty_frame()
|
||||
"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,
|
||||
check(frame.find("g 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");
|
||||
@@ -403,9 +442,10 @@ void test_agenda_selection_and_scrolling()
|
||||
|
||||
const auto frame = nocal::tui::render_month(
|
||||
std::span<const nocal::tui::CalendarItem>{}, state);
|
||||
check(frame.find("Holiday") == std::string::npos &&
|
||||
// With 1-row footer, row_capacity = 4, showing indices 0-3
|
||||
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");
|
||||
"agenda shows items with the selected item 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,
|
||||
@@ -433,10 +473,86 @@ void test_agenda_input_and_search_precedence()
|
||||
|
||||
} // namespace
|
||||
|
||||
void test_help_frame()
|
||||
{
|
||||
using namespace std::chrono;
|
||||
auto state = base_state(80, 24);
|
||||
state.show_help = true;
|
||||
const auto frame = nocal::tui::render_month(std::span<const nocal::tui::CalendarItem>{}, state);
|
||||
check(frame.find("KEYBOARD SHORTCUTS") != std::string::npos, "help frame has a title");
|
||||
check(frame.find("NAVIGATE") != std::string::npos &&
|
||||
frame.find("APPOINTMENTS") != std::string::npos &&
|
||||
frame.find("VIEWS") != std::string::npos &&
|
||||
frame.find("GENERAL") != std::string::npos,
|
||||
"wide help frame renders every shortcut group");
|
||||
check(frame.find("Redo last change") != std::string::npos &&
|
||||
frame.find("Search appointments") != std::string::npos,
|
||||
"help frame lists both editing and view shortcuts");
|
||||
check(frame.find("? close") != std::string::npos &&
|
||||
frame.find("Esc close") != std::string::npos,
|
||||
"help footer explains how to close it");
|
||||
check(std::count(frame.begin(), frame.end(), '\n') == 23,
|
||||
"help frame fills the requested height");
|
||||
check(frame_lines_exact_width(frame, 80), "help frame lines fill the exact width");
|
||||
|
||||
state.width = 60;
|
||||
const auto narrow = nocal::tui::render_month(std::span<const nocal::tui::CalendarItem>{}, state);
|
||||
check(narrow.find("NAVIGATE") != std::string::npos &&
|
||||
narrow.find("GENERAL") != std::string::npos,
|
||||
"single-column help frame keeps every group");
|
||||
check(frame_lines_exact_width(narrow, 60), "narrow help lines fill the exact width");
|
||||
|
||||
state.ansi = true;
|
||||
const auto styled = nocal::tui::render_month(std::span<const nocal::tui::CalendarItem>{}, state);
|
||||
check(styled.find("\x1b[1m") != std::string::npos, "help keys are bold when ANSI is on");
|
||||
}
|
||||
|
||||
void test_status_bar_chrome()
|
||||
{
|
||||
using namespace std::chrono;
|
||||
const std::vector<nocal::tui::CalendarItem> items{
|
||||
{.id = "1", .title = "Design review", .day = year{2026} / July / day{17},
|
||||
.time_of_day = hours{9} + minutes{30}, .all_day = false,
|
||||
.end_time_of_day = std::nullopt, .start_day = {}, .end_day = {},
|
||||
.location = {}, .description = {}, .detail_title = {},
|
||||
.detail_all_day = false, .detail_start_time_of_day = std::nullopt,
|
||||
.segment = nocal::tui::ItemSegment::single, .recurring = false,
|
||||
.recurrence_summary = {}, .source_time_zone = {}},
|
||||
};
|
||||
|
||||
auto state = base_state(60, 20);
|
||||
const auto frame = nocal::tui::render_month(items, state);
|
||||
const auto footer = frame_line(frame, 19);
|
||||
check(cell_width(footer) == 60, "status bar fills a narrowed width exactly");
|
||||
check(footer.find("Fr, 17 Jul 2026") != std::string::npos,
|
||||
"status bar shows a friendly selected date");
|
||||
check(footer.find("Tab focus") != std::string::npos &&
|
||||
footer.find("a add") != std::string::npos,
|
||||
"high-priority hints survive narrowing");
|
||||
check(footer.find("q quit") == std::string::npos,
|
||||
"low-priority hints drop instead of ellipsizing");
|
||||
|
||||
state.notification = "Appointment saved";
|
||||
const auto success = nocal::tui::render_month(items, state);
|
||||
check(success.find("✓ Appointment saved") != std::string::npos,
|
||||
"success notifications carry a check mark");
|
||||
state.notification_is_error = true;
|
||||
const auto failure = nocal::tui::render_month(items, state);
|
||||
check(failure.find("! Appointment saved") != std::string::npos,
|
||||
"error notifications carry a warning mark");
|
||||
|
||||
state = base_state(30, 12);
|
||||
const auto compact = nocal::tui::render_month(items, state);
|
||||
check(frame_lines_exact_width(compact, 30),
|
||||
"compact frame hint lines never overflow their width");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_full_month_render();
|
||||
test_compact_and_input();
|
||||
test_help_frame();
|
||||
test_status_bar_chrome();
|
||||
test_sunday_start_full_render_and_domain_window();
|
||||
test_wednesday_start_compact_render();
|
||||
test_monday_default_and_invalid_week_start_fallback();
|
||||
|
||||
Reference in New Issue
Block a user