gitnu 0.1.4

gitnu indexes your git status so you can use numbers instead of filenames.
Documentation
use crate::opts::Opts;
use std::io::Error;

fn has_color(s: &str) -> bool {
    s.contains("\x1b[31m") || s.contains("\x1b[32m")
}

fn print_line(line: &String, count: &mut u16, limit: u16) {
    // only work with colored lines
    if !has_color(&line) {
        println!("{}", line);
        return;
    }
    // line is colored
    *count += 1;
    if *count > limit {
        return;
    }
    if line.starts_with('\t') {
        println!("{}{}", count, line);
    } else {
        println!("{: <4}{}", count, line);
    }
}

// this prints `git status` enumerated
// has nothing to do with data management
pub fn run(opts: Opts) -> Result<(), Error> {
    let mut git = opts.cmd()?;
    git.args(["-c", "status.color=always", "status"]);
    git.stdout(std::process::Stdio::piped()); // capture stdout

    // spawn the process
    let mut git = git.spawn()?;

    // get stdout
    let output = git.stdout.as_mut().ok_or(Error::new(
        std::io::ErrorKind::NotFound,
        "Unable to get stdout",
    ))?;

    // start couting
    let mut count = 0;
    let limit = 50;

    use std::io::{BufRead, BufReader};
    BufReader::new(output)
        .lines()
        .filter_map(|line| line.ok())
        .for_each(|line| print_line(&line, &mut count, limit));

    if count > limit {
        println!("... {} hidden items (gitnu)", count - limit);
    }

    git.wait().map(|v| ())
}