grep names each file once with its lines under it, the changes header keeps its position whole, and the bash teardown tests stop flaking on macOS

- grep groups its lines under each file, the layout of rg --heading, rather than repeating the
  path on every line: 9–28% fewer bytes than rg -n on the searches measured. scopes: true labels
  each run of matches with the function or type around it.
- The changes pane's header shortens the path rather than cut its position, and keeps a gap
  before the FILE / DIFF switch.
- The bash teardown tests count a loop still running as a survivor, not one write already under
  way when the kill landed.
This commit is contained in:
Evan Whittaker
2026-10-18 09:18:05 -05:00
parent 7b460ab9c7
commit 933c1195b4
23 changed files with 673 additions and 163 deletions

View File

@@ -19,25 +19,75 @@ use unicode_width::UnicodeWidthStr;
/// there are others and that stepping is a thing you can do, which is what the footer's bracket
/// keys then explain.
pub(super) fn render_header(frame: &mut Frame, area: Rect, app: &App, view: &ChangesView) {
let styles = &app.theme_styles;
let entry = view.current();
let width = usize::from(area.width);
let line = header_line(app, view, area);
frame.render_widget(Paragraph::new(line), Rect { height: 1, ..area });
if area.height > 1 {
frame.render_widget(
Block::default().borders(Borders::TOP).border_style(app.theme_styles.border_muted),
Rect { y: area.y + 1, height: 1, ..area },
);
}
}
let position = match (view.position(), view.files.len()) {
/// Cells kept between the file's details and the FILE / DIFF switch, so its slab never touches them.
const SWITCH_GAP: usize = 2;
/// The least of a path worth showing: below this the position goes before the path does.
const PATH_FLOOR: usize = 8;
/// The header's one line, laid out so it fits: every fixed part is measured first and the path gets
/// what they leave. When even a stub of path will not fit, the position goes whole, never `8 of`.
fn header_line(app: &App, view: &ChangesView, area: Rect) -> Line<'static> {
let width = usize::from(area.width);
let entry = view.current();
let lead = lead_span(app, view, entry);
let details = detail_spans(app, view, entry);
let tabs = match view.changed() {
true => view_tabs(view.view, app),
false => ViewTabs::default(),
};
let mut position = position_label(view);
let fixed = |position: &str| {
let tail = tabs.width() + position_cells(position);
cells(std::slice::from_ref(&lead)) + cells(&details) + tail + SWITCH_GAP
};
if fixed(&position) + PATH_FLOOR > width {
position.clear();
}
// Cut from the left: the tail of a path is the file, which is the thing being named. A file
// outside the project arrives absolute and is said the way a person would say it
let budget = width.saturating_sub(fixed(&position)).max(PATH_FLOOR);
let path = truncate_path_left(&home_relative(&view.path), budget);
let mut spans =
vec![lead, Span::styled(path, app.theme_styles.text.add_modifier(Modifier::BOLD))];
spans.extend(details);
push_tail(&mut spans, (app, area), tabs, position);
Line::from(spans)
}
/// `8 of 14`, or nothing for a single file.
fn position_label(view: &ChangesView) -> String {
match (view.position(), view.files.len()) {
(Some(index), total) if total > 1 => format!("{} of {total}", index + 1),
_ => String::new(),
};
let counts = entry.and_then(count_label).unwrap_or_default();
// Give the path whatever the fixed parts leave, and cut it from the left: the tail of a path
// is the file, which is the thing being named. A file outside the project arrives absolute and
// is said the way a person would say it, which is also what tells the reader at a glance that
// they are not looking at project code.
let reserved = position.chars().count() + counts.chars().count() + 6;
let titled = home_relative(&view.path);
let path = truncate_path_left(&titled, width.saturating_sub(reserved).max(8));
}
}
// A changed file leads with its git letter; any other file with the mark of its language
let lead = match entry {
/// The position's cells with the two that part it from the switch, or none when it is absent.
fn position_cells(position: &str) -> usize {
match position.is_empty() {
true => 0,
false => position.width() + 2,
}
}
fn cells(spans: &[Span<'_>]) -> usize {
spans.iter().map(|span| UnicodeWidthStr::width(span.content.as_ref())).sum()
}
/// A changed file leads with its git letter; any other file with the mark of its language.
fn lead_span(app: &App, view: &ChangesView, entry: Option<&ChangedFile>) -> Span<'static> {
let styles = &app.theme_styles;
match entry {
Some(file) => {
Span::styled(format!("{} ", marker_of(file.status)), status_style(file.status, app))
}
@@ -49,10 +99,13 @@ pub(super) fn render_header(frame: &mut Frame, area: Rect, app: &App, view: &Cha
crate::widgets::language_hue(icon, styles),
)
}
};
let mut spans = vec![lead];
spans.push(Span::styled(path, styles.text.add_modifier(Modifier::BOLD)));
// What the File view is showing: how long it is, and that it was cut short when it was
}
}
/// What follows the path: the File view's length (and that it was cut short), and `+6 −8`.
fn detail_spans(app: &App, view: &ChangesView, entry: Option<&ChangedFile>) -> Vec<Span<'static>> {
let styles = &app.theme_styles;
let mut spans = Vec::new();
if let (PeekView::File, crate::changes::TextLoad::Ready(file)) = (view.view, &view.text) {
let lines = file.text.lines().count();
let mut meta = format!(" {lines} line{}", if lines == 1 { "" } else { "s" });
@@ -66,39 +119,39 @@ pub(super) fn render_header(frame: &mut Frame, area: Rect, app: &App, view: &Cha
spans.push(Span::styled(format!(" +{additions}"), styles.success));
spans.push(Span::styled(format!(" −{deletions}"), styles.error));
}
// A changed file has two faces, and the one not showing is a click away
let tabs = match view.changed() {
true => view_tabs(view.view, app),
false => ViewTabs::default(),
};
let tabs_width: usize = tabs.spans.iter().map(|span| span.content.width()).sum();
let used: usize = spans.iter().map(|span| UnicodeWidthStr::width(span.content.as_ref())).sum();
let tail = tabs_width + position.chars().count() + usize::from(!position.is_empty()) * 2;
if tail > 0 {
let pad = width.saturating_sub(used + tail);
spans.push(Span::raw(" ".repeat(pad)));
let tabs_at = used + pad;
if let Some((start, cells)) = tabs.other {
if let (Ok(x), Ok(cells)) = (u16::try_from(tabs_at + start), u16::try_from(cells)) {
app.hit.borrow_mut().push(
Rect::new(area.x + x, area.y, cells, 1),
MouseTarget::ChangesFooter(ChangesFooterAction::ToggleView),
);
}
}
spans.extend(tabs.spans);
if !position.is_empty() {
spans.push(Span::raw(" "));
spans.push(Span::styled(position, styles.muted));
}
}
spans
}
frame.render_widget(Paragraph::new(Line::from(spans)), Rect { height: 1, ..area });
if area.height > 1 {
frame.render_widget(
Block::default().borders(Borders::TOP).border_style(styles.border_muted),
Rect { y: area.y + 1, height: 1, ..area },
);
/// The switch and the position, pushed to the right edge with at least [`SWITCH_GAP`] before them,
/// and the hidden face of the switch published as the click that flips the view.
fn push_tail(
spans: &mut Vec<Span<'static>>,
(app, area): (&App, Rect),
tabs: ViewTabs,
position: String,
) {
let tail = tabs.width() + position_cells(&position);
if tail == 0 {
return;
}
let used = cells(spans);
let pad = usize::from(area.width).saturating_sub(used + tail).max(SWITCH_GAP);
spans.push(Span::raw(" ".repeat(pad)));
publish_switch(app, area, used + pad, tabs.other);
spans.extend(tabs.spans);
if !position.is_empty() {
spans.push(Span::raw(" "));
spans.push(Span::styled(position, app.theme_styles.muted));
}
}
/// Publishes the switch's hidden face, `other` cells into a switch drawn at column `at`, as the
/// click that flips the view.
fn publish_switch(app: &App, area: Rect, at: usize, other: Option<(usize, usize)>) {
let Some((start, width)) = other else { return };
if let (Ok(x), Ok(width)) = (u16::try_from(at + start), u16::try_from(width)) {
let target = MouseTarget::ChangesFooter(ChangesFooterAction::ToggleView);
app.hit.borrow_mut().push(Rect::new(area.x + x, area.y, width, 1), target);
}
}
@@ -110,6 +163,12 @@ struct ViewTabs {
other: Option<(usize, usize)>,
}
impl ViewTabs {
fn width(&self) -> usize {
cells(&self.spans)
}
}
/// `FILE DIFF`, both cut into badges: the showing face lit, the other on the idle surface.
///
/// Both in capitals and both slabs, so the pair reads as a switch with two positions rather than a
@@ -160,12 +219,6 @@ pub(super) fn sentence(message: &str) -> String {
})
}
/// `+6 −8`, or nothing at all when git could not count (a binary blob).
fn count_label(file: &ChangedFile) -> Option<String> {
let (additions, deletions) = file.additions.zip(file.deletions)?;
Some(format!(" +{additions} −{deletions}"))
}
fn marker_of(status: luxe_core::FileChangeStatus) -> &'static str {
use luxe_core::FileChangeStatus as Status;
match status {

View File

@@ -171,13 +171,13 @@ ChangesWide@100x30: frame=7f799b893667c928 hits=5ebcfa50c83c624f
ChangesWide@64x20: frame=3531cf4c1d3f2402 hits=a39e334a4bdaa029
ChangesNarrow@140x44: frame=4d45021ad9fb0fa7 hits=de2158bdae6d8dfb
ChangesNarrow@100x30: frame=2ee7cc81d7896506 hits=6dca1cfbcba4056a
ChangesNarrow@64x20: frame=903e59bd8b8a62f8 hits=98deec46c37135b8
ChangesNarrow@64x20: frame=b82352043f680144 hits=65afb8e6ea7f4981
ChangesFailed@140x44: frame=b8c525886e754d21 hits=88e878b841c4ee77
ChangesFailed@100x30: frame=aba8595c8158cca4 hits=d3e7f3e0ab644214
ChangesFailed@64x20: frame=69cdcefbe785c866 hits=27476cdcd9937bea
ChangesFailed@64x20: frame=8d0caaba450a4f3a hits=e16f1ab1fbfea007
ChangesExternal@140x44: frame=fc75aaae10ddb262 hits=d5c3115642e748ad
ChangesExternal@100x30: frame=522c8250b0f50ac4 hits=3dd17e6200cfb4b5
ChangesExternal@64x20: frame=a6d2706231364207 hits=6f0e8da295aaa965
ChangesExternal@64x20: frame=d257ba5dbedfc85f hits=a8e0be5b4625e2bc
ChatTools+palette: frame=85cc5ae977de2fa6 hits=ca2a2a735278a5bd
ChatTools+slash: frame=a3ce4c3a7d03f8d0 hits=8adf06de80ecdcb2
ChatTools+mention: frame=33c4a73f189a3dcc hits=c1b8d78b51a767b7
@@ -219,7 +219,7 @@ ChatWideProse searching: frame=1878156c08a54641 hits=00e988aa75182c51
ChatWideProse selecting: frame=8c1edde42c1f3700 hits=bddfef30519a2a3a
ChatWideProse copied: frame=7757bb42f647c93e hits=bddfef30519a2a3a
ChangesWide@180x44: frame=2f39ea02da654a31 hits=e9b01340cccc666e
ChangesNarrow unwrapped: frame=d83dfbbe3d21abf8 hits=29eecb5dbf51e195
ChangesNarrow unwrapped: frame=13da9745cf50215c hits=c84985bf30e3251e
ChangesWide file: frame=4292536a789062da hits=da530d7bf2c94fdf
ChangesWide file cursor: frame=aacfd7dfe8f072f0 hits=6293b97445fe71a6
ChangesWide file unwrapped: frame=cbf79ee6830376c5 hits=316acbdf05625e0b

View File

@@ -517,3 +517,43 @@ fn the_pane_wraps_long_lines_without_being_asked() {
assert!(!clipped.contains(tail), "clipped now: {clipped}");
assert!(clipped.contains('…'), "and marked as clipped: {clipped}");
}
/// The header's position is whole or absent, never `8 of`: the path is what gives way, and a gap
/// always parts the line counts from the FILE / DIFF switch. The path used to be measured against
/// everything but the switch, so the line ran long and lost its last part, the position.
#[test]
fn the_changes_header_keeps_its_position_whole_and_its_switch_apart() {
use luxe_tui::fixture::FixtureScenario::{ChangesNarrow, ChangesWide};
// Below about 128 columns the dock lies over the pane, so narrower widths drop the dock
let wide = [(ChangesWide, 172u16), (ChangesWide, 140)];
for (scenario, width) in wide.into_iter().chain((44..=110).map(|width| (ChangesNarrow, width)))
{
let (buffer, row, text) = changes_header(scenario, width);
let end = text.trim_end();
let cut = [" 8", " 8 o", " 8 of", " 8 of 1"].iter().any(|cut| end.ends_with(cut));
assert!(!cut, "{width}: the position was cut: {text}");
// Plain background in the two cells after the counts, before the FILE slab begins
let counts = column_of(&text, "−9");
let plain = buffer[(counts - 1, row)].bg;
for x in counts + 2..counts + 4 {
assert_eq!(buffer[(x, row)].bg, plain, "{width}: no gap before the switch: {text}");
}
}
// As wide as the guide's shot, the position shows
let wide = changes_header(ChangesWide, 172).2;
assert!(wide.contains("8 of 14"), "{wide}");
}
/// A guide diff scene at `width` columns: the frame, its header row, and that row's text.
fn changes_header(
scenario: luxe_tui::fixture::FixtureScenario,
width: u16,
) -> (ratatui::buffer::Buffer, u16, String) {
let backend = test_backend(width, 50);
let mut app = luxe_tui::fixture::seeded_app("luxe", scenario).expect("the fixture");
app.update(Msg::TerminalResized { width, height: 50 });
let buffer = render_app(&mut app, &backend);
let row = row_containing(&buffer, "DIFF", width, 50);
let text = row_text(&buffer, row, width);
(buffer, row, text)
}