diff_color/
lib.rs

1//! Color `diff --unified` output.
2//!
3//! # Example
4//!
5//! ```bash
6//! $ diff --unified <(git show 2e60019:README.md) README.md | diff-color
7//! ```
8use colored::Colorize;
9use std::io::{stdin, BufRead, Error};
10use std::result::Result;
11
12pub fn run() -> Result<(), Error> {
13    for line in stdin().lock().lines() {
14        let line = line?;
15
16        if line.starts_with("---") {
17            println!("{}", line.yellow());
18        } else if line.starts_with("+++") {
19            println!("{}", line.yellow());
20        } else if line.starts_with("@@ ") {
21            println!("{}", line.cyan());
22        } else if line.starts_with("+") {
23            println!("{}", line.green());
24        } else if line.starts_with("-") {
25            println!("{}", line.red());
26        } else {
27            println!("{}", line);
28        }
29    }
30
31    Ok(())
32}