fn print_diff_result(
    display_width: usize,
    use_color: bool,
    background: BackgroundColor,
    print_unchanged: bool,
    summary: &DiffResult,
) {
    match (&summary.lhs_src, &summary.rhs_src) {
        (FileContent::Text(lhs_src), FileContent::Text(rhs_src)) => {
            let opposite_to_lhs = opposite_positions(&summary.lhs_positions);
            let opposite_to_rhs = opposite_positions(&summary.rhs_positions);

            let hunks = matched_pos_to_hunks(&summary.lhs_positions, &summary.rhs_positions);
            let hunks = merge_adjacent(
                &hunks,
                &opposite_to_lhs,
                &opposite_to_rhs,
                lhs_src.max_line(),
                rhs_src.max_line(),
            );

            let lang_name = summary.language.clone().unwrap_or_else(|| "Text".into());
            if hunks.is_empty() {
                if print_unchanged {
                    println!(
                        "{}",
                        style::header(&summary.path, 1, 1, &lang_name, use_color, background)
                    );
                    if lang_name == "Text" || summary.lhs_src == summary.rhs_src {
                        // TODO: there are other Text names now, so
                        // they will hit the second case incorrectly.
                        println!("No changes.\n");
                    } else {
                        println!("No syntactic changes.\n");
                    }
                }
                return;
            }

            if env::var("INLINE").is_ok() {
                inline::print(
                    lhs_src,
                    rhs_src,
                    &summary.lhs_positions,
                    &summary.rhs_positions,
                    &hunks,
                    &summary.path,
                    &lang_name,
                    use_color,
                    background,
                );
            } else {
                side_by_side::print(
                    &hunks,
                    display_width,
                    use_color,
                    background,
                    &summary.path,
                    &lang_name,
                    lhs_src,
                    rhs_src,
                    &summary.lhs_positions,
                    &summary.rhs_positions,
                );
            }
        }
        (FileContent::Binary(lhs_bytes), FileContent::Binary(rhs_bytes)) => {
            let changed = lhs_bytes != rhs_bytes;
            if print_unchanged || changed {
                println!(
                    "{}",
                    style::header(&summary.path, 1, 1, "binary", use_color, background)
                );
                if changed {
                    println!("Binary contents changed.");
                } else {
                    println!("No changes.");
                }
            }
        }
        (_, FileContent::Binary(_)) | (FileContent::Binary(_), _) => {
            // We're diffing a binary file against a text file.
            println!(
                "{}",
                style::header(&summary.path, 1, 1, "binary", use_color, background)
            );
            println!("Binary contents changed.");
        }
    }
}
// TODO: factor out a DiffOptions struct.
factor out a DiffOptions struct.
factor out a DiffOptions struct .
fn print_diff_result(
    display_width: usize,
    use_color: bool,
    background: BackgroundColor,
    print_unchanged: bool,
    summary: &DiffResult,
) {
    match (&summary.lhs_src, &summary.rhs_src) {
        (FileContent::Text(lhs_src), FileContent::Text(rhs_src)) => {
            let opposite_to_lhs = opposite_positions(&summary.lhs_positions);
            let opposite_to_rhs = opposite_positions(&summary.rhs_positions);
            let hunks = matched_pos_to_hunks(&summary.lhs_positions, &summary.rhs_positions);
            let hunks = merge_adjacent(
                &hunks,
                &opposite_to_lhs,
                &opposite_to_rhs,
                lhs_src.max_line(),
                rhs_src.max_line(),
            );
            let lang_name = summary.language.clone().unwrap_or_else(|| "Text".into());
            if hunks.is_empty() {
                if print_unchanged {
                    println!(
                        "{}",
                        style::header(&summary.path, 1, 1, &lang_name, use_color, background)
                    );
                    if lang_name == "Text" || summary.lhs_src == summary.rhs_src {
                        // TODO: there are other Text names now, so
                        // they will hit the second case incorrectly.
                        println!("No changes.\n");
                    } else {
                        println!("No syntactic changes.\n");
                    }
                }
                return;
            }
            if env::var("INLINE").is_ok() {
                inline::print(
                    lhs_src,
                    rhs_src,
                    &summary.lhs_positions,
                    &summary.rhs_positions,
                    &hunks,
                    &summary.path,
                    &lang_name,
                    use_color,
                    background,
                );
            } else {
                side_by_side::print(
                    &hunks,
                    display_width,
                    use_color,
                    background,
                    &summary.path,
                    &lang_name,
                    lhs_src,
                    rhs_src,
                    &summary.lhs_positions,
                    &summary.rhs_positions,
                );
            }
        }
        (FileContent::Binary(lhs_bytes), FileContent::Binary(rhs_bytes)) => {
            let changed = lhs_bytes != rhs_bytes;
            if print_unchanged || changed {
                println!(
                    "{}",
                    style::header(&summary.path, 1, 1, "binary", use_color, background)
                );
                if changed {
                    println!("Binary contents changed.");
                } else {
                    println!("No changes.");
                }
            }
        }
        (_, FileContent::Binary(_)) | (FileContent::Binary(_), _) => {
            // We're diffing a binary file against a text file.
            println!(
                "{}",
                style::header(&summary.path, 1, 1, "binary", use_color, background)
            );
            println!("Binary contents changed.");
        }
    }
}
fn print_diff_result ( display_width : usize , use_color : bool , background : BackgroundColor , print_unchanged : bool , summary : & DiffResult , ) { match ( & summary . lhs_src , & summary . rhs_src ) { ( FileContent :: Text ( lhs_src ) , FileContent :: Text ( rhs_src ) ) => { let opposite_to_lhs = opposite_positions ( & summary . lhs_positions ) ; let opposite_to_rhs = opposite_positions ( & summary . rhs_positions ) ; let hunks = matched_pos_to_hunks ( & summary . lhs_positions , & summary . rhs_positions ) ; let hunks = merge_adjacent ( & hunks , & opposite_to_lhs , & opposite_to_rhs , lhs_src . max_line ( ) , rhs_src . max_line ( ) , ) ; let lang_name = summary . language . clone ( ) . unwrap_or_else ( | | " " . into ( ) ) ; if hunks . is_empty ( ) { if print_unchanged { println ! ( " " style header ( summary path 1 1 lang_name use_color background ) ) ; if lang_name == " " || summary . lhs_src == summary . rhs_src { // TODO: there are other Text names now, so // they will hit the second case incorrectly. println ! ( " \n " ) ; } else { println ! ( " \n " ) ; } } return ; } if env :: var ( " " ) . is_ok ( ) { inline :: print ( lhs_src , rhs_src , & summary . lhs_positions , & summary . rhs_positions , & hunks , & summary . path , & lang_name , use_color , background , ) ; } else { side_by_side :: print ( & hunks , display_width , use_color , background , & summary . path , & lang_name , lhs_src , rhs_src , & summary . lhs_positions , & summary . rhs_positions , ) ; } } ( FileContent :: Binary ( lhs_bytes ) , FileContent :: Binary ( rhs_bytes ) ) => { let changed = lhs_bytes != rhs_bytes ; if print_unchanged || changed { println ! ( " " style header ( summary path 1 1 " " use_color background ) ) ; if changed { println ! ( " " ) ; } else { println ! ( " " ) ; } } } ( _ , FileContent :: Binary ( _ ) ) | ( FileContent :: Binary ( _ ) , _ ) => { // We're diffing a binary file against a text file. println ! ( " " style header ( summary path 1 1 " " use_color background ) ) ; println ! ( " " ) ; } } }
TODO: factor out a DiffOptions struct.
TODO : factor out a DiffOptions struct .
display_width
usize
use_color
bool
background
BackgroundColor
print_unchanged
bool
summary
&DiffResult