cli/
cli.rs

1extern crate moins;
2extern crate termion;
3
4use io::Result;
5use std::env;
6use std::fs::File;
7use std::io;
8use std::io::prelude::*;
9
10use moins::Color;
11use moins::Moins;
12use moins::PagerOptions;
13use std::collections::HashMap;
14
15// open your cargo lock with the following command :
16// `cargo run --example cli Cargo.lock` and enjoy the colors !
17fn main() -> Result<()> {
18    let args: Vec<String> = env::args().collect();
19
20    let path = if args.len() > 1 {
21        Some(args[1].as_str())
22    } else {
23        None
24    };
25
26    let mut content = String::new();
27
28    let mut file = if let Some(path) = path {
29        File::open(path)?
30    } else {
31        panic!("expected an input file")
32    };
33
34    file.read_to_string(&mut content)?;
35
36    let mut colors = HashMap::new();
37    colors.insert("[[package]]", Color::Blue);
38    colors.insert("dependencies", Color::Magenta);
39    colors.insert("version", Color::LightRed);
40    colors.insert("name", Color::Cyan);
41    colors.insert("metadata", Color::Green);
42
43    let options = PagerOptions {
44        colors,
45        search: false,
46        line_number: false,
47    };
48
49    Moins::run(&mut content, Some(options));
50
51    Ok(())
52}