rustik-diff 0.3.0

Pure diff viewer and Git diff pager for Rustik.
Documentation
//! Shared diff status presentation primitives.

use rustik_tui::{Color, Label, Line, Style};

use crate::{DiffPalette, ReviewProgress, Stats};

/// Glyph used for filled and empty review progress segments.
pub const REVIEW_PROGRESS_BAR_GLYPH: &str = "━";

/// Returns a recoverable-error status line with the standard error badge.
pub fn recoverable_error(error: &str, value_fg: Color, background: Color) -> Line {
    let message = format!(" {error} ");
    Line::blank()
        .item(Label::new(" error ").style(Style::default().fg(Color::White).bg(Color::Red).bold()))
        .item(Label::new(&message).style(Style::default().fg(value_fg).bg(background)))
        .style(Style::default().bg(background))
}

/// Width of the standard review progress bar.
const REVIEW_PROGRESS_BAR_WIDTH: usize = 8;

/// Returns a compact addition and deletion summary.
pub fn diffstat(stats: Stats, palette: DiffPalette) -> Line {
    Line::blank()
        .item(Label::new(&format!("+{}", stats.insertions)).fg(palette.positive_fg))
        .item(Label::space())
        .item(Label::new(&format!("-{}", stats.deletions)).fg(palette.negative_fg))
}

/// Formats a changed-file count with the correct singular or plural noun.
pub fn file_count(files: usize) -> String {
    let plural = if files == 1 { "" } else { "s" };
    format!("{files} file{plural}")
}

/// Returns the standard fixed-width review progress bar.
pub fn progress_bar(progress: ReviewProgress, palette: DiffPalette, empty_fg: Color) -> Line {
    let filled = progress.filled(REVIEW_PROGRESS_BAR_WIDTH);
    let empty = REVIEW_PROGRESS_BAR_WIDTH - filled;

    Line::blank()
        .item(Label::new(&REVIEW_PROGRESS_BAR_GLYPH.repeat(filled)).fg(palette.positive_fg))
        .item(Label::new(&REVIEW_PROGRESS_BAR_GLYPH.repeat(empty)).fg(empty_fg))
}