diff: Show file collapsed marker in header

ae4230edd626ed15059f27178e6d7633dafcb281
Alexis Sellier committed ago 1 parent 6a26964e
crates/diff/src/viewer.rs +13 -4
11 11
use rustik_highlight as syntax;
12 12
use rustik_tui as tui;
13 13
use tui::{
14 14
    Badge, Buffer, Cell, Color, Constraint, Control, Event, HStack, Key, Label, Line, Mouse,
15 15
    MouseButton, Placement, Rect, Scroll, ScrollView, ScrollbarStyle, Size, Style, Table,
16 -
    TableOptions, Text, VStack, View, Viewport, Widget, colors,
16 +
    TableOptions, Text, TreeStyle, VStack, View, Viewport, Widget, colors,
17 17
};
18 18
19 19
use crate::context::{self, ContextChange, ContextState};
20 20
use crate::highlight::{DiffHighlighter, HighlightKeyInput, HighlightResult};
21 21
use crate::word;
1099 1099
                    diff: None,
1100 1100
                };
1101 1101
            }
1102 1102
            FILE_HEADER_ROW => {
1103 1103
                return RenderRow {
1104 -
                    line: wrap_child(file.header_line(child_cols, self.options.diff_palette)),
1104 +
                    line: wrap_child(file.header_line(
1105 +
                        child_cols,
1106 +
                        collapsed,
1107 +
                        self.options.diff_palette,
1108 +
                    )),
1105 1109
                    diff: None,
1106 1110
                };
1107 1111
            }
1108 1112
            row if row == bottom => {
1109 1113
                return RenderRow {
1703 1707
                Some((hunk, row))
1704 1708
            })
1705 1709
    }
1706 1710
1707 1711
    /// Returns a file header line.
1708 -
    fn header_line(&self, cols: usize, palette: DiffPalette) -> Line {
1712 +
    fn header_line(&self, cols: usize, collapsed: bool, palette: DiffPalette) -> Line {
1709 1713
        let mut left = Line::blank();
1710 -
        left.push(Label::from_char(self.header.kind.marker()).fg(LINE_NUMBER_FG));
1714 +
        let marker = if collapsed {
1715 +
            TreeStyle::DEFAULT.collapsed_marker
1716 +
        } else {
1717 +
            TreeStyle::DEFAULT.expanded_marker
1718 +
        };
1719 +
        left.push(Label::from_char(marker).fg(LINE_NUMBER_FG));
1711 1720
        left.push(Label::space());
1712 1721
        left = left.extend(self.path_line());
1713 1722
1714 1723
        if let Some(badge) = self.badge(palette) {
1715 1724
            left.push(Label::space());
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
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
a.rs +0 -0
a.rs +0 -0
a.rs +0 -0
b.rs +0 -0
crates/diff/tests/golden/bottom_of_file_64x5.txt +1 -1
1 1
╭─────────────────────────────────────────────────────────────╮🮘
2 -
│ ⊙ a.rs                                                +2 -1 │🮘
2 +
│ ▿ a.rs                                                +2 -1 │🮘
3 3
├╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴┤▗
4 4
│ 3    4       tail                                           │▐
5 5
╰─────────────────────────────────────────────────────────────╯▐
crates/diff/tests/golden/collapsed_file_64x6.txt +1 -1
1 1
╭─────────────────────────────────────────────────────────────╮🮘
2 -
│ ⊙ a.rs                                                +2 -1 │🮘
2 +
│ ▹ a.rs                                                +2 -1 │🮘
3 3
╰─────────────────────────────────────────────────────────────╯🮘
4 4
                                                               🮘
5 5
                                                               🮘
6 6
                                                               🮘
crates/diff/tests/golden/expanded_file_card_64x9.txt +1 -1
1 1
╭─────────────────────────────────────────────────────────────╮🮘
2 -
│ ⊙ a.rs                                                +2 -1 │🮘
2 +
│ ▿ a.rs                                                +2 -1 │🮘
3 3
├─────────────────────────────────────────────────────────────┤🮘
4 4
│ 1    1       context                                        │🮘
5 5
│ 2          - old                                            │🮘
6 6
│      2     + new                                            │🮘
7 7
│      3     + extra                                          │🮘
crates/diff/tests/golden/file_kinds_80x24.txt +6 -6
1 1
╭─────────────────────────────────────────────────────────────────────────────╮🮘
2 -
│ ⊕ new.rs  created                                                        +1 │🮘
2 +
│ ▿ new.rs  created                                                        +1 │🮘
3 3
├─────────────────────────────────────────────────────────────────────────────┤🮘
4 4
│      1     + new                                                            │🮘
5 5
╰─────────────────────────────────────────────────────────────────────────────╯🮘
6 6
╭─────────────────────────────────────────────────────────────────────────────╮🮘
7 -
│ ⊖ old.rs  deleted                                                        -1 │🮘
7 +
│ ▿ old.rs  deleted                                                        -1 │🮘
8 8
├─────────────────────────────────────────────────────────────────────────────┤🮘
9 9
│ 1          - old                                                            │🮘
10 10
╰─────────────────────────────────────────────────────────────────────────────╯🮘
11 11
╭─────────────────────────────────────────────────────────────────────────────╮🮘
12 -
│ ↦ from.rs → to.rs  moved                                                    │🮘
12 +
│ ▿ from.rs → to.rs  moved                                                    │🮘
13 13
╰─────────────────────────────────────────────────────────────────────────────╯🮘
14 14
╭─────────────────────────────────────────────────────────────────────────────╮🮘
15 -
│ ⇉ copy.rs → copy2.rs  copied                                                │🮘
15 +
│ ▿ copy.rs → copy2.rs  copied                                                │🮘
16 16
╰─────────────────────────────────────────────────────────────────────────────╯🮘
17 17
╭─────────────────────────────────────────────────────────────────────────────╮🮘
18 -
│ ⊙ mode.sh  mode changed                                                     │🮘
18 +
│ ▿ mode.sh  mode changed                                                     │🮘
19 19
╰─────────────────────────────────────────────────────────────────────────────╯🮘
20 20
╭─────────────────────────────────────────────────────────────────────────────╮🮘
21 -
│ ⊙ image.png  binary                                                         │🮘
21 +
│ ▿ image.png  binary                                                         │🮘
22 22
╰─────────────────────────────────────────────────────────────────────────────╯🮘
23 23
                                                                               🮘
24 24
                                                                               🮘
crates/diff/tests/golden/focused_second_file_64x6.txt +1 -1
1 1
╭─────────────────────────────────────────────────────────────╮🮘
2 -
│ ⊙ b.rs                                                +1 -1 │🮘
2 +
│ ▿ b.rs                                                +1 -1 │🮘
3 3
├─────────────────────────────────────────────────────────────┤🮘
4 4
│ 1    1       keep                                           │▗
5 5
│ 2          - before                                         │▐
6 6
│      2     + after                                          │▝
crates/diff/tests/golden/highlighted_source_64x5.txt +1 -1
1 1
╭─────────────────────────────────────────────────────────────╮▐
2 -
│ ⊙ a.rs                                                +2 -1 │▐
2 +
│ ▿ a.rs                                                +2 -1 │▐
3 3
├─────────────────────────────────────────────────────────────┤▝
4 4
│ 1    1       highlighted context                            │🮘
5 5
│ 2          - old                                            │🮘
crates/diff/tests/golden/multi_hunk_gap_64x12.txt +1 -1
1 1
╭─────────────────────────────────────────────────────────────╮🮘
2 -
│ ⊙ a.rs                                                +2 -2 │🮘
2 +
│ ▿ a.rs                                                +2 -2 │🮘
3 3
├─────────────────────────────────────────────────────────────┤🮘
4 4
│ 1    1       keep                                           │🮘
5 5
│ 2          - old                                            │🮘
6 6
│      2     + new                                            │🮘
7 7
│            ⋮                                                │🮘
crates/diff/tests/golden/narrow_view_14x8.txt +1 -1
1 1
╭───────────╮▐
2 -
│ ⊙ a.rs +2 │▐
2 +
│ ▿ a.rs +2 │▐
3 3
├───────────┤▐
4 4
│ 1    1    │▐
5 5
│ 2         │▐
6 6
│      2    │▐
7 7
│      3    │▐
crates/diff/tests/golden/preamble_and_no_newline_64x17.txt +1 -1
7 7
│                                                             │🮘
8 8
│ Message body text 1.                                        │🮘
9 9
│ Message body text 2.                                        │🮘
10 10
╰─────────────────────────────────────────────────────────────╯🮘
11 11
╭─────────────────────────────────────────────────────────────╮🮘
12 -
│ ⊙ a.rs                                                +1 -1 │🮘
12 +
│ ▿ a.rs                                                +1 -1 │🮘
13 13
├─────────────────────────────────────────────────────────────┤🮘
14 14
│ 1          - old                                            │🮘
15 15
│      1     + new                                            │🮘
16 16
│              \ No newline at end of file                    │🮘
17 17
╰─────────────────────────────────────────────────────────────╯🮘
crates/diff/tests/golden/sticky_header_before_next_file_64x5.txt +1 -1
1 1
╰─────────────────────────────────────────────────────────────╯🮘
2 2
╭─────────────────────────────────────────────────────────────╮🮘
3 -
│ ⊙ b.rs                                                +1 -1 │▗
3 +
│ ▿ b.rs                                                +1 -1 │▗
4 4
├─────────────────────────────────────────────────────────────┤▐
5 5
│ 1    1       keep                                           │🮘
crates/diff/tests/golden/sticky_header_file_end_boundary_64x5.txt +2 -2
1 -
│ ⊙ a.rs                                                +2 -1 │🮘
1 +
│ ▿ a.rs                                                +2 -1 │🮘
2 2
├╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴┤▗
3 3
╰─────────────────────────────────────────────────────────────╯▐
4 4
╭─────────────────────────────────────────────────────────────╮🮘
5 -
│ ⊙ b.rs                                                +1 -1 │🮘
5 +
│ ▿ b.rs                                                +1 -1 │🮘
crates/diff/tests/golden/sticky_header_full_corner_boundary_64x5.txt +1 -1
1 1
╭─────────────────────────────────────────────────────────────╮🮘
2 -
│ ⊙ a.rs                                                +2 -1 │▗
2 +
│ ▿ a.rs                                                +2 -1 │▗
3 3
├╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴┤▐
4 4
╰─────────────────────────────────────────────────────────────╯🮘
5 5
╭─────────────────────────────────────────────────────────────╮🮘
crates/diff/tests/golden/sticky_header_inside_file_64x5.txt +1 -1
1 1
╭─────────────────────────────────────────────────────────────╮🮘
2 -
│ ⊙ a.rs                                                +2 -1 │🮘
2 +
│ ▿ a.rs                                                +2 -1 │🮘
3 3
├╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴┤▗
4 4
│ 3    4       tail                                           │▐
5 5
╰─────────────────────────────────────────────────────────────╯▐
crates/diff/tests/golden/sticky_header_replaces_chrome_64x5.txt +1 -1
1 1
╭─────────────────────────────────────────────────────────────╮🮘
2 -
│ ⊙ a.rs                                                +2 -1 │▗
2 +
│ ▿ a.rs                                                +2 -1 │▗
3 3
├╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴┤▐
4 4
│      3     + extra                                          │▐
5 5
│ 3    4       tail                                           │🮘
crates/diff/tests/golden/sticky_header_starting_64x5.txt +1 -1
1 1
╭─────────────────────────────────────────────────────────────╮▗
2 -
│ ⊙ a.rs                                                +2 -1 │▐
2 +
│ ▿ a.rs                                                +2 -1 │▐
3 3
├╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴┤▐
4 4
│ 2          - old                                            │🮘
5 5
│      2     + new                                            │🮘
crates/diff/tests/golden/wide_file_tree_100x12.txt +2 -2
1 1
                             ╭────────────────────────────────────────────────────────────────────╮▐
2 -
▿ rustik/                    │ ⊙ a.rs                                                       +2 -1 │▐
2 +
▿ rustik/                    │ ▿ a.rs                                                       +2 -1 │▐
3 3
  ⊙ a.rs                     ├────────────────────────────────────────────────────────────────────┤▐
4 4
  ⊙ b.rs                     │ 1    1       context                                               │▐
5 5
                             │ 2          - old                                                   │▐
6 6
                             │      2     + new                                                   │▐
7 7
                             │      3     + extra                                                 │▐
8 8
                             │ 3    4       tail                                                  │▐
9 9
╭──────────────────────────╮ ╰────────────────────────────────────────────────────────────────────╯▐
10 10
│ lines changed  +3 -2     │ ╭────────────────────────────────────────────────────────────────────╮🮘
11 -
│ files changed   2        │ │ ⊙ b.rs                                                       +1 -1 │🮘
11 +
│ files changed   2        │ │ ▿ b.rs                                                       +1 -1 │🮘
12 12
╰──────────────────────────╯ ├────────────────────────────────────────────────────────────────────┤🮘