brain: Rename hunk visibility modes

da3ee72c58fe9c0ce156427429f4d7b2cf778590
Describe the visible hunk set as all or pending instead of framing the
mode around accepted hunks.

Assisted-by: Codex:gpt-5.6-sol
Alexis Sellier committed ago 1 parent 136b3f3f
crates/brain/src/review.rs +12 -12
8 8
9 9
use std::collections::BTreeSet;
10 10
11 11
use rustik_diff::HunkId;
12 12
13 -
/// Visibility of accepted hunks in commit diffs.
13 +
/// Set of hunks visible in commit diffs.
14 14
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
15 -
pub enum AcceptedVisibility {
16 -
    /// Hide accepted hunks.
15 +
pub enum HunkVisibility {
16 +
    /// Show only hunks pending acceptance.
17 17
    #[default]
18 -
    Hidden,
19 -
    /// Show accepted hunks.
20 -
    Shown,
18 +
    Pending,
19 +
    /// Show all hunks.
20 +
    All,
21 21
}
22 22
23 -
impl AcceptedVisibility {
24 -
    /// Switches between hidden and shown accepted hunks.
23 +
impl HunkVisibility {
24 +
    /// Switches between pending and all hunks.
25 25
    pub fn toggle(&mut self) {
26 26
        *self = match self {
27 -
            Self::Hidden => Self::Shown,
28 -
            Self::Shown => Self::Hidden,
27 +
            Self::Pending => Self::All,
28 +
            Self::All => Self::Pending,
29 29
        };
30 30
    }
31 31
}
32 32
33 33
/// Visibility of the active file outside its diff hunks.
41 41
}
42 42
43 43
/// Visibility modes reported by the active review view.
44 44
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
45 45
pub struct Visibility {
46 -
    /// Visibility of accepted hunks.
47 -
    pub accepted: AcceptedVisibility,
46 +
    /// Set of hunks visible in the diff.
47 +
    pub hunks: HunkVisibility,
48 48
    /// Visibility of the active file.
49 49
    pub file: FileVisibility,
50 50
}
51 51
52 52
/// Per-hunk acceptance state for one commit.
crates/brain/src/session.rs +10 -10
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;
22 22
use crate::error::Error;
23 -
use crate::review::{AcceptedVisibility, FileVisibility, Visibility};
23 +
use crate::review::{FileVisibility, HunkVisibility, Visibility};
24 24
25 25
mod commit;
26 26
mod event;
27 27
mod hunk;
28 28
mod status;
184 184
        commits: slots,
185 185
        range,
186 186
        history_status,
187 187
        accepted_hunks: Vec::new(),
188 188
        current: 0,
189 -
        accepted_visibility: AcceptedVisibility::default(),
189 +
        hunk_visibility: HunkVisibility::default(),
190 190
        mode,
191 191
        parked: None,
192 192
        list: ListState::new(),
193 193
        options,
194 194
        backend,
253 253
    history_status: Option<HistoryStatus>,
254 254
    /// Hunk acceptances available to undo, in acceptance order.
255 255
    accepted_hunks: Vec<(usize, rustik_diff::HunkId)>,
256 256
    /// Index of the commit currently displayed.
257 257
    current: usize,
258 -
    /// Visibility of accepted hunks across commit viewers.
259 -
    accepted_visibility: AcceptedVisibility,
258 +
    /// Set of hunks visible across commit viewers.
259 +
    hunk_visibility: HunkVisibility,
260 260
    /// Active view: the commit list, the diff, or a hunk's comment box.
261 261
    mode: Mode,
262 262
    /// Hunk view kept alive while another tab is active, for Tab round-trips.
263 263
    parked: Option<Box<HunkView>>,
264 264
    /// Selection and scroll state for the commit-list tab.
402 402
            Event::Key(Key::Char('A')) => {
403 403
                self.toggle_focused_file(area)?;
404 404
                Ok(Control::Redraw)
405 405
            }
406 406
            Event::Key(Key::Char('v')) => {
407 -
                self.accepted_visibility.toggle();
407 +
                self.hunk_visibility.toggle();
408 408
                self.refresh_visibility()?;
409 409
                Ok(Control::Redraw)
410 410
            }
411 411
            Event::Key(Key::Char('j')) => self.apply(DiffAction::NextHunk, area),
412 412
            Event::Key(Key::Char('k')) => self.apply(DiffAction::PreviousHunk, area),
522 522
        } else {
523 523
            self.accept_hunks(BTreeSet::from([(self.current, hunk)]))?;
524 524
            self.accepted_hunks.push((self.current, hunk));
525 525
        }
526 526
        self.reconcile_reviews()?;
527 -
        if !accepted && matches!(self.accepted_visibility, AcceptedVisibility::Hidden) {
527 +
        if !accepted && matches!(self.hunk_visibility, HunkVisibility::Pending) {
528 528
            self.current()?.viewer.apply(DiffAction::NextHunk, area);
529 529
        }
530 530
531 531
        Ok(())
532 532
    }
994 994
    /// Rebuilds the current commit's files to match accepted-hunk visibility.
995 995
    ///
996 996
    /// The original decoded document is kept in `CommitReview::document`; the
997 997
    /// viewer receives a filtered copy when accepted hunks are hidden.
998 998
    fn refresh_visibility(&mut self) -> Result<(), Error> {
999 -
        let accepted_visibility = self.accepted_visibility;
999 +
        let hunk_visibility = self.hunk_visibility;
1000 1000
        let area = viewer_area(self.terminal.area());
1001 1001
        let loaded = self.current()?;
1002 1002
1003 -
        let files: Vec<FileDiff> = if matches!(accepted_visibility, AcceptedVisibility::Shown) {
1003 +
        let files: Vec<FileDiff> = if matches!(hunk_visibility, HunkVisibility::All) {
1004 1004
            loaded.document.files.clone()
1005 1005
        } else {
1006 1006
            loaded
1007 1007
                .document
1008 1008
                .files
1047 1047
1048 1048
    /// Reconciles review state and refreshes the active viewer when needed.
1049 1049
    fn reconcile_reviews(&mut self) -> Result<(), Error> {
1050 1050
        self.reconcile_state();
1051 1051
        self.history_status = None;
1052 -
        if matches!(self.accepted_visibility, AcceptedVisibility::Hidden)
1052 +
        if matches!(self.hunk_visibility, HunkVisibility::Pending)
1053 1053
            && !matches!(self.mode, Mode::Commits)
1054 1054
        {
1055 1055
            self.refresh_visibility()?;
1056 1056
        }
1057 1057
        Ok(())
1275 1275
    }
1276 1276
1277 1277
    /// Returns the footer chrome for the current session mode.
1278 1278
    fn chrome(&self) -> Chrome {
1279 1279
        let visibility = Visibility {
1280 -
            accepted: self.accepted_visibility,
1280 +
            hunks: self.hunk_visibility,
1281 1281
            file: self
1282 1282
                .mode
1283 1283
                .file_visibility(self.commits[self.current].loaded.as_ref()),
1284 1284
        };
1285 1285
        let (context, progress, stats) = if matches!(self.mode, Mode::Commits) {
a.rs +0 -0
crates/brain/src/session/status.rs +7 -7
11 11
    Border, Buffer, Color, Constraint, HStack, Label, Line, Rect, Size, Style, Table, TableOptions,
12 12
    Widget, colors,
13 13
};
14 14
15 15
use crate::comments::Comment;
16 -
use crate::review::{AcceptedVisibility, FileVisibility, Visibility};
16 +
use crate::review::{FileVisibility, HunkVisibility, Visibility};
17 17
18 18
use super::commit::CommitSlot;
19 19
20 20
/// Number of rows used by the status bar.
21 21
const STATUS_ROWS: usize = 1;
47 47
const SELECTED_COMMENT_BORDER: Color = Color::Fixed(239);
48 48
/// Background color for the selected commit, matching the active file row.
49 49
pub(super) const SELECTED_COMMIT_BG: Color = Color::Fixed(235);
50 50
/// Marker shown beside a commit whose hunks have all been accepted: ✔.
51 51
const REVIEWED_MARK: char = '✔';
52 -
/// Marker shown when accepted hunks are visible in the footer: ✔.
53 -
const APPROVED_HUNKS_MODE_ICON: &str = "✔";
52 +
/// Marker highlighted when all hunks are visible in the footer: ✔.
53 +
const ALL_HUNKS_MODE_ICON: &str = "✔";
54 54
/// Marker shown when full-file mode is visible in the footer: ↕.
55 55
const FULL_FILE_MODE_ICON: &str = "↕";
56 56
/// Separator shown between footer status segments: ·.
57 57
const FOOTER_SEPARATOR: &str = " · ";
58 58
/// Marker used when footer text truncates: ….
211 211
            .style(Style::default().bg(FOOTER_BG))
212 212
    }
213 213
214 214
    /// Returns the right status section with review state and diff statistics.
215 215
    fn right_status(&self) -> Line {
216 -
        let accepted_fg = match self.visibility.accepted {
217 -
            AcceptedVisibility::Hidden => FOOTER_FG,
218 -
            AcceptedVisibility::Shown => self.palette.positive_fg,
216 +
        let all_hunks_fg = match self.visibility.hunks {
217 +
            HunkVisibility::Pending => FOOTER_FG,
218 +
            HunkVisibility::All => self.palette.positive_fg,
219 219
        };
220 220
        let full_file_fg = match self.visibility.file {
221 221
            FileVisibility::Context => FOOTER_FG,
222 222
            FileVisibility::Full => FULL_FILE_MODE_FG,
223 223
        };
230 230
                .item(Label::new(&file_count(self.stats.files_changed)).fg(FOOTER_VALUE_FG));
231 231
        }
232 232
233 233
        status
234 234
            .item(Label::new(FOOTER_SEPARATOR).fg(FOOTER_FG))
235 -
            .item(Label::new(APPROVED_HUNKS_MODE_ICON).fg(accepted_fg))
235 +
            .item(Label::new(ALL_HUNKS_MODE_ICON).fg(all_hunks_fg))
236 236
            .item(Label::space())
237 237
            .item(Label::new(FULL_FILE_MODE_ICON).fg(full_file_fg))
238 238
            .style(Style::default().bg(FOOTER_BG))
239 239
    }
240 240
}