Compare commits

...
3 Commits
Author SHA1 Message Date
Ansho ReiandClaude Opus 5 90b313952b (6d327df) Stop colour escapes leaking into the board's detail view, and bump to 0.8.4
The detail view renders with colour off, because ratatui draws styled spans and
an escape sequence inside a paragraph is not one. `detail_of` asks for that with
`content_trim(&content, false)`. Two paths ignored the argument and asked the
terminal instead.

`colorize_ordered` took no colour parameter at all and called `color_text`,
which is `paint(.., should_use_colors())`, and `content_trim` routes every
Implementation Plan line through it. In the TUI stdout is a terminal, so each
numbered step arrived as ESC[36m, the number, ESC[0m, then the text: exactly the
gap between the number and the step text where the reported artifact showed.
`colorize_line` did the same for a hand-written line inside a Metadata section,
and `colorize_bold` honoured its `enabled` flag on the early return and then
asked `should_use_colors()` again for the bold run, which made the flag a lie in
half the function.

`colorize_ordered` now takes the decision and is private, `content_trim` being
its only caller. `colorize_line` is deleted rather than given the argument: it
was a `pub` alias for `colorize_bold` with one caller, and asking the terminal
was the only thing it added, so `render_metadata_table` calls `colorize_bold`
with the decision it already holds.

Why this shipped, and the reason for the shape of the tests. The guard was an
assert that the detail view holds no escape byte, and it could not fail: a test
binary has no tty, so `should_use_colors()` was false and the leaking branch was
never taken. An absence is now asserted alongside a presence, `content_trim(..,
false)` carries no escape and `content_trim(.., true)` still colours, which pins
the flag as the only thing that decides. A third test scans this file for
`color_text` callers and fails on a new one; it also corrected the assumption
this commit started from, since the remaining caller is `ambiguous` and not
`display_ticket_items`.

The visible symptom is a terminal artifact that no test here can see, since
TestBackend applies cell updates and parses no escapes. What is proven is that
the escapes are gone, and that the CLI still paints its plan numbers cyan in a
pty, which is the condition the leak needed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-21 16:48:01 +02:00
Ansho ReiandClaude Opus 5 7240fc263b Record the overlay title decisions, and bump to 0.8.3
The bump for 0721739, which landed in the commit before this one. The board
section of AGENTS.md gains the two facts the next change to the modal needs:
the name travels beside the text in `Detail` rather than inside it, since
anything in the paragraph scrolls away and `content_trim` drops the heading on
purpose; and `detail_title` cuts the string itself because ratatui truncates a
block title at whatever cell it reaches and would take the id with it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-21 16:42:53 +02:00
Ansho ReiandClaude Opus 5 580e3cf7f0 (0721739) Show the ticket id and title on the detail overlay's border
The modal named nothing. It showed a description, criteria and a metadata table
belonging to a ticket whose title is nowhere in the text, because content_trim
drops the `# ` heading on purpose: `cmd_show` prints it. The card behind the
overlay carries it, but the overlay covers most of the board, and the seven
characters of id in the metadata table were the only thing identifying what was
open.

The id and the name now sit on the block title, `(1111111) · First one`. The id
goes first because that is how every other view addresses a ticket, and both sit
on the border rather than at the head of the paragraph, so reading to the end of
a long ticket cannot carry them off the screen.

The string is cut here rather than left to the renderer, which truncates an
overlong block title at whatever cell it reaches and would take the id with it.
Cut against the inner width, the id survives whole and the name ends in an
ellipsis where it was trimmed.

`Board::detail` is now a `Detail` carrying the title, the id and the text, since
the title has to travel beside the body rather than inside it.

Written in an opencode session, lost from the working tree to a `git checkout
src/tui.rs` that Claude ran to drop a scratch test, and recovered from the
opencode snapshot store. The diff is unchanged from what was written, bar one
rebase conflict where both sides had added a test helper in the same place.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-21 16:41:26 +02:00
5 changed files with 276 additions and 34 deletions
+6 -1
View File
@@ -94,6 +94,8 @@ and this file is for what someone changing worklane's own code needs.
- The draw aligns the focused column again on its own geometry, so a resize between keypress and frame cannot hide the selection, and caps every column against blank space past its last card. The stored value may go stale after a tick shrinks the column; that is fine, because what is drawn is corrected immediately and the next navigation writes the correction back
- Entering another column follows the selection rather than resetting to its top. The card index carries across columns, so a reset would open the column with the highlight below the fold whenever it was — the opposite of the detail view's reset-on-selection-move, where each ticket genuinely starts at its own top. The index is shared and clamps permanently when a shorter column pulls it down, so a column you return to follows the selection to where it now sits rather than holding your old place
- **The footer names only keys that work.** It read `↑↓ scroll` when nothing scrolled at all, which sends the reader looking for their own mistake. A UI that misdescribes itself is worse than one that is merely incomplete
- **The overlay names its ticket on the border, not at the head of the paragraph.** `Board::detail` is a `Detail` carrying the title, the id and the text, because the name has to travel beside the body rather than inside it: `content_trim` drops the `# ` heading on purpose, since `cmd_show` prints it, and anything in the paragraph scrolls away
- `detail_title` cuts the string itself instead of leaving it to ratatui, which truncates an overlong block title at whatever cell it reaches and would take the id with it. Cut against the inner width, so the id survives whole and the name ends in an ellipsis. The id goes first because that is how every other view addresses a ticket
- The detail view renders with colour off. ratatui draws styled spans, so an escape sequence in a paragraph would be printed as literal bytes. `content_trim` and `format_comments_with` take the colour decision for that reason
- Read only. Moving a card by keypress is a follow-up, deliberately kept out until the watch and render loop were solid
- **Done is hidden until `d` asks for it.** Not a new opinion: `ls` already counts done in its summary and leaves it out of the listing. Done only grows, so a quarter of the width was going to the column least often read. The footer carries its count while it is hidden, which is the board's version of that summary line
@@ -115,6 +117,9 @@ and this file is for what someone changing worklane's own code needs.
### Color and Output
- Use `color_text()` for coloured output — it respects `should_use_colors()` (terminal detection), and `paint()` is the same with the decision passed in
- **`color_text()` is for the CLI's own printing only. Anything reachable from `content_trim` takes the decision as an argument and calls `paint()`**, because the board renders with colour off and an escape sequence in a ratatui paragraph is drawn as literal bytes. `nothing_the_body_renders_asks_the_terminal_for_the_colour_decision` scans this file and fails on a new caller; the allowlist is `ambiguous`, which builds a failed-search message for stderr
- A function that takes an `enabled` flag must use it all the way down. `colorize_bold` honoured its flag on the early return and then asked `should_use_colors()` for the bold run, which made the flag a lie in half the function
- **A test that asserts an absence has to be paired with one that asserts the presence.** The guard for this, an assert that the detail view holds no escape byte, could not fail: a test binary has no tty, so `should_use_colors()` was false and the leaking branch was never taken. The pair is now `content_trim(.., false)` has no escape and `content_trim(.., true)` still colours, which pins the flag as the only thing that decides
- **The palette is the `Color` enum, not a string.** `Color::ansi()` gives the CLI its SGR sequence and `From<Color> for ratatui::style::Color` gives the TUI its equivalent, so a colour that exists for one renderer and not the other is a compile error. The stringly-typed version needed a test for exactly that, and a missing entry silently produced an empty prefix, which is how `magenta` came to be undefined
- Reset color with `\x1b[0m` after colored text
- Bold uses `\x1b[1;35m` (magenta bold)
@@ -131,7 +136,7 @@ and this file is for what someone changing worklane's own code needs.
- Grey is indexed colour 8 in the 256-colour form, not SGR 90 or 37. Both of those failed on a real palette: 90 leans on the bright-black slot and 37 can sit on top of the default foreground. `\x1b[38;5;8m` is byte for byte what crossterm emits for ratatui's `Color::DarkGray`, the grey frig and pantop use for dimmed rows
### Code Organization
- Colorization functions (`colorize_line`, `colorize_ordered`, `content_trim_colored`) handle markdown formatting
- Colorization functions (`colorize_ordered`, `colorize_bold`, `content_trim_colored`) handle markdown formatting. `colorize_line` is gone: it was a `pub` alias for `colorize_bold` with one caller, and the only thing it added was asking the terminal
- `show` renders the Metadata section as a two column table via `render_metadata_table`, not line by line. Column width is measured on the raw field names in characters and padding is applied before anything is styled: measuring a coloured string counts its escapes towards its width. `paint()` is `color_text()` with the colour decision passed in, which is what lets a test render both ways in one process
- The title is printed once, by `cmd_show`. `content_trim_colored` skips the `# ` heading in the file content
- Rules under headings are measured on the displayed name in characters, never on the raw line or in bytes
Generated
+1 -1
View File
@@ -1494,7 +1494,7 @@ dependencies = [
[[package]]
name = "worklane"
version = "0.8.2"
version = "0.8.4"
dependencies = [
"anyhow",
"assert_cmd",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "worklane"
version = "0.8.2"
version = "0.8.4"
edition = "2024"
[dependencies]
+171 -22
View File
@@ -30,6 +30,19 @@ pub struct Column {
pub tickets: Vec<TicketItem>,
}
/// What the detail view holds while it is open: the ticket it belongs to, then its
/// body and comments as one plain text.
///
/// The title travels beside the text rather than inside it, because it does not
/// scroll: it names the overlay from the border, where no amount of reading can
/// carry it off the screen.
#[derive(Debug)]
pub struct Detail {
pub title: String,
pub id: String,
pub text: String,
}
/// What is on screen.
pub struct Board {
pub columns: Vec<Column>,
@@ -38,8 +51,8 @@ pub struct Board {
/// First visible line of each column, counted in card lines. Parallel to
/// `columns`, so a tick that reshapes the board resizes it in step.
pub offsets: Vec<u16>,
/// The body and comments of the selected ticket, when the detail view is open.
pub detail: Option<String>,
/// The open detail view, when one is open.
pub detail: Option<Detail>,
/// First visible line of the detail view, counted in wrapped lines.
pub offset: u16,
/// Whether the done column is drawn. Off at startup, and not remembered between
@@ -274,7 +287,7 @@ impl Board {
let text = detail_text_area(Rect::new(0, 0, screen.width, screen.height));
// A screenful less a line, so the eye has something to land on after the jump.
let step = text.height.saturating_sub(1).max(1) as isize;
let last = last_offset(detail, text) as isize;
let last = last_offset(&detail.text, text) as isize;
self.offset = (self.offset as isize + pages.saturating_mul(step)).clamp(0, last) as u16;
}
@@ -289,11 +302,12 @@ impl Board {
}
}
/// The whole ticket as plain text: the body as `show` renders it, then the comments.
/// The ticket as the detail view holds it: its name and short id, then the body as
/// `show` renders it and the comments.
///
/// Plain rather than coloured, since ratatui draws styled spans and an escape sequence
/// in a paragraph would be printed as literal bytes.
fn detail_of(ticket: &TicketItem) -> String {
fn detail_of(ticket: &TicketItem) -> Detail {
let content = std::fs::read_to_string(&ticket.path).unwrap_or_default();
let mut out = content_trim(&content, false);
@@ -307,7 +321,11 @@ fn detail_of(ticket: &TicketItem) -> String {
out.push('\n');
out.push_str(&format_comments_with(&comments, false));
out
Detail {
title: ticket.title.clone(),
id: ticket.id.clone(),
text: out,
}
}
/// A fingerprint of every ticket and comment file: name, length and modified time.
@@ -581,24 +599,24 @@ fn last_offset(detail: &str, text: Rect) -> u16 {
.saturating_sub(text.height)
}
fn draw_detail(frame: &mut Frame, detail: &str, offset: u16, area: Rect) {
fn draw_detail(frame: &mut Frame, detail: &Detail, offset: u16, area: Rect) {
let overlay = detail_overlay(area);
// Clamped here as well as on the keypress: the terminal may have been resized since,
// and a ticket read to its end can grow shorter under a tick.
let offset = offset.min(last_offset(detail, detail_text_area(area)));
let offset = offset.min(last_offset(&detail.text, detail_text_area(area)));
let block = Block::default()
.borders(Borders::ALL)
.border_style(Style::default().fg(Color::Cyan.into()))
.title(Span::styled(
" ticket ",
detail_title(detail, overlay.width),
Style::default().fg(Color::Orange.into()),
));
frame.render_widget(Clear, overlay);
frame.render_widget(
Paragraph::new(detail.to_string())
Paragraph::new(detail.text.to_string())
.block(block)
.wrap(Wrap { trim: false })
.scroll((offset, 0)),
@@ -606,6 +624,35 @@ fn draw_detail(frame: &mut Frame, detail: &str, offset: u16, area: Rect) {
);
}
/// The overlay's title: the short id and the name of the ticket it has open.
///
/// The id goes first because that is how every other view addresses a ticket, and the
/// name after it because that is what the id is shorthand for. Both sit on the border
/// rather than at the head of the paragraph, so reading to the end of a long ticket
/// cannot carry them off the screen.
///
/// The string is cut here rather than left to the renderer, which truncates an
/// overlong title at whatever cell it reaches and would take the id with it. Cut
/// against the inner width — a border column on either side is not the title's to
/// write on — the id survives whole and the name ends in an ellipsis where it was
/// trimmed. On an overlay too narrow for even the id, what fits is what shows.
fn detail_title(detail: &Detail, overlay_width: u16) -> String {
let room = overlay_width.saturating_sub(2) as usize;
let full = format!(" ({}) · {} ", detail.id, detail.title);
if full.chars().count() <= room {
return full;
}
let prefix = format!(" ({}) · ", detail.id);
match room.checked_sub(prefix.chars().count() + 1) {
Some(keep) if keep > 0 => {
let name: String = detail.title.chars().take(keep).collect();
format!("{prefix}{name}…")
}
_ => full.chars().take(room).collect(),
}
}
#[cfg(test)]
mod tests {
use super::*;
@@ -680,6 +727,18 @@ mod tests {
render(board, width, height).pop().expect("no rows rendered")
}
/// The overlay's top border row, where the block title sits.
///
/// Counted in characters rather than bytes: the rows carry multi-byte glyphs.
fn overlay_title_row(lines: &[String], width: u16, height: u16) -> String {
let overlay = detail_overlay(Rect::new(0, 0, width, height));
lines[overlay.y as usize]
.chars()
.skip(overlay.x as usize)
.take(overlay.width as usize)
.collect()
}
#[test]
fn the_board_draws_the_four_statuses_as_columns_once_done_is_shown() {
let dir = board_dir();
@@ -1229,20 +1288,98 @@ mod tests {
assert!(board.detail.is_none());
board.toggle_detail();
let detail = board.detail.clone().expect("no detail");
let detail = board.detail.as_ref().expect("no detail");
assert!(detail.contains("A description."), "{detail}");
assert!(detail.contains("Crit one"), "{detail}");
assert!(detail.contains("A note from elsewhere."), "{detail}");
assert!(detail.contains("bob"), "{detail}");
assert!(detail.text.contains("A description."), "{}", detail.text);
assert!(detail.text.contains("Crit one"), "{}", detail.text);
assert!(detail.text.contains("A note from elsewhere."), "{}", detail.text);
assert!(detail.text.contains("bob"), "{}", detail.text);
// Plain text, since ratatui would print an escape as literal bytes
assert!(!detail.contains('\x1b'), "escapes reached the detail view: {detail:?}");
assert!(
!detail.text.contains('\x1b'),
"escapes reached the detail view: {:?}",
detail.text
);
board.toggle_detail();
assert!(board.detail.is_none());
}
/// The reported bug: the modal showed a description, criteria and a metadata
/// table belonging to a ticket it never named.
#[test]
fn the_detail_view_names_the_ticket_it_has_open() {
let dir = board_dir();
write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "First one", "");
let mut board = Board::new(&dir).unwrap();
board.toggle_detail();
let screen = render(&board, SCREEN.width, SCREEN.height);
let row = overlay_title_row(&screen, SCREEN.width, SCREEN.height);
assert!(row.contains("(1111111)"), "no short id on the border:\n{row}");
assert!(row.contains("First one"), "no title on the border:\n{row}");
// The heading stays out of the text: `show` prints it and here the border
// carries it, so it is on screen once rather than twice.
assert!(
!board.detail.as_ref().unwrap().text.contains("First one"),
"{:?}",
board.detail
);
}
/// Scrolled to the end of a long ticket, the name is still where it started.
#[test]
fn the_name_stays_on_screen_at_the_end_of_a_long_ticket() {
let dir = board_dir();
write_ticket(
&dir,
"backlog",
"11111111-0000-4000-8000-000000000000",
"First one",
&long_section(60),
);
let mut board = Board::new(&dir).unwrap();
board.toggle_detail();
for _ in 0..20 {
board.scroll_detail(1, SCREEN);
}
let screen = render(&board, SCREEN.width, SCREEN.height);
assert!(screen.join("\n").contains("Line 060"), "nothing scrolled:\n{}", screen.join("\n"));
let row = overlay_title_row(&screen, SCREEN.width, SCREEN.height);
assert!(row.contains("(1111111)"), "the id scrolled away:\n{row}");
assert!(row.contains("First one"), "the title scrolled away:\n{row}");
}
/// A title longer than the overlay is cut to the border — corners intact, id
/// whole, ellipsis where the name gave up — not overrun and not dropped whole.
#[test]
fn a_long_title_is_cut_to_the_border_it_sits_on() {
let dir = board_dir();
// Long enough to pass the overlay's inner width many times over, short enough
// that its slug still fits a filename.
let title = format!("Head {} tailmarker", "filler ".repeat(20));
write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", &title, "");
let mut board = Board::new(&dir).unwrap();
board.toggle_detail();
let screen = render(&board, SCREEN.width, SCREEN.height);
let row = overlay_title_row(&screen, SCREEN.width, SCREEN.height);
assert!(row.starts_with('┌'), "the left corner gave way:\n{row}");
assert!(row.ends_with('┐'), "the right corner gave way:\n{row}");
assert!(row.contains("(1111111)"), "the id did not survive the cut:\n{row}");
assert!(row.contains("Head"), "the border was left blank:\n{row}");
assert!(row.contains('…'), "the cut read as a complete title:\n{row}");
assert!(!row.contains("tailmarker"), "the title overran the border:\n{row}");
}
/// A comment added while the detail view is open shows up on the next tick.
#[test]
fn a_tick_picks_up_a_comment_added_under_an_open_detail_view() {
@@ -1252,7 +1389,7 @@ mod tests {
let mut board = Board::new(&dir).unwrap();
board.toggle_detail();
assert!(!board.detail.clone().unwrap().contains("A late note."));
assert!(!board.detail.as_ref().unwrap().text.contains("A late note."));
let comments = dir.join("comments").join(uuid);
std::fs::create_dir_all(&comments).unwrap();
@@ -1263,7 +1400,11 @@ mod tests {
.unwrap();
assert!(board.tick().unwrap(), "the tick saw no change");
assert!(board.detail.clone().unwrap().contains("A late note."), "{:?}", board.detail);
assert!(
board.detail.as_ref().unwrap().text.contains("A late note."),
"{:?}",
board.detail
);
}
#[test]
@@ -1384,13 +1525,21 @@ mod tests {
let mut board = Board::new(&dir).unwrap();
board.toggle_detail();
// By id rather than title: the body leaves the title to the caller that prints
// the heading, so the detail text does not carry it.
assert!(board.detail.clone().unwrap().contains("11111111"), "{:?}", board.detail);
// By id in the text: the heading is stripped from the body, and the title
// travels beside it for the block title instead.
assert!(
board.detail.as_ref().unwrap().text.contains("11111111"),
"{:?}",
board.detail
);
board.select_card(1, SCREEN);
assert_eq!(board.selected().map(|t| t.title.clone()), Some("Beta".to_string()));
assert!(board.detail.clone().unwrap().contains("22222222"), "{:?}", board.detail);
assert!(
board.detail.as_ref().unwrap().text.contains("22222222"),
"{:?}",
board.detail
);
}
/// A newly selected ticket starts at its own top, not where the last one was left.
+97 -9
View File
@@ -403,7 +403,7 @@ pub fn content_trim(content: &str, colored: bool) -> String {
// Implementation Plan - color numbers in cyan
if current_section == "## Implementation Plan" {
result.push_str(&colorize_ordered(line));
result.push_str(&colorize_ordered(line, colored));
result.push('\n');
continue;
}
@@ -454,7 +454,13 @@ pub fn content_trim(content: &str, colored: bool) -> String {
result
}
pub fn colorize_ordered(line: &str) -> String {
/// Colour the `1.` at the head of a numbered line, leaving the rest alone.
///
/// Takes the decision rather than asking for it. Asking is what put `\x1b[36m` and
/// `\x1b[0m` around every Implementation Plan number in the board's detail view,
/// which renders with colour off precisely because a paragraph is not a place an
/// escape sequence can go.
fn colorize_ordered(line: &str, colored: bool) -> String {
if line.chars().next().is_none_or(|c| !c.is_ascii_digit()) {
return line.to_string();
}
@@ -468,7 +474,7 @@ pub fn colorize_ordered(line: &str) -> String {
// still scanning digits
} else if *c == '.' && i + 1 < chars.len() && chars[i + 1] == ' ' {
let number = &line[..i + 1];
result.push_str(&color_text(number, Color::Cyan));
result.push_str(&paint(number, Color::Cyan, colored));
result.push_str(&line[i + 1..]);
return result;
} else {
@@ -558,7 +564,10 @@ fn render_metadata_table(lines: &[&str], colored: bool) -> String {
result.push_str(METADATA_GUTTER);
result.push_str(&metadata_value_cell(name, value, colored));
}
MetadataRow::Other(text) => result.push_str(&colorize_line(text)),
// The decision this row is rendered under, not the one the terminal
// would give: `colorize_line` asked `should_use_colors()` here, which is
// how escapes reached the board's detail view.
MetadataRow::Other(text) => result.push_str(&colorize_bold(text, colored)),
}
result.push('\n');
}
@@ -571,10 +580,6 @@ pub fn is_unknown_value(value: &str) -> bool {
trimmed == "_None_" || trimmed == "_Not set_" || trimmed == "-None-" || trimmed == "-Not set-"
}
pub fn colorize_line(line: &str) -> String {
colorize_bold(line, should_use_colors())
}
/// Replace `**bold**` with colour, or leave the line exactly as it is.
///
/// Taking `enabled` rather than asking makes both paths testable, and the
@@ -600,7 +605,9 @@ fn colorize_bold(line: &str, enabled: bool) -> String {
match (i + 2..chars.len()).find(|&at| is_delimiter(&chars, at)) {
Some(close) => {
let bold: String = chars[i + 2..close].iter().collect();
result.push_str(&color_text(&bold, Color::Magenta));
// `enabled`, not `should_use_colors()`. Asking again here made the
// flag a lie: the early return above respected it and this did not.
result.push_str(&paint(&bold, Color::Magenta, enabled));
i = close + 2;
}
// Unterminated: the rest is literal. The old scan walked off the end
@@ -1552,6 +1559,87 @@ mod tests {
assert_eq!(rendered, format!("Priority {glyph} _Not set_\n"));
}
/// A ticket with the two things that used to leak: a numbered plan, and a
/// hand-written line inside the Metadata section.
const BOTH_LEAKS: &str = "# T\n\n## Implementation Plan\n1. First step\n2. Second step\n\
\n## Metadata\n\n- **ID**: abc\nA **handwritten** note\n";
/// The bug: the board asks for `content_trim(content, false)` because a paragraph
/// is no place for an escape sequence, and two paths asked the terminal instead.
#[test]
fn the_body_carries_no_escape_when_the_colour_is_off() {
let rendered = content_trim(BOTH_LEAKS, false);
assert!(
!rendered.contains('\x1b'),
"an escape survived colour being off: {rendered:?}"
);
// And the content is all still there, in plain form.
assert!(rendered.contains("1. First step"), "{rendered:?}");
assert!(rendered.contains("**handwritten**"), "{rendered:?}");
}
/// The other half of the pair, and the one that makes the first mean something:
/// with the flag on, both paths still colour. Without this, the passing test above
/// could be a colouring path that was simply deleted.
#[test]
fn the_body_colours_the_plan_number_and_a_metadata_note_when_the_colour_is_on() {
let rendered = content_trim(BOTH_LEAKS, true);
assert!(
rendered.contains(&format!("{}1.", Color::Cyan.ansi())),
"the plan number lost its colour: {rendered:?}"
);
assert!(
rendered.contains(&format!("{}handwritten", Color::Magenta.ansi())),
"the bold run lost its colour: {rendered:?}"
);
}
/// The flag has to be the only thing that decides, or the disabled path is just
/// the terminal's answer in disguise — which is why the leak survived a test
/// asserting the detail view holds no escapes. In a test binary there is no tty,
/// so `should_use_colors()` is false and the leaking branch was never taken.
#[test]
fn nothing_the_body_renders_asks_the_terminal_for_the_colour_decision() {
let callers = callers_of_color_text(include_str!("util.rs"));
// `ambiguous` is the one that may: it builds the candidate list for a failed
// search, reaches the user on stderr, and is not reachable from `content_trim`.
assert_eq!(
callers,
vec!["ambiguous".to_string()],
"`color_text` asks `should_use_colors()`. Everything reachable from \
`content_trim` has to take the decision as an argument and pass it to \
`paint` instead, because the board renders with colour off and an escape \
in a ratatui paragraph is drawn as literal bytes. If the new caller really \
is CLI-only, add it here and say why."
);
}
/// Which functions in this file call `color_text`, by name, definitions and the
/// test module excluded.
fn callers_of_color_text(source: &str) -> Vec<String> {
let body = match source.find("\n#[cfg(test)]") {
Some(end) => &source[..end],
None => source,
};
let mut current = String::new();
let mut callers = Vec::new();
for line in body.lines() {
if let Some(rest) = line.strip_prefix("fn ").or_else(|| line.strip_prefix("pub fn ")) {
current = rest.split('(').next().unwrap_or_default().to_string();
continue;
}
if line.contains("color_text(") && !callers.contains(&current) {
callers.push(current.clone());
}
}
callers
}
#[test]
fn a_section_rule_matches_the_width_of_its_name() {
let rendered = content_trim_colored("# T\n\n## Description\nbody\n");