.cargo/
crates/
brain/
diff/
benches/
src/
bin/
themes/
viewer/
builtins.rs
13.4 KiB
commit.rs
7.0 KiB
context.rs
10.1 KiB
decode.rs
31.0 KiB
decorate.rs
4.2 KiB
document.rs
24.7 KiB
encode.rs
4.9 KiB
highlight.rs
24.4 KiB
highlighter.rs
12.4 KiB
lib.rs
2.0 KiB
status.rs
2.0 KiB
viewer.rs
183.1 KiB
word.rs
16.8 KiB
tests/
Cargo.toml
867 B
README.md
696 B
files/
highlight/
repo/
signals/
tui/
tui-core/
tui-termion/
tui-widgets/
scripts/
src/
.gitignore
30 B
.gitsigners
198 B
AGENTS.md
1.9 KiB
CONTRIBUTING
1.7 KiB
Cargo.lock
5.4 KiB
Cargo.toml
1.9 KiB
LICENSE
1.1 KiB
README.md
245 B
STYLE
3.7 KiB
clippy.toml
213 B
crates/diff/src/status.rs
raw
| 1 | //! Shared diff status presentation primitives. |
| 2 | |
| 3 | use rustik_tui::{Color, Label, Line, Style}; |
| 4 | |
| 5 | use crate::{DiffPalette, ReviewProgress, Stats}; |
| 6 | |
| 7 | /// Glyph used for filled and empty review progress segments. |
| 8 | pub const REVIEW_PROGRESS_BAR_GLYPH: &str = "━"; |
| 9 | |
| 10 | /// Returns a recoverable-error status line with the standard error badge. |
| 11 | pub fn recoverable_error(error: &str, value_fg: Color, background: Color) -> Line { |
| 12 | let message = format!(" {error} "); |
| 13 | Line::blank() |
| 14 | .item(Label::new(" error ").style(Style::default().fg(Color::White).bg(Color::Red).bold())) |
| 15 | .item(Label::new(&message).style(Style::default().fg(value_fg).bg(background))) |
| 16 | .style(Style::default().bg(background)) |
| 17 | } |
| 18 | |
| 19 | /// Width of the standard review progress bar. |
| 20 | const REVIEW_PROGRESS_BAR_WIDTH: usize = 8; |
| 21 | |
| 22 | /// Returns a compact addition and deletion summary. |
| 23 | pub fn diffstat(stats: Stats, palette: DiffPalette) -> Line { |
| 24 | Line::blank() |
| 25 | .item(Label::new(&format!("+{}", stats.insertions)).fg(palette.positive_fg)) |
| 26 | .item(Label::space()) |
| 27 | .item(Label::new(&format!("-{}", stats.deletions)).fg(palette.negative_fg)) |
| 28 | } |
| 29 | |
| 30 | /// Formats a changed-file count with the correct singular or plural noun. |
| 31 | pub fn file_count(files: usize) -> String { |
| 32 | let plural = if files == 1 { "" } else { "s" }; |
| 33 | format!("{files} file{plural}") |
| 34 | } |
| 35 | |
| 36 | /// Returns the standard fixed-width review progress bar. |
| 37 | pub fn progress_bar(progress: ReviewProgress, palette: DiffPalette, empty_fg: Color) -> Line { |
| 38 | let filled = progress.filled(REVIEW_PROGRESS_BAR_WIDTH); |
| 39 | let empty = REVIEW_PROGRESS_BAR_WIDTH - filled; |
| 40 | |
| 41 | Line::blank() |
| 42 | .item(Label::new(&REVIEW_PROGRESS_BAR_GLYPH.repeat(filled)).fg(palette.positive_fg)) |
| 43 | .item(Label::new(&REVIEW_PROGRESS_BAR_GLYPH.repeat(empty)).fg(empty_fg)) |
| 44 | } |
| 45 | |
| 46 | /// Returns a fully filled standard review progress bar in `fg`. |
| 47 | pub fn full_progress_bar(fg: Color) -> Line { |
| 48 | Line::new(Label::new(&REVIEW_PROGRESS_BAR_GLYPH.repeat(REVIEW_PROGRESS_BAR_WIDTH)).fg(fg)) |
| 49 | } |