brain: Refine history columns

7fc72fc9009a4bc17813af7fc83882cefd100340
Group commit identity and review progress into compact columns so the
history view remains clear at narrower widths.

Assisted-by: Codex:gpt-5.6-sol
Alexis Sellier committed ago 1 parent a3c96b07
crates/brain/src/session.rs +7 -9
304 304
    backend: &dyn Backend,
305 305
    brain: &Brain,
306 306
    comments: &ReviewComments,
307 307
    palette: rustik_diff::DiffPalette,
308 308
    width: usize,
309 -
) -> Result<Table<9, Line>, Error> {
309 +
) -> Result<Table<7, Line>, Error> {
310 310
    let (mut slots, _) = reviewed_slots(commits, backend, brain, comments)?;
311 311
    slots.reverse();
312 312
    Ok(history_table(&slots, palette, width))
313 313
}
314 314
366 366
/// Builds the commit table shared by interactive and regular history output.
367 367
fn history_table(
368 368
    commits: &[CommitSlot],
369 369
    palette: rustik_diff::DiffPalette,
370 370
    width: usize,
371 -
) -> Table<9, Line> {
371 +
) -> Table<7, Line> {
372 372
    let now = current_timestamp();
373 373
    let largest_change_count = commits
374 374
        .iter()
375 375
        .map(|slot| {
376 376
            let stats = slot.remaining_stats();
378 378
        })
379 379
        .max()
380 380
        .unwrap_or(0);
381 381
    let diffstat_width = (width / HISTORY_DIFFSTAT_WIDTH_DIVISOR)
382 382
        .clamp(HISTORY_DIFFSTAT_MIN_WIDTH, HISTORY_DIFFSTAT_MAX_WIDTH);
383 -
    let mut table = Table::<9, Line>::new(TableOptions {
383 +
    let mut table = Table::<7, Line>::new(TableOptions {
384 384
        spacing: 2,
385 385
        ..TableOptions::default()
386 386
    })
387 387
    .with_layout([
388 -
        Column::auto(),
389 -
        Column::auto(),
390 -
        Column::auto(),
391 388
        Column::flex(1),
392 389
        Column::collapse(2),
393 390
        Column::collapse(3),
394 391
        Column::collapse(1),
395 392
        Column::auto(),
393 +
        Column::auto(),
396 394
        Column::collapse(4),
397 395
    ]);
398 396
    for slot in commits {
399 -
        let [state, id, summary] = commit_row(slot, palette);
400 -
        let [hunks, author, age, branches, comments, diffstat] =
397 +
        let identity = commit_row(slot);
398 +
        let [author, age, branches, comments, progress, diffstat] =
401 399
            commit_row_suffix(slot, palette, now, largest_change_count, diffstat_width);
402 400
        table.push([
403 -
            state, hunks, id, summary, author, age, branches, comments, diffstat,
401 +
            identity, author, age, branches, comments, progress, diffstat,
404 402
        ]);
405 403
    }
406 404
    table
407 405
}
408 406
a.rs +0 -0
crates/brain/src/session/status.rs +90 -49
362 362
/// Returns the viewer area above the footer chrome.
363 363
pub(super) fn viewer_area(area: Rect) -> Rect {
364 364
    Chrome::areas(area).0
365 365
}
366 366
367 -
/// Returns the state and leading columns for one commit-table row.
368 -
pub(super) fn commit_row(slot: &CommitSlot, palette: DiffPalette) -> [Line; 3] {
367 +
/// Returns the identity column for one commit-table row.
368 +
pub(super) fn commit_row(slot: &CommitSlot) -> Line {
369 369
    let dropped = matches!(slot.state, CommitReviewState::Dropped);
370 370
    let row_style = if dropped {
371 371
        Style::default().dim()
372 372
    } else {
373 373
        Style::default()
374 374
    };
375 -
    let state = match slot.state {
376 -
        CommitReviewState::Accepted => Label::from_char(REVIEWED_MARK).fg(palette.positive_fg),
377 -
        CommitReviewState::Rejected => Label::from_char(REJECTED_MARK).fg(palette.negative_fg),
378 -
        CommitReviewState::Dropped => Label::from_char(DROPPED_MARK).fg(colors::fixed::MUTED),
379 -
        CommitReviewState::Pending if slot.accepted_hunks > 0 => {
380 -
            Label::from_char(IN_PROGRESS_MARK).fg(colors::rgb::ORANGE)
381 -
        }
382 -
        CommitReviewState::Pending => Label::from_char(PENDING_MARK).fg(colors::fixed::MUTED),
375 +
    let summary_style = if dropped {
376 +
        Style::default().dim().strikethrough()
377 +
    } else {
378 +
        Style::default()
383 379
    };
384 -
    [
385 -
        Line::new(state).style(row_style),
386 -
        Line::new(Label::new(&slot.commit.id.short()).fg(colors::rgb::ORANGE)).style(row_style),
387 -
        Line::new(slot.commit.summary.as_str()).style(if dropped {
388 -
            Style::default().dim().strikethrough()
389 -
        } else {
390 -
            Style::default()
391 -
        }),
392 -
    ]
380 +
    Line::new(
381 +
        Label::new(&slot.commit.id.short())
382 +
            .fg(colors::rgb::ORANGE)
383 +
            .style(row_style),
384 +
    )
385 +
    .item(Label::space().style(row_style))
386 +
    .item(Label::new(slot.commit.summary.as_str()).style(summary_style))
393 387
}
394 388
395 389
/// Returns the right-side columns for one commit-table row.
396 390
///
397 -
/// Columns are ordered by their wide-layout position: hunk progress, author,
398 -
/// age, branches, comment count, and diffstat.
391 +
/// Columns are ordered by their wide-layout position: author, age, branches,
392 +
/// comment count, hunk progress, and diffstat.
399 393
pub(super) fn commit_row_suffix(
400 394
    slot: &CommitSlot,
401 395
    palette: DiffPalette,
402 396
    now: u64,
403 397
    largest_change_count: usize,
430 424
        .unwrap_or(0);
431 425
    let hunk_color = match (slot.state, percent) {
432 426
        (CommitReviewState::Rejected, _) => palette.negative_fg,
433 427
        (_, 0) => colors::fixed::MUTED,
434 428
        (_, 100) => palette.positive_fg,
435 -
        _ => colors::rgb::ORANGE,
429 +
        _ => colors::rgb::BLUE,
436 430
    };
437 -
    let hunks = Line::new(
438 -
        Label::new(&format!(
439 -
            "{percent}%/{:<HISTORY_HUNK_COUNT_WIDTH$}",
440 -
            slot.total_hunks
441 -
        ))
442 -
        .fg(hunk_color),
443 -
    );
431 +
    let state = match slot.state {
432 +
        CommitReviewState::Accepted => Label::from_char(REVIEWED_MARK).fg(palette.positive_fg),
433 +
        CommitReviewState::Rejected => Label::from_char(REJECTED_MARK).fg(palette.negative_fg),
434 +
        CommitReviewState::Dropped => Label::from_char(DROPPED_MARK).fg(colors::fixed::MUTED),
435 +
        CommitReviewState::Pending if slot.accepted_hunks > 0 => {
436 +
            Label::from_char(IN_PROGRESS_MARK).fg(colors::rgb::BLUE)
437 +
        }
438 +
        CommitReviewState::Pending => Label::from_char(PENDING_MARK).fg(colors::fixed::MUTED),
439 +
    };
440 +
    let progress = Line::new(state)
441 +
        .item(Label::space())
442 +
        .item(Label::new(&format!("{percent}%")).fg(hunk_color))
443 +
        .item(Label::new("/").fg(colors::fixed::MUTED))
444 +
        .item(
445 +
            Label::new(&format!("{:<HISTORY_HUNK_COUNT_WIDTH$}", slot.total_hunks))
446 +
                .fg(colors::fixed::MUTED),
447 +
        )
448 +
        .style(row_style);
444 449
    let comments = slot
445 450
        .loaded
446 451
        .as_ref()
447 452
        .map_or(slot.comment_count, |loaded| loaded.comments.len());
448 453
    [
449 -
        hunks,
450 454
        Line::new(Label::new(slot.commit.author.as_str()).fg(HISTORY_VALUE_FG))
451 455
            .style(identity_style),
452 456
        Line::new(
453 457
            Label::from(relative_time(
454 458
                slot.commit.recency.seconds.into(),
459 463
        .style(identity_style),
460 464
        Line::new(Label::new(&slot.commit.branches.join(", ")).fg(colors::rgb::TEAL))
461 465
            .style(row_style),
462 466
        Line::new(Label::new(&format!("{COMMENT_MARK} {comments:>2}")).fg(colors::fixed::MUTED))
463 467
            .style(row_style),
468 +
        progress,
464 469
        diffstat.style(row_style),
465 470
    ]
466 471
}
467 472
468 473
/// Returns a change count and proportional addition and deletion graph.
747 752
        for (state, marker) in [
748 753
            (CommitReviewState::Accepted, REVIEWED_MARK),
749 754
            (CommitReviewState::Rejected, REJECTED_MARK),
750 755
        ] {
751 756
            slot.state = state;
752 -
            assert_eq!(
753 -
                commit_row(&slot, DiffPalette::default())[0].to_string(),
754 -
                marker.to_string()
755 -
            );
757 +
            let progress = commit_row_suffix(
758 +
                &slot,
759 +
                DiffPalette::default(),
760 +
                now as u64,
761 +
                stats.insertions + stats.deletions,
762 +
                8,
763 +
            )[4]
764 +
            .to_string();
765 +
            assert!(progress.starts_with(marker));
756 766
            assert!(
757 767
                commit_row_suffix(
758 768
                    &slot,
759 769
                    DiffPalette::default(),
760 770
                    now as u64,
765 775
                .is_empty()
766 776
            );
767 777
        }
768 778
769 779
        slot.state = CommitReviewState::Dropped;
770 -
        let [hunks, mut author, mut age, _, comments, diffstat] = commit_row_suffix(
780 +
        let [mut author, mut age, _, comments, progress, diffstat] = commit_row_suffix(
771 781
            &slot,
772 782
            DiffPalette::default(),
773 783
            now as u64,
774 784
            stats.insertions + stats.deletions,
775 785
            8,
776 786
        );
777 -
        assert_eq!(
778 -
            commit_row(&slot, DiffPalette::default())[0].to_string(),
779 -
            DROPPED_MARK.to_string()
780 -
        );
781 787
        assert!(diffstat.to_string().is_empty());
782 -
        assert_eq!(hunks.to_string(), "0%/1   ");
788 +
        assert_eq!(progress.to_string(), format!("{DROPPED_MARK} 0%/1   "));
783 789
        assert_eq!(comments.to_string(), "🗩  3");
784 790
785 791
        let mut author_buffer = Buffer::empty(Rect::new(0, 0, slot.commit.author.len(), 1));
786 792
        let mut age_buffer = Buffer::empty(Rect::new(0, 0, 16, 1));
787 793
        author.render(author_buffer.area(), &mut author_buffer);
798 804
                .dim()
799 805
                .strikethrough()
800 806
        );
801 807
802 808
        slot.state = CommitReviewState::Pending;
803 -
        assert_eq!(
804 -
            commit_row(&slot, DiffPalette::default())[0].to_string(),
805 -
            PENDING_MARK.to_string()
809 +
        assert!(
810 +
            commit_row_suffix(
811 +
                &slot,
812 +
                DiffPalette::default(),
813 +
                now as u64,
814 +
                stats.insertions + stats.deletions,
815 +
                8,
816 +
            )[4]
817 +
            .to_string()
818 +
            .starts_with(PENDING_MARK)
806 819
        );
807 820
        slot.accepted_hunks = 1;
808 -
        assert_eq!(
809 -
            commit_row(&slot, DiffPalette::default())[0].to_string(),
810 -
            IN_PROGRESS_MARK.to_string()
821 +
        assert!(
822 +
            commit_row_suffix(
823 +
                &slot,
824 +
                DiffPalette::default(),
825 +
                now as u64,
826 +
                stats.insertions + stats.deletions,
827 +
                8,
828 +
            )[4]
829 +
            .to_string()
830 +
            .starts_with(IN_PROGRESS_MARK)
811 831
        );
812 832
813 833
        for (state, accepted_hunks, expected_color) in [
814 834
            (CommitReviewState::Pending, 0, colors::fixed::MUTED),
815 -
            (CommitReviewState::Pending, 1, colors::rgb::ORANGE),
835 +
            (CommitReviewState::Pending, 1, colors::rgb::BLUE),
816 836
            (
817 837
                CommitReviewState::Pending,
818 838
                2,
819 839
                DiffPalette::default().positive_fg,
820 840
            ),
825 845
            ),
826 846
        ] {
827 847
            slot.state = state;
828 848
            slot.accepted_hunks = accepted_hunks;
829 849
            slot.total_hunks = 2;
830 -
            let [mut hunks, _, _, _, _, _] = commit_row_suffix(
850 +
            let [_, _, _, _, mut progress, _] = commit_row_suffix(
831 851
                &slot,
832 852
                DiffPalette::default(),
833 853
                now as u64,
834 854
                stats.insertions + stats.deletions,
835 855
                8,
836 856
            );
837 857
            let mut buffer = Buffer::empty(Rect::new(0, 0, 16, 1));
838 -
            hunks.render(buffer.area(), &mut buffer);
858 +
            progress.render(buffer.area(), &mut buffer);
859 +
            let slash_col =
860 +
                2 + format!("{}", accepted_hunks.saturating_mul(100) / slot.total_hunks).len() + 1;
861 +
862 +
            let icon_color = match (state, accepted_hunks) {
863 +
                (CommitReviewState::Rejected, _) => DiffPalette::default().negative_fg,
864 +
                (CommitReviewState::Pending, 0) => colors::fixed::MUTED,
865 +
                (CommitReviewState::Pending, _) => colors::rgb::BLUE,
866 +
                _ => unreachable!(),
867 +
            };
839 868
840 869
            assert_eq!(
841 870
                buffer.get(0, 0).unwrap().style(),
871 +
                Style::default().fg(icon_color)
872 +
            );
873 +
            assert_eq!(
874 +
                buffer.get(2, 0).unwrap().style(),
842 875
                Style::default().fg(expected_color)
843 876
            );
877 +
            assert_eq!(
878 +
                buffer.get(slash_col, 0).unwrap().style(),
879 +
                Style::default().fg(colors::fixed::MUTED)
880 +
            );
881 +
            assert_eq!(
882 +
                buffer.get(slash_col + 1, 0).unwrap().style(),
883 +
                Style::default().fg(colors::fixed::MUTED)
884 +
            );
844 885
        }
845 886
    }
846 887
847 888
    #[test]
848 889
    fn history_diffstat_scales_against_largest_commit() {