summaryrefslogtreecommitdiffstats
path: root/examples/cat.rs
blob: 73d8bb2b24ef9e281241d39b0f809b2a26a65bbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/// A very simple colorized `cat` clone, using `bat` as a library.
/// See `src/bin/bat` for the full `bat` application.
use bat::{
    config::{Config, InputFile, StyleComponent, StyleComponents},
    Controller, HighlightingAssets,
};
use console::Term;
use std::process;

fn main() {
    let files = std::env::args_os().skip(1).collect::<Vec<_>>();

    if files.is_empty() {
        eprintln!("No input files specified");
        process::exit(1);
    }

    let config = Config {
        term_width: Term::stdout().size().1 as usize,
        colored_output: true,
        true_color: true,
        style_components: StyleComponents::new(&[
            StyleComponent::Header,
            StyleComponent::Grid,
            StyleComponent::Numbers,
        ]),
        files: files.iter().map(|file| InputFile::Ordinary(file)).collect(),
        ..Default::default()
    };
    let assets = HighlightingAssets::from_binary();

    Controller::new(&config, &assets).run().expect("no errors");
}