magi-code 0.96.1

Repository-aware CLI coding agent for terminal work
Documentation
use super::{DisplayLine, DisplayRole};

pub(crate) fn render_diff(input: &str) -> Vec<DisplayLine> {
    if input.is_empty() {
        return vec![DisplayLine::from_span("", DisplayRole::DiffContext)];
    }
    input
        .split('\n')
        .map(|line| DisplayLine::from_span(line, classify_diff_line(line)))
        .collect()
}

fn classify_diff_line(line: &str) -> DisplayRole {
    if line.starts_with("diff --git ")
        || line.starts_with("index ")
        || line.starts_with("--- ")
        || line.starts_with("+++ ")
    {
        DisplayRole::DiffFileHeader
    } else if line.starts_with("@@") {
        DisplayRole::DiffHunkHeader
    } else if line.starts_with("\\ No newline at end of file") {
        DisplayRole::DiffMetadata
    } else if line.starts_with('+') {
        DisplayRole::DiffInserted
    } else if line.starts_with('-') {
        DisplayRole::DiffRemoved
    } else if line.starts_with('!') {
        DisplayRole::DiffChanged
    } else {
        DisplayRole::DiffContext
    }
}