brain: Fix a few UI issues

b4dbf0bdb09fde585072bb78cdead6c2f19c4b38
Alexis Sellier committed ago 1 parent 6f044fb9
crates/brain/src/session.rs +12 -1
7 7
use rustik_diff::{
8 8
    ContextChange, DiffAction, DiffDocument, DiffFocus, DiffOptions, DiffViewer, FileDiff,
9 9
    FileTreeMode, HighlightOutput, HighlightRequest, Highlighter, ReviewProgress, ViewChange,
10 10
    spawn_highlighter,
11 11
};
12 +
use rustik_repo::DiffStat;
12 13
use rustik_tui::{Control, Event, Key, Line, List, ListState, Mouse, MouseButton, Rect, Terminal};
13 14
use rustik_tui_termion as tui_termion;
14 15
15 16
use crate::backend::{Backend, Brain, Commit, CommitHunks};
16 17
use crate::comments::ReviewComments;
950 951
            .as_ref()
951 952
            .map_or_else(ReviewProgress::default, |loaded| ReviewProgress {
952 953
                accepted: loaded.review.accepted().len(),
953 954
                total: loaded.file_hunks.values().map(Vec::len).sum(),
954 955
            });
956 +
        let stats = slot.loaded.as_ref().map_or_else(
957 +
            || {
958 +
                if slot.reviewed {
959 +
                    DiffStat::default()
960 +
                } else {
961 +
                    slot.commit.stats
962 +
                }
963 +
            },
964 +
            CommitReview::remaining_stats,
965 +
        );
955 966
        Chrome {
956 967
            status: Status {
957 968
                mode: self.mode.label(),
958 969
                short: slot.commit.id.short(),
959 970
                summary: slot.commit.summary.clone(),
960 971
                progress,
961 -
                stats: slot.commit.stats,
972 +
                stats,
962 973
                palette: self.options.diff_palette,
963 974
                visibility: self.visibility,
964 975
            },
965 976
            actions: self.action_context(),
966 977
        }
crates/brain/src/session/commit.rs +22 -1
4 4
5 5
use rustik_diff::{
6 6
    ContextUpdate, DiffDocument, DiffOptions, DiffViewer, Encode as _, FileDiff, FileId, FileStats,
7 7
    HunkId,
8 8
};
9 -
use rustik_repo::PatchId;
9 +
use rustik_repo::{DiffStat, PatchId};
10 10
use rustik_tui::Rect;
11 11
12 12
use crate::backend::{Brain, Commit};
13 13
use crate::comments::{CommentTarget, Comments, ReviewComments};
14 14
use crate::decorate::Decorations;
53 53
    /// Original diff stats per hunk, used for file-level remaining diffstats.
54 54
    pub(super) hunk_stats: BTreeMap<HunkId, FileStats>,
55 55
}
56 56
57 57
impl CommitReview {
58 +
    /// Returns the combined diffstat of files with hunks that still need review.
59 +
    pub(super) fn remaining_stats(&self) -> DiffStat {
60 +
        let mut total = DiffStat::default();
61 +
62 +
        for hunks in self.file_hunks.values() {
63 +
            let mut remaining = false;
64 +
            for hunk in hunks {
65 +
                if self.review.is_accepted(*hunk) {
66 +
                    continue;
67 +
                }
68 +
                remaining = true;
69 +
                if let Some(stats) = self.hunk_stats.get(hunk) {
70 +
                    total.insertions += stats.additions;
71 +
                    total.deletions += stats.deletions;
72 +
                }
73 +
            }
74 +
            total.files_changed += usize::from(remaining);
75 +
        }
76 +
        total
77 +
    }
78 +
58 79
    /// Decodes one commit's review state from its diff document.
59 80
    ///
60 81
    /// Single-hunk patches and their patch ids are computed here, once, so
61 82
    /// later reconciliations only hash residual hunks and comment lookups can
62 83
    /// match on stable ids.
a.rs +0 -0
crates/brain/src/session/status.rs +1 -1
268 268
                        .style(Style::default().bold()),
269 269
                )
270 270
                .item(Label::space())
271 271
                .item(Label::new(label).fg(ACTION_LABEL_FG));
272 272
        }
273 -
        line.truncated(cols, "")
273 +
        line.truncated(cols.saturating_sub(2), "").inset(cols)
274 274
    }
275 275
}
276 276
277 277
impl Widget for Chrome {
278 278
    fn size(&self, parent: Constraint) -> Size {
crates/diff/src/viewer.rs +1 -3
51 51
const MARKER_WIDTH: usize = 3;
52 52
/// Scrollbar track glyph (distinct from box-drawing borders so the column reads as a track).
53 53
const SCROLLBAR_TRACK: char = '๐Ÿฎ˜';
54 54
/// Scrollbar thumb glyph.
55 55
const SCROLLBAR_THUMB: char = 'โ–';
56 -
/// Scrollbar thumb color, one fixed-color shade darker than dim chrome.
57 -
const SCROLLBAR_THUMB_COLOR: Color = Color::Fixed(237);
58 56
/// File-card divider glyph (used between header/hunks and between hunks).
59 57
const DIVIDER: char = 'โ”€';
60 58
/// Foreground color for neutral file-kind badges such as moved and copied.
61 59
const FILE_KIND_BADGE_FG: Color = colors::rgb::PURPLE;
62 60
/// Dim background for neutral file-kind badges.
2020 2018
2021 2019
    /// Returns the diff scrollbar style.
2022 2020
    fn scrollbar_style() -> ScrollbarStyle {
2023 2021
        ScrollbarStyle::new(
2024 2022
            Cell::new(SCROLLBAR_TRACK, Style::default().fg(colors::FAINT)),
2025 -
            Cell::new(SCROLLBAR_THUMB, Style::default().fg(SCROLLBAR_THUMB_COLOR)),
2023 +
            Cell::new(SCROLLBAR_THUMB, Style::default().fg(colors::FAINT)),
2026 2024
        )
2027 2025
    }
2028 2026
}
2029 2027
2030 2028
impl Widget for DiffViewer {
a.rs +0 -0
a.rs +0 -0
b.rs +0 -0
a.rs +0 -0
a.rs +0 -0
a.rs +0 -0
b.rs +0 -0
crates/diff/tests/golden/sticky_header_before_next_file_64x5.txt +0 -0
src/a.rs +0 -0
src/b.rs +0 -0
README.md +0 -0
src/app/a.rs +0 -0
src/lib/b.rs +0 -0
README.md +0 -0
a.rs +0 -0
b.rs +0 -0
assets/css/style.css +0 -0
assets/css/style.css +0 -0
first.rs +0 -0
second.rs +0 -0
a.rs +0 -0
a.rs +0 -0
a.rs +0 -0
a.rs +0 -0
b.rs +0 -0