brain: End history rows with stats and files
5d5d2b2dce4134162cd8d3b2365f07a0ed68124e
Keep the remaining diffstat and changed-file count visible while flexible history metadata truncates to the available width. Assisted-by: Codex:gpt-5.6-sol
1 parent
fd2b8535
crates/brain/src/session.rs
+25 -27
| 11 | 11 | spawn_highlighter, |
|
| 12 | 12 | }; |
|
| 13 | 13 | use rustik_repo::DiffStat; |
|
| 14 | 14 | use rustik_tui::{ |
|
| 15 | 15 | Constraint, Control, Event, Key, Line, List, ListState, Mouse, MouseButton, Rect, ScrollView, |
|
| 16 | - | Size, Style, Table, TableOptions, Terminal, |
|
| 16 | + | Style, Table, TableOptions, Terminal, |
|
| 17 | 17 | }; |
|
| 18 | 18 | use rustik_tui_termion as tui_termion; |
|
| 19 | 19 | ||
| 20 | 20 | use crate::backend::{Backend, Brain, Commit, CommitHunks, FilePatches, HistoryStatus}; |
|
| 21 | 21 | use crate::comments::ReviewComments; |
| 30 | 30 | use commit::{CommitReview, CommitSlot}; |
|
| 31 | 31 | use event::{ContextFetch, Resize, TerminalEvent, Update, context_change}; |
|
| 32 | 32 | use hunk::{CommentEdit, HunkView}; |
|
| 33 | 33 | use status::{ |
|
| 34 | 34 | ActionContext, Chrome, SELECTED_COMMIT_BG, Status, StatusContext, commit_row, |
|
| 35 | - | commit_row_with_author, current_timestamp, viewer_area, |
|
| 35 | + | commit_row_suffix, commit_row_suffix_with_author, commit_table_lines, current_timestamp, |
|
| 36 | + | viewer_area, |
|
| 36 | 37 | }; |
|
| 37 | - | ||
| 38 | 38 | pub(crate) use status::{BRAIN_BADGE_BG, progress_bar}; |
|
| 39 | 39 | ||
| 40 | 40 | /// Terminal backend used by the interactive viewer. |
|
| 41 | 41 | type BrainTerminal = Terminal<tui_termion::TermionBackend<tui_termion::term::TerminalScreen>>; |
|
| 42 | 42 |
| 1094 | 1094 | let now = current_timestamp(); |
|
| 1095 | 1095 | let last = self.commits.len() - 1; |
|
| 1096 | 1096 | self.terminal.draw(|frame| { |
|
| 1097 | 1097 | let (body, chrome_area) = Chrome::areas(frame.area); |
|
| 1098 | 1098 | let cols = ScrollView::body_cols(body); |
|
| 1099 | - | let mut author_table = Table::<10, Line>::new(TableOptions { |
|
| 1099 | + | let mut table = Table::<3, Line>::new(TableOptions { |
|
| 1100 | + | spacing: 2, |
|
| 1101 | + | ..TableOptions::default() |
|
| 1102 | + | }); |
|
| 1103 | + | let mut author_suffix = Table::<6, Line>::new(TableOptions { |
|
| 1104 | + | spacing: 2, |
|
| 1105 | + | ..TableOptions::default() |
|
| 1106 | + | }); |
|
| 1107 | + | let mut suffix = Table::<5, Line>::new(TableOptions { |
|
| 1100 | 1108 | spacing: 2, |
|
| 1101 | 1109 | ..TableOptions::default() |
|
| 1102 | 1110 | }); |
|
| 1103 | 1111 | for (index, slot) in self.commits.iter().enumerate() { |
|
| 1104 | 1112 | let graph = match (index, last) { |
|
| 1105 | - | (0, 0) => "──●", |
|
| 1106 | - | (0, _) => "╭─●", |
|
| 1107 | - | (index, last) if index == last => "╰─●", |
|
| 1108 | - | _ => "├─●", |
|
| 1113 | + | (0, 0) => "──◉︎", |
|
| 1114 | + | (0, _) => "╭─◉︎", |
|
| 1115 | + | (index, last) if index == last => "╰─◉︎", |
|
| 1116 | + | _ => "├─◉︎", |
|
| 1109 | 1117 | }; |
|
| 1110 | - | author_table.push(commit_row_with_author( |
|
| 1111 | - | slot, palette, graph, now, |
|
| 1112 | - | )); |
|
| 1118 | + | table.push(commit_row(slot, graph)); |
|
| 1119 | + | author_suffix.push(commit_row_suffix_with_author(slot, palette, now)); |
|
| 1120 | + | suffix.push(commit_row_suffix(slot, palette, now)); |
|
| 1113 | 1121 | } |
|
| 1114 | - | let rows = if author_table.size(Constraint::UNBOUNDED).cols <= cols { |
|
| 1115 | - | author_table.lines(Constraint::max(Size::new(cols, usize::MAX))) |
|
| 1122 | + | let author_suffix_cols = author_suffix.size(Constraint::UNBOUNDED).cols; |
|
| 1123 | + | let rows = if table.size(Constraint::UNBOUNDED).cols + author_suffix_cols + 2 |
|
| 1124 | + | <= cols |
|
| 1125 | + | { |
|
| 1126 | + | commit_table_lines(&table, &author_suffix, cols) |
|
| 1116 | 1127 | } else { |
|
| 1117 | - | let mut table = Table::<9, Line>::new(TableOptions { |
|
| 1118 | - | spacing: 2, |
|
| 1119 | - | ..TableOptions::default() |
|
| 1120 | - | }); |
|
| 1121 | - | for (index, slot) in self.commits.iter().enumerate() { |
|
| 1122 | - | let graph = match (index, last) { |
|
| 1123 | - | (0, 0) => "──●", |
|
| 1124 | - | (0, _) => "╭─●", |
|
| 1125 | - | (index, last) if index == last => "╰─●", |
|
| 1126 | - | _ => "├─●", |
|
| 1127 | - | }; |
|
| 1128 | - | table.push(commit_row(slot, palette, graph, now)); |
|
| 1129 | - | } |
|
| 1130 | - | table.lines(Constraint::max(Size::new(cols, usize::MAX))) |
|
| 1128 | + | commit_table_lines(&table, &suffix, cols) |
|
| 1131 | 1129 | }; |
|
| 1132 | 1130 | let selected = Style::default().bg(SELECTED_COMMIT_BG); |
|
| 1133 | 1131 | let list = List::new(rows) |
|
| 1134 | 1132 | .selected_styles(selected, selected) |
|
| 1135 | 1133 | .scrollbar(DiffViewer::scrollbar_style()); |
crates/brain/src/session/status.rs
+87 -53
| 350 | 350 | /// Returns the viewer area above the footer chrome. |
|
| 351 | 351 | pub(super) fn viewer_area(area: Rect) -> Rect { |
|
| 352 | 352 | Chrome::areas(area).0 |
|
| 353 | 353 | } |
|
| 354 | 354 | ||
| 355 | - | /// Returns one commit-table row without an author column. |
|
| 356 | - | pub(super) fn commit_row( |
|
| 357 | - | slot: &CommitSlot, |
|
| 358 | - | palette: DiffPalette, |
|
| 359 | - | graph: &str, |
|
| 360 | - | now: u64, |
|
| 361 | - | ) -> [Line; 9] { |
|
| 362 | - | let [graph, id, diffstat, files, status, progress, branches, _, age, summary] = |
|
| 363 | - | commit_row_with_author(slot, palette, graph, now); |
|
| 364 | - | ||
| 355 | + | /// Returns the leading columns for one commit-table row. |
|
| 356 | + | pub(super) fn commit_row(slot: &CommitSlot, graph: &str) -> [Line; 3] { |
|
| 365 | 357 | [ |
|
| 366 | - | graph, id, diffstat, files, status, progress, branches, age, summary, |
|
| 358 | + | Line::new(Label::new(graph).fg(colors::fixed::MUTED)), |
|
| 359 | + | Line::new(Label::new(&slot.commit.id.short()).fg(colors::rgb::ORANGE)), |
|
| 360 | + | Line::new(slot.commit.summary.as_str()), |
|
| 367 | 361 | ] |
|
| 368 | 362 | } |
|
| 369 | 363 | ||
| 370 | - | /// Returns one commit-table row including an author column. |
|
| 371 | - | pub(super) fn commit_row_with_author( |
|
| 364 | + | /// Returns the protected commit columns without an author column. |
|
| 365 | + | pub(super) fn commit_row_suffix(slot: &CommitSlot, palette: DiffPalette, now: u64) -> [Line; 5] { |
|
| 366 | + | let [_, age, branches, files, progress, diffstat] = |
|
| 367 | + | commit_row_suffix_with_author(slot, palette, now); |
|
| 368 | + | ||
| 369 | + | [age, branches, files, progress, diffstat] |
|
| 370 | + | } |
|
| 371 | + | ||
| 372 | + | /// Returns the protected commit columns including an author column. |
|
| 373 | + | pub(super) fn commit_row_suffix_with_author( |
|
| 372 | 374 | slot: &CommitSlot, |
|
| 373 | 375 | palette: DiffPalette, |
|
| 374 | - | graph: &str, |
|
| 375 | 376 | now: u64, |
|
| 376 | - | ) -> [Line; 10] { |
|
| 377 | + | ) -> [Line; 6] { |
|
| 377 | 378 | let stats = slot |
|
| 378 | 379 | .loaded |
|
| 379 | 380 | .as_ref() |
|
| 380 | 381 | .map_or(slot.remaining_stats, CommitReview::remaining_stats); |
|
| 381 | - | let short = slot.commit.id.short(); |
|
| 382 | - | let complete = slot.progress.is_complete(); |
|
| 383 | - | let status = if complete { |
|
| 384 | - | Label::from_char(REVIEWED_MARK).fg(palette.positive_fg) |
|
| 385 | - | } else { |
|
| 386 | - | Label::space() |
|
| 387 | - | }; |
|
| 388 | - | let diffstat = if complete { |
|
| 382 | + | let diffstat = if slot.progress.is_complete() { |
|
| 389 | 383 | Line::blank() |
|
| 390 | 384 | } else { |
|
| 391 | 385 | Line::blank() |
|
| 392 | 386 | .item(Label::new(&format!("+{}", stats.insertions)).fg(palette.positive_fg)) |
|
| 393 | 387 | .item(Label::space()) |
|
| 394 | 388 | .item(Label::new(&format!("-{}", stats.deletions)).fg(palette.negative_fg)) |
|
| 395 | 389 | }; |
|
| 390 | + | let status = if slot.progress.is_complete() { |
|
| 391 | + | Label::from_char(REVIEWED_MARK).fg(palette.positive_fg) |
|
| 392 | + | } else { |
|
| 393 | + | Label::space() |
|
| 394 | + | }; |
|
| 395 | + | let progress = Line::new(status).item(Label::space()).extend(progress_bar( |
|
| 396 | + | slot.progress, |
|
| 397 | + | palette, |
|
| 398 | + | FOOTER_FG, |
|
| 399 | + | )); |
|
| 400 | + | ||
| 396 | 401 | [ |
|
| 397 | - | Line::new(Label::new(graph).fg(colors::fixed::MUTED)), |
|
| 398 | - | Line::new(Label::new(&short).fg(colors::rgb::ORANGE)), |
|
| 399 | - | diffstat, |
|
| 400 | - | Line::new(Label::new(&file_count(stats.files_changed)).fg(FOOTER_FG)), |
|
| 401 | - | Line::new(status), |
|
| 402 | - | progress_bar(slot.progress, palette, FOOTER_FG), |
|
| 403 | - | Line::new(Label::new(&slot.commit.branches.join(", ")).fg(colors::rgb::TEAL)), |
|
| 404 | 402 | Line::new(Label::new(slot.commit.author.as_str()).fg(colors::fixed::MUTED)), |
|
| 405 | 403 | Line::new( |
|
| 406 | 404 | Label::from(relative_time( |
|
| 407 | 405 | slot.commit.recency.seconds.into(), |
|
| 408 | 406 | now.into(), |
|
| 409 | 407 | )) |
|
| 410 | 408 | .fg(colors::fixed::DIM), |
|
| 411 | 409 | ), |
|
| 412 | - | Line::new(slot.commit.summary.as_str()), |
|
| 410 | + | Line::new(Label::new(&slot.commit.branches.join(", ")).fg(colors::rgb::TEAL)), |
|
| 411 | + | Line::new(Label::new(&file_count(stats.files_changed)).fg(FOOTER_FG)), |
|
| 412 | + | progress, |
|
| 413 | + | diffstat, |
|
| 413 | 414 | ] |
|
| 414 | 415 | } |
|
| 415 | 416 | ||
| 417 | + | /// Renders commit rows while reserving the right columns from truncation. |
|
| 418 | + | pub(super) fn commit_table_lines<const W: usize, const S: usize>( |
|
| 419 | + | metadata: &Table<W, Line>, |
|
| 420 | + | suffix: &Table<S, Line>, |
|
| 421 | + | cols: usize, |
|
| 422 | + | ) -> Vec<Line> { |
|
| 423 | + | let suffix_cols = suffix.size(Constraint::UNBOUNDED).cols.min(cols); |
|
| 424 | + | let spacing = cols.saturating_sub(suffix_cols).min(2); |
|
| 425 | + | let metadata_cols = cols - suffix_cols - spacing; |
|
| 426 | + | let metadata = metadata.lines(Constraint::tight(metadata_cols)); |
|
| 427 | + | let suffix = suffix.lines(Constraint::tight(suffix_cols)); |
|
| 428 | + | ||
| 429 | + | metadata |
|
| 430 | + | .into_iter() |
|
| 431 | + | .zip(suffix) |
|
| 432 | + | .map(|(metadata, suffix)| { |
|
| 433 | + | (0..spacing) |
|
| 434 | + | .fold(metadata, |line, _| line.item(Label::space())) |
|
| 435 | + | .extend(suffix) |
|
| 436 | + | }) |
|
| 437 | + | .collect() |
|
| 438 | + | } |
|
| 439 | + | ||
| 416 | 440 | /// Renders one stored comment as a bordered card. |
|
| 417 | 441 | pub(super) fn comment_card_lines(comment: &Comment, selected: bool, cols: usize) -> Vec<Line> { |
|
| 418 | 442 | let border = if selected { |
|
| 419 | 443 | SELECTED_COMMENT_BORDER |
|
| 420 | 444 | } else { |
| 606 | 630 | assert_eq!(buffer.get(79, 0).unwrap().glyph(), " "); |
|
| 607 | 631 | assert_eq!(buffer.get(79, 0).unwrap().style().bg_color(), FOOTER_BG); |
|
| 608 | 632 | } |
|
| 609 | 633 | ||
| 610 | 634 | #[test] |
|
| 611 | - | fn commit_row_keeps_status_and_pointers_before_summary() { |
|
| 635 | + | fn commit_row_reserves_stats_suffix_before_truncating_metadata() { |
|
| 612 | 636 | let now = 2_000_000_000; |
|
| 613 | 637 | let recency = CommitTime { |
|
| 614 | 638 | seconds: now - 3_600, |
|
| 615 | 639 | }; |
|
| 616 | 640 | let stats = DiffStat { |
| 618 | 642 | insertions: 2, |
|
| 619 | 643 | deletions: 3, |
|
| 620 | 644 | }; |
|
| 621 | 645 | let slot = CommitSlot { |
|
| 622 | 646 | commit: Commit { |
|
| 623 | - | id: "0123456789abcdef0123456789abcdef01234567" |
|
| 624 | - | .parse() |
|
| 625 | - | .unwrap(), |
|
| 647 | + | id: "0123456789abcdef0123456789abcdef01234567".parse().unwrap(), |
|
| 626 | 648 | summary: "A commit summary that cannot fit in the remaining width".to_owned(), |
|
| 627 | 649 | author: "Alice".to_owned(), |
|
| 628 | 650 | branches: vec!["main".to_owned()], |
|
| 629 | 651 | recency, |
|
| 630 | 652 | stats, |
|
| 631 | 653 | }, |
|
| 632 | 654 | progress: ReviewProgress { |
|
| 633 | - | accepted: 1, |
|
| 655 | + | accepted: 0, |
|
| 634 | 656 | total: 1, |
|
| 635 | 657 | }, |
|
| 636 | 658 | remaining_stats: stats, |
|
| 637 | 659 | document: None, |
|
| 638 | 660 | identities: None, |
|
| 639 | 661 | loaded: None, |
|
| 640 | 662 | }; |
|
| 641 | - | let mut table = Table::<10, Line>::new(TableOptions { |
|
| 663 | + | let mut table = Table::<3, Line>::new(TableOptions { |
|
| 642 | 664 | spacing: 2, |
|
| 643 | 665 | ..TableOptions::default() |
|
| 644 | 666 | }); |
|
| 645 | - | table.push(commit_row_with_author( |
|
| 667 | + | table.push(commit_row(&slot, "──◉︎")); |
|
| 668 | + | let mut suffix = Table::<6, Line>::new(TableOptions { |
|
| 669 | + | spacing: 2, |
|
| 670 | + | ..TableOptions::default() |
|
| 671 | + | }); |
|
| 672 | + | suffix.push(commit_row_suffix_with_author( |
|
| 646 | 673 | &slot, |
|
| 647 | 674 | DiffPalette::default(), |
|
| 648 | - | "──●", |
|
| 649 | 675 | now as u64, |
|
| 650 | 676 | )); |
|
| 651 | - | let constrained_cols = table.size(Constraint::UNBOUNDED).cols |
|
| 652 | - | - slot.commit.summary.chars().count() |
|
| 653 | - | + 1; |
|
| 654 | - | ||
| 655 | - | let line = table |
|
| 656 | - | .lines(Constraint::tight(constrained_cols)) |
|
| 677 | + | let wide_cols = |
|
| 678 | + | table.size(Constraint::UNBOUNDED).cols + suffix.size(Constraint::UNBOUNDED).cols + 2; |
|
| 679 | + | let wide = commit_table_lines(&table, &suffix, wide_cols) |
|
| 680 | + | .pop() |
|
| 681 | + | .unwrap() |
|
| 682 | + | .to_string(); |
|
| 683 | + | let narrow_cols = wide_cols - slot.commit.summary.chars().count() + 1; |
|
| 684 | + | let narrow = commit_table_lines(&table, &suffix, narrow_cols) |
|
| 657 | 685 | .pop() |
|
| 658 | 686 | .unwrap() |
|
| 659 | 687 | .to_string(); |
|
| 660 | 688 | ||
| 661 | - | assert!(line.contains(REVIEWED_MARK), "line: {line:?}"); |
|
| 662 | - | assert!(line.contains("main"), "line: {line:?}"); |
|
| 663 | - | assert!(!line.contains(&slot.commit.summary), "line: {line:?}"); |
|
| 689 | + | assert!(wide.contains(&slot.commit.summary), "line: {wide:?}"); |
|
| 690 | + | assert!( |
|
| 691 | + | wide.ends_with("1 file ━━━━━━━━ +2 -3"), |
|
| 692 | + | "line: {wide:?}" |
|
| 693 | + | ); |
|
| 694 | + | assert!(narrow.contains("main"), "line: {narrow:?}"); |
|
| 695 | + | assert!( |
|
| 696 | + | narrow.ends_with("1 file ━━━━━━━━ +2 -3"), |
|
| 697 | + | "line: {narrow:?}" |
|
| 698 | + | ); |
|
| 664 | 699 | ||
| 665 | - | let mut hidden = Table::<9, Line>::new(TableOptions { |
|
| 700 | + | let mut hidden = Table::<5, Line>::new(TableOptions { |
|
| 666 | 701 | spacing: 2, |
|
| 667 | 702 | ..TableOptions::default() |
|
| 668 | 703 | }); |
|
| 669 | - | hidden.push(commit_row(&slot, DiffPalette::default(), "──●", now as u64)); |
|
| 704 | + | hidden.push(commit_row_suffix(&slot, DiffPalette::default(), now as u64)); |
|
| 670 | 705 | assert_eq!( |
|
| 671 | - | table.size(Constraint::UNBOUNDED).cols, |
|
| 706 | + | suffix.size(Constraint::UNBOUNDED).cols, |
|
| 672 | 707 | hidden.size(Constraint::UNBOUNDED).cols + "Alice".len() + 2 |
|
| 673 | 708 | ); |
|
| 674 | 709 | assert!( |
|
| 675 | - | !hidden |
|
| 676 | - | .lines(Constraint::UNBOUNDED) |
|
| 710 | + | !commit_table_lines(&table, &hidden, wide_cols) |
|
| 677 | 711 | .pop() |
|
| 678 | 712 | .unwrap() |
|
| 679 | 713 | .to_string() |
|
| 680 | 714 | .contains("Alice") |
|
| 681 | 715 | ); |