(9b7fa7d) Expand the campaign frame with enter

Three rows of prose was the right default and the wrong ceiling. enter
while the frame holds the selection gives it half the board, enter again
gives the rows back, and pgup and pgdn go on doing what they do against
whichever height it is at.

Half of what the frame and the columns divide, which is the screen less
the tab row and the footer. Half rather than most of it for the same
reason the frame is not an overlay: the columns below are the campaign's
members, and a reader inspecting the campaign has to go on seeing what
it is made of. So `Chrome::campaign` is an `Option<FrameSize>` rather
than a bool and `campaign_rows` takes a height, resolved in `frame_rows`
because that is the one place that already has an area to take a share
of, which keeps `Chrome` itself pure.

Bounded at both ends, and the upper bound is the one that matters:
`Constraint::Min(COLUMN_MIN_ROWS)` would take rows back from a frame
that asked for too many, silently, and the frame's own measurement would
then disagree with what is drawn. Floored at the collapsed height, since
expanding must never shrink the frame, so a board too short to divide
gives the collapsed height back rather than one nothing measured. Swept
over every height from 4 to 60, tabbed and not.

q does not gain a layer and the arrow keys do not take the height back.
The expanded frame is the frame at its other height, not a thing laid
over the board, so q goes on taking the campaign filter off from either
and enter is the only key that undoes what enter did. The height
outlives the selection for the same reason: it is a view of the campaign
the reader chose, so the columns stay short with the selection on a
card. `dismiss` and `select_card` are untouched, and two tests pin that.

`enter` routes through `Board::toggle_focused` rather than in the
`main.rs` arm, the rule `dismiss` and `scroll_page` follow. It was inert
on the frame for free before, because `Tab::selected` hands back nothing
there and `toggle_detail` had nothing to open; that answer is now the
thing in the way, and AGENTS.md and `Tab::selected`'s doc are amended
rather than left describing the key by what it used to do.

The toggle re-clamps the frame offset through `scroll_frame(0, screen)`.
A taller viewport has a smaller last offset, so where the reader was can
end up past the end of the frame they just asked for, and the next pgup
would count down from a number the frame never showed.

Criterion 13 is not done: 2a83bd4 has not landed, so there is no tag
frame to give a second height to. What it inherits is on the ticket, and
all of it is generic rather than campaign-specific.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ansho Rei
2026-08-24 03:08:39 +02:00
co-authored by Claude Opus 5
parent af1ef1f97f
commit dd2b457bff
6 changed files with 509 additions and 24 deletions
+4 -1
View File
@@ -210,7 +210,10 @@ fn run_tui(paths: &[std::path::PathBuf], start: &std::path::Path) -> Result<()>
KeyCode::Char('c') if key.modifiers.contains(KeyModifiers::CONTROL) => {
board.should_quit = true
}
KeyCode::Enter | KeyCode::Char(' ') => board.toggle_detail(),
// The frame's own height while it holds the selection, and the detail
// overlay on a card. `Board::toggle_focused` rather than a condition here,
// for the reason the scroll keys route there.
KeyCode::Enter | KeyCode::Char(' ') => board.toggle_focused(screen),
KeyCode::Left | KeyCode::Char('h') => board.select_column(-1, screen),
KeyCode::Right | KeyCode::Char('l') => board.select_column(1, screen),
// Up and down stay on the selection, open detail view or not, so a
+493 -16
View File
@@ -44,8 +44,25 @@ const ALL: &str = "all";
pub struct Chrome {
/// Whether the tab row is drawn, which is whether more than one board is monitored.
pub tabbed: bool,
/// Whether the campaign frame is drawn, which is whether a campaign is selected.
pub campaign: bool,
/// The campaign frame, at the height it is drawn, or `None` for a tab showing the whole
/// board.
///
/// A state rather than the bool it was, because the frame has two heights now and every
/// measurement of the board has to agree about which one it is at. `Option` rather than a
/// third variant, so "there is no frame" stays the shape it was and the two heights are
/// only ever compared with each other.
pub campaign: Option<FrameSize>,
}
/// How much of the board the campaign frame is taking.
///
/// Collapsed is where it opens and where it goes back to. Expanded is what `enter` asks for
/// while the frame holds the selection, and it outlives the selection: the height is a view
/// the reader chose, not a property of where the selection happens to be.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum FrameSize {
Collapsed,
Expanded,
}
impl Chrome {
@@ -72,14 +89,49 @@ impl Chrome {
/// spent here is a row of cards.
const CAMPAIGN_ROWS: u16 = Self::CAMPAIGN_PROSE_ROWS + 2;
fn campaign_rows(self) -> u16 {
match self.campaign {
true => Self::CAMPAIGN_ROWS,
false => 0,
/// The rows the frame takes out of a board `height` rows tall.
///
/// The height comes in because the expanded frame is a *share* rather than a second
/// constant, and `frame_rows` is the one place that already has an area to take a share
/// of — which is what keeps `Chrome` itself cheap and pure and copied from
/// `Board::chrome` without a screen to hand.
///
/// Half of what the frame and the columns divide between them: the board less the tab
/// row and the footer, both a fixed length above and below. Half rather than most of it,
/// and against the shared rows rather than against the whole screen, for the same reason
/// the frame is not an overlay: the columns below it are the campaign's members, and a
/// reader inspecting the campaign has to be able to go on seeing what it is made of.
/// Floored, so the odd row goes to the cards.
///
/// Bounded at both ends, and the upper bound is the one that matters:
/// `Constraint::Min(COLUMN_MIN_ROWS)` would take the rows back silently, and the frame's
/// own measurement would then disagree with what is drawn, which is the fault `Chrome`
/// exists to prevent. The lower bound is [`Self::CAMPAIGN_ROWS`], since expanding must
/// never shrink the frame — so on a board too short to divide, `enter` gives the
/// collapsed frame back rather than a height nothing measured.
fn campaign_rows(self, height: u16) -> u16 {
let Some(size) = self.campaign else { return 0 };
let shared = height.saturating_sub(u16::from(self.tabbed) + FOOTER_ROWS);
match size {
FrameSize::Collapsed => Self::CAMPAIGN_ROWS,
FrameSize::Expanded => {
let room = shared.saturating_sub(COLUMN_MIN_ROWS).max(Self::CAMPAIGN_ROWS);
(shared / 2).clamp(Self::CAMPAIGN_ROWS, room)
}
}
}
}
/// The rows the columns are never asked to give up, and the footer's one row.
///
/// Named because two places read each of them: `frame_rows` lays them out and
/// `Chrome::campaign_rows` bounds its share against them. A share computed against a
/// reservation written out by hand is a share that comes to disagree with the layout.
const COLUMN_MIN_ROWS: u16 = 3;
const FOOTER_ROWS: u16 = 1;
/// Where a tab's selection is: among its cards, or on the campaign frame above them.
///
/// The board had no focus beyond a column and a card, and `select_card` clamped at zero. A
@@ -282,6 +334,13 @@ pub struct Tab {
/// the tab was left. A tab showing the whole board has no frame to hold it, which is
/// the invariant `select_campaign` and `reload` keep.
pub focus: Focus,
/// Whether the frame is drawn at its expanded height.
///
/// Per tab like the filter it belongs to. Not per focus: `enter` on the frame is what
/// sets it and `enter` on the frame is what takes it back, so the height survives the
/// selection moving down to the cards — the reader chose a view of the campaign, not a
/// thing about where the highlight is.
pub expanded: bool,
/// First visible line of the frame's prose, counted in wrapped lines the way
/// `Board::offset` counts the overlay's.
///
@@ -302,6 +361,7 @@ impl Tab {
campaigns: Vec::new(),
campaign: None,
focus: Focus::default(),
expanded: false,
frame_offset: 0,
}
}
@@ -671,9 +731,13 @@ impl Board {
/// takes three rows off the columns, and a keypress that scrolled against the old
/// height would put the selection where the next frame does not draw it.
pub fn chrome(&self) -> Chrome {
let tab = self.current();
Chrome {
tabbed: self.tabbed(),
campaign: self.current().campaign.is_some(),
campaign: tab.campaign.is_some().then_some(match tab.expanded {
true => FrameSize::Expanded,
false => FrameSize::Collapsed,
}),
}
}
@@ -751,6 +815,7 @@ impl Board {
// selection, and the next campaign selected starts at the top of its own
// description rather than partway down the last one's.
tab.focus = Focus::Cards;
tab.expanded = false;
tab.frame_offset = 0;
}
tab.columns = retain_campaign(columns, tab.campaign.as_deref());
@@ -1231,6 +1296,7 @@ impl Board {
// the cards and its prose starts at the top — the answer `refresh_detail` gives the
// overlay when the ticket under it changes.
tab.focus = Focus::Cards;
tab.expanded = false;
tab.frame_offset = 0;
// Swallowed for the reason the tick's is not: there is nobody above a keypress to
@@ -1487,6 +1553,44 @@ impl Board {
tab.frame_offset = at.clamp(0, last) as u16;
}
/// What `enter` does: the frame's height on the frame, the overlay on a card.
///
/// The routing is here rather than in the dispatch, the rule `dismiss` and `scroll_page`
/// follow: the arms in `main.rs` are not reachable from a test. It is also what stopped
/// being automatic — `enter` was inert on the frame because `Tab::selected` hands back
/// nothing there and `toggle_detail` had nothing to open, and that answer is now the
/// thing in the way.
pub fn toggle_focused(&mut self, screen: Size) {
match self.current().focus {
Focus::Frame => self.toggle_frame(screen),
Focus::Cards => self.toggle_detail(),
}
}
/// Give the frame's prose half the board, or give the rows back.
///
/// Only from the frame, since it is the frame's own height and `enter` on a card is the
/// overlay's. `q` is not involved: it takes the campaign filter off from either height,
/// because the expanded frame is the frame at its other height and not a layer laid over
/// the board — putting a press between the reader and the board is what a fourth layer
/// would cost, and `enter` already undoes what `enter` did.
///
/// Nor does the selection take it back. Up and down go on moving on and off the frame
/// and leave it where it was, so the columns stay short with the selection on a card.
/// That is the point: the height is a view of the campaign the reader chose.
pub fn toggle_frame(&mut self, screen: Size) {
if self.current().focus != Focus::Frame {
return;
}
self.current_mut().expanded = !self.current().expanded;
// The viewport changed height, so where the reader was may be past the end of it: a
// taller frame has a smaller last offset than a shorter one. A scroll of no pages is
// that clamp and nothing else, which keeps it in the one place it lives — and it
// leaves the reader where they were rather than back at the top of the description.
self.scroll_frame(0, screen);
}
fn refresh_detail(&mut self) {
// A newly selected ticket starts at its top, not partway down where the last one
// was left.
@@ -1898,7 +2002,7 @@ pub fn draw(frame: &mut Frame, board: &Board) {
if chrome.tabbed {
draw_tabs(frame, board, rows[TAB_ROW]);
}
if chrome.campaign {
if chrome.campaign.is_some() {
draw_campaign(frame, board.current(), rows[CAMPAIGN_ROW]);
}
draw_columns(frame, board, rows[BOARD_ROW]);
@@ -1937,9 +2041,9 @@ fn frame_rows(area: Rect, chrome: Chrome) -> std::rc::Rc<[Rect]> {
.direction(Direction::Vertical)
.constraints([
Constraint::Length(u16::from(chrome.tabbed)),
Constraint::Length(chrome.campaign_rows()),
Constraint::Min(3),
Constraint::Length(1),
Constraint::Length(chrome.campaign_rows(area.height)),
Constraint::Min(COLUMN_MIN_ROWS),
Constraint::Length(FOOTER_ROWS),
])
.split(area)
}
@@ -2696,13 +2800,21 @@ fn draw_footer(frame: &mut Frame, board: &Board, area: Rect) {
// do. `↑ frame` is not named on the board for the same reason `c` is dropped from a
// filtered board: the frame is drawn right above the columns and up is the key that
// reaches it, and the row has no cells to spend saying so.
// Which way `enter` will go, since the key is a toggle and the frame is already at one
// of its two heights. Naming it `enter expand` while it collapses would be the fault
// 1b78a24 was, a footer describing a key by what it used to do.
let height = match board.current().expanded {
true => "enter collapse",
false => "enter expand",
};
let keys = match (board.detail.is_some(), board.current().focus) {
(true, _) => format!(
" {tabs}←→↑↓ select pgup/pgdn scroll / search y copy id enter/q close {done} {quit} "
),
(false, Focus::Frame) => {
format!(" {tabs}↓ board pgup/pgdn scroll / search y copy id {done} {quit} ")
}
(false, Focus::Frame) => format!(
" {tabs}↓ board {height} pgup/pgdn scroll / search y copy id {done} {quit} "
),
(false, Focus::Cards) => format!(
" {tabs}←→ column ↑↓ card / search {campaign}y copy id enter detail {done} {quit} "
),
@@ -3256,7 +3368,7 @@ mod tests {
const SCREEN: Size = Size { width: 120, height: 20 };
/// One board, no campaign selected: the chrome most of these tests measure against.
const PLAIN: Chrome = Chrome { tabbed: false, campaign: false };
const PLAIN: Chrome = Chrome { tabbed: false, campaign: None };
/// The rendered buffer as lines of text, escapes and styling dropped.
fn render(board: &Board, width: u16, height: u16) -> Vec<String> {
@@ -7305,8 +7417,11 @@ mod tests {
assert!(board.selected().is_none(), "a card was handed back from the frame");
assert!(!a_card_is_highlighted(&board, 120, 20), "a card is still drawn picked out");
board.toggle_detail();
// `enter` reaches the frame's own height now rather than the overlay, but the
// overlay is still what it does not open: there is no ticket here to open.
board.toggle_focused(SCREEN);
assert!(board.detail.is_none(), "enter opened a ticket nothing was selecting");
board.toggle_focused(SCREEN);
board.select_card(1, SCREEN);
assert!(a_card_is_highlighted(&board, 120, 20), "the highlight did not come back");
@@ -7453,6 +7568,368 @@ mod tests {
std::fs::remove_dir_all(&dir).ok();
}
// ---------------------------------------------------- the frame's two heights --
/// The frame's page indicator, or nothing when it is not drawn.
///
/// Cut out of the bottom border, where it sits between `q board` and the standing, so a
/// test can say the frame repaged without knowing what the numbers should be.
fn frame_indicator(board: &Board, width: u16, height: u16) -> Option<String> {
let rows = frame_lines(board, width, height);
let bottom = rows.last().expect("no frame drawn").clone();
let at = bottom.find("pg ")?;
Some(bottom[at..].split('─').next()?.trim().to_string())
}
/// The rows the frame takes, as the layout gives them out.
fn frame_height(board: &Board, screen: Size) -> u16 {
frame_rows(Rect::new(0, 0, screen.width, screen.height), board.chrome())[CAMPAIGN_ROW]
.height
}
/// `enter` on the frame gives its prose half the board, and `enter` again gives the rows
/// back. A toggle, so the key that expands is the key that collapses.
#[test]
fn enter_expands_the_frame_and_enter_again_gives_the_rows_back() {
let dir = board_dir();
let mut board = frame_board(&dir, 60);
let collapsed = frame_height(&board, SCREEN);
assert_eq!(collapsed, Chrome::CAMPAIGN_ROWS, "the board did not open collapsed");
board.select_card(-1, SCREEN);
board.toggle_focused(SCREEN);
let expanded = frame_height(&board, SCREEN);
assert!(board.current().expanded, "the tab does not think it expanded");
assert!(expanded > collapsed, "the frame did not grow: {expanded} rows");
board.toggle_focused(SCREEN);
assert!(!board.current().expanded, "the tab did not collapse");
assert_eq!(frame_height(&board, SCREEN), collapsed, "the rows did not come back");
std::fs::remove_dir_all(&dir).ok();
}
/// And only from the frame. `enter` on a card is the overlay's, which is what the routing
/// in `toggle_focused` is for.
#[test]
fn enter_on_a_card_opens_the_ticket_rather_than_the_frame() {
let dir = board_dir();
let mut board = frame_board(&dir, 60);
board.toggle_focused(SCREEN);
assert!(board.detail.is_some(), "enter did not open the ticket");
assert!(!board.current().expanded, "enter on a card expanded the frame");
board.toggle_focused(SCREEN);
assert!(board.detail.is_none(), "enter did not close the ticket");
std::fs::remove_dir_all(&dir).ok();
}
/// Half of what the frame and the columns divide, which is the screen less the tab row
/// and the footer. Half rather than most of it: the columns below are the campaign's
/// members, and a reader inspecting the campaign has to go on seeing what it is made of.
#[test]
fn the_expanded_frame_takes_half_of_what_it_shares_with_the_columns() {
let dir = board_dir();
let mut board = frame_board(&dir, 60);
board.select_card(-1, SCREEN);
board.toggle_focused(SCREEN);
let shared = SCREEN.height - FOOTER_ROWS;
assert_eq!(frame_height(&board, SCREEN), shared / 2, "not half of the shared rows");
// The odd row goes to the cards, and the two of them plus the footer are the screen.
let columns = board_area(SCREEN, board.chrome()).height;
assert!(columns >= shared / 2, "the cards did not keep the odd row");
assert_eq!(frame_height(&board, SCREEN) + columns + FOOTER_ROWS, SCREEN.height);
std::fs::remove_dir_all(&dir).ok();
}
/// The share is bounded at both ends, and a sweep is what says so rather than one screen
/// that happens to work. Expanding must never shrink the frame, and must never take rows
/// the columns are reserved: `Constraint::Min` would take them back silently, and the
/// measurement here would then disagree with what is drawn.
#[test]
fn the_expanded_share_is_bounded_at_both_ends() {
for height in 4..=60u16 {
for tabbed in [false, true] {
let chrome = Chrome {
tabbed,
campaign: Some(FrameSize::Expanded),
};
let rows = chrome.campaign_rows(height);
let shared = height.saturating_sub(u16::from(tabbed) + FOOTER_ROWS);
assert!(
rows >= Chrome::CAMPAIGN_ROWS,
"expanding shrank the frame to {rows} rows at height {height}"
);
// Only where the board can hold both. Below that the frame is pinned to its
// collapsed height and the layout is what apportions what is left.
if shared >= Chrome::CAMPAIGN_ROWS + COLUMN_MIN_ROWS {
assert!(
shared - rows >= COLUMN_MIN_ROWS,
"the columns kept {} rows at height {height}",
shared - rows
);
}
}
}
}
/// A board too short to divide gives the collapsed frame back rather than a height
/// nothing measured.
#[test]
fn a_board_too_short_to_divide_stays_at_the_collapsed_height() {
let short = Size { width: 80, height: 10 };
let chrome = Chrome {
tabbed: false,
campaign: Some(FrameSize::Expanded),
};
assert_eq!(chrome.campaign_rows(short.height), Chrome::CAMPAIGN_ROWS);
}
/// Every measurement of the board agrees about the expanded height. That is what `Chrome`
/// is for: a keypress that scrolled against the taller board would put the selection
/// where the next frame does not draw it.
#[test]
fn every_measurement_agrees_about_the_expanded_height() {
let dir = board_dir();
let mut board = frame_board(&dir, 60);
board.select_card(-1, SCREEN);
board.toggle_focused(SCREEN);
let rows = frame_rows(Rect::new(0, 0, SCREEN.width, SCREEN.height), board.chrome());
let total: u16 = rows.iter().map(|row| row.height).sum();
assert_eq!(total, SCREEN.height, "the rows do not add up to the screen");
// The keypress measures the prose off the screen and the draw off the area it is
// given. Two answers here is how a scroll comes to clamp against a frame nobody drew.
assert_eq!(
frame_text_area(SCREEN, board.chrome()),
rows[CAMPAIGN_ROW].inner(Margin::new(1, 1)),
"the keypress and the draw measure different prose"
);
assert_eq!(board_area(SCREEN, board.chrome()), rows[BOARD_ROW]);
assert_eq!(
column_text_height(SCREEN, board.chrome()),
rows[BOARD_ROW].height - 2,
"the cards are laid out against a column of another height"
);
std::fs::remove_dir_all(&dir).ok();
}
/// The scroll keys go on doing what they do, and the indicator repages: the step and the
/// clamp are both measured off the viewport, so both move when the frame does.
#[test]
fn the_scroll_keys_page_through_the_expanded_frame_and_the_indicator_repages() {
let dir = board_dir();
let mut board = frame_board(&dir, 60);
board.select_card(-1, SCREEN);
let collapsed = frame_indicator(&board, 120, 20).expect("no indicator collapsed");
board.toggle_focused(SCREEN);
let expanded = frame_indicator(&board, 120, 20).expect("no indicator expanded");
assert_ne!(collapsed, expanded, "the indicator did not repage: {expanded}");
assert!(expanded.starts_with("pg 1/"), "not on the first page: {expanded}");
board.scroll_page(1, SCREEN);
assert!(board.current().frame_offset > 0, "the expanded frame did not scroll");
let moved = frame_indicator(&board, 120, 20).expect("the indicator went away");
assert!(moved.starts_with("pg 2/"), "the indicator did not follow: {moved}");
// And the clamp is still the wrapped prose, not blank rows past the end of it.
board.scroll_page(40, SCREEN);
let text = frame_text_area(SCREEN, board.chrome());
let last = last_offset(&frame_prose(board.campaign().expect("no campaign")), text);
assert_eq!(board.current().frame_offset, last, "the scroll ran past the description");
std::fs::remove_dir_all(&dir).ok();
}
/// A description that did not fit the collapsed frame and does fit the expanded one
/// spends no indicator and leaves the keys inert, the answer ebad2fa gave for a short
/// description in a collapsed frame.
#[test]
fn a_description_that_fits_the_expanded_frame_spends_no_indicator() {
let dir = board_dir();
let mut board = frame_board(&dir, 5);
board.select_card(-1, SCREEN);
assert!(frame_indicator(&board, 120, 20).is_some(), "five lines fit three rows");
board.toggle_focused(SCREEN);
assert_eq!(frame_indicator(&board, 120, 20), None, "an indicator over prose that fits");
board.scroll_page(1, SCREEN);
assert_eq!(board.current().frame_offset, 0, "prose that fits scrolled");
std::fs::remove_dir_all(&dir).ok();
}
/// A description that fits the collapsed frame expands anyway. A key that worked on one
/// campaign and not the next is worse than one that sometimes has little to reveal, which
/// is the trade the scroll keys already take.
#[test]
fn a_short_description_still_expands_the_frame() {
let dir = board_dir();
let mut board = campaign_board(&dir);
board.select_campaign(Some(V1.to_string()), SCREEN);
board.select_card(-1, SCREEN);
board.toggle_focused(SCREEN);
assert!(board.current().expanded, "a one line description refused to expand");
assert!(
frame_height(&board, SCREEN) > Chrome::CAMPAIGN_ROWS,
"the frame did not grow"
);
std::fs::remove_dir_all(&dir).ok();
}
/// `q` takes the campaign filter off from an expanded frame exactly as it does from a
/// collapsed one. The expanded frame is the frame at its other height, not a layer laid
/// over the board, so it is not a press the reader has to spend on the way out.
#[test]
fn q_takes_the_filter_off_from_an_expanded_frame() {
let dir = board_dir();
let mut board = frame_board(&dir, 60);
board.select_card(-1, SCREEN);
board.toggle_focused(SCREEN);
assert!(board.current().expanded, "nothing expanded");
board.dismiss(SCREEN);
assert_eq!(board.current().campaign, None, "q was spent collapsing the frame");
assert!(!board.current().expanded, "the height outlived the frame");
assert!(!board.should_quit, "the board quit out from under the frame");
let all: usize = board.current().columns.iter().map(|c| c.cards.len()).sum();
assert_eq!(all, 4, "the whole board did not come back");
std::fs::remove_dir_all(&dir).ok();
}
/// Up and down leave the height where it was. The reader chose a view of the campaign;
/// moving the selection off it is not asking for the view back.
#[test]
fn up_and_down_leave_the_frame_at_the_height_it_was() {
let dir = board_dir();
let mut board = frame_board(&dir, 60);
board.select_card(-1, SCREEN);
board.toggle_focused(SCREEN);
let expanded = frame_height(&board, SCREEN);
board.select_card(1, SCREEN);
assert_eq!(board.current().focus, Focus::Cards, "down did not leave the frame");
assert!(board.current().expanded, "down collapsed the frame");
assert_eq!(frame_height(&board, SCREEN), expanded, "the columns took the rows back");
board.select_card(-1, SCREEN);
assert!(board.current().expanded, "up changed the height");
std::fs::remove_dir_all(&dir).ok();
}
/// The footer says which of the two `enter` is about to do, since the key is a toggle and
/// the frame is already at one of its heights. ebad2fa left it out of this row because it
/// did nothing here.
#[test]
fn the_footer_says_which_way_enter_will_go_on_the_frame() {
let dir = board_dir();
let mut board = frame_board(&dir, 60);
board.select_card(-1, SCREEN);
let row = footer(&board, 120, 20);
assert!(row.contains("enter expand"), "enter is not named on the frame:\n{row}");
board.toggle_focused(SCREEN);
let row = footer(&board, 120, 20);
assert!(row.contains("enter collapse"), "enter still offered as expand:\n{row}");
assert!(!row.contains("enter expand"), "the row names it both ways:\n{row}");
std::fs::remove_dir_all(&dir).ok();
}
/// Expanding and collapsing leave the reader where they were rather than at the top. The
/// offset has to be re-clamped as the height changes, since a taller viewport has a
/// smaller last offset than a shorter one.
#[test]
fn expanding_and_collapsing_leave_the_reader_where_they_were() {
let dir = board_dir();
let mut board = frame_board(&dir, 60);
board.select_card(-1, SCREEN);
board.scroll_page(1, SCREEN);
let at = board.current().frame_offset;
assert!(at > 0, "nothing scrolled");
board.toggle_focused(SCREEN);
assert!(board.current().frame_offset > 0, "expanding went back to the top");
// And the stored offset is inside the taller viewport, not left past its end where
// the next pgup would count down from a number the frame never showed.
let text = frame_text_area(SCREEN, board.chrome());
let last = last_offset(&frame_prose(board.campaign().expect("no campaign")), text);
assert!(board.current().frame_offset <= last, "the offset sits past the end");
board.toggle_focused(SCREEN);
assert!(board.current().frame_offset > 0, "collapsing went back to the top");
std::fs::remove_dir_all(&dir).ok();
}
/// The height is the tab's own, beside the filter it belongs to, so switching away and
/// back returns to it.
#[test]
fn the_expanded_frame_is_the_tabs_own() {
let one = board_dir();
let two = board_dir();
write_campaign(&one, V1, "First public release", "v1", &long_description(60));
write_ticket(
&one,
"backlog",
"11111111-0000-4000-8000-000000000000",
"In v1",
&campaign_field(V1),
);
write_ticket(&two, "backlog", "77777777-0000-4000-8000-000000000000", "Elsewhere", "");
let mut board = boards(&[("one", &one), ("two", &two)]);
board.select_campaign(Some(V1.to_string()), SCREEN);
board.select_card(-1, SCREEN);
board.toggle_focused(SCREEN);
assert!(board.current().expanded, "nothing expanded");
board.select_tab(2, SCREEN);
assert!(!board.current().expanded, "the height came across to another tab");
board.select_tab(-2, SCREEN);
assert!(board.current().expanded, "the tab did not keep its height");
std::fs::remove_dir_all(&one).ok();
std::fs::remove_dir_all(&two).ok();
}
/// And selecting another campaign opens its frame collapsed, the answer `select_campaign`
/// already gives the offset and the focus: it is a different description, and a reader
/// who did not ask for half the board should not be given it.
#[test]
fn selecting_another_campaign_opens_its_frame_collapsed() {
let dir = board_dir();
let mut board = frame_board(&dir, 60);
board.select_card(-1, SCREEN);
board.toggle_focused(SCREEN);
board.select_campaign(Some(BEAVER.to_string()), SCREEN);
assert!(!board.current().expanded, "the new campaign opened at half the board");
assert_eq!(frame_height(&board, SCREEN), Chrome::CAMPAIGN_ROWS);
std::fs::remove_dir_all(&dir).ok();
}
/// A campaign that leaves the board takes the frame with it, focus and offset both: the
/// filter goes back to the whole board, and a frame nothing draws must not be holding
/// the selection.