mirror of https://github.com/sharkdp/bat
Simplify 'using_controller' example
parent
310654d49f
commit
b9ce3c248c
@ -0,0 +1,35 @@
|
||||
use bat::{
|
||||
assets::HighlightingAssets,
|
||||
controller::Controller,
|
||||
inputfile::InputFile,
|
||||
style::{OutputComponent, OutputComponents},
|
||||
Config,
|
||||
};
|
||||
use console::Term;
|
||||
use std::process;
|
||||
|
||||
fn main() {
|
||||
let files = std::env::args().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,
|
||||
output_components: OutputComponents::new(&[
|
||||
OutputComponent::Header,
|
||||
OutputComponent::Grid,
|
||||
OutputComponent::Numbers,
|
||||
]),
|
||||
files: files.iter().map(|file| InputFile::Ordinary(file)).collect(),
|
||||
theme: "1337".into(),
|
||||
..Default::default()
|
||||
};
|
||||
let assets = HighlightingAssets::new();
|
||||
|
||||
Controller::new(&config, &assets).run().expect("no errors");
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
use bat::{
|
||||
assets::HighlightingAssets,
|
||||
controller::Controller,
|
||||
inputfile::InputFile,
|
||||
style::{OutputComponent, OutputComponents},
|
||||
Config,
|
||||
};
|
||||
use std::collections::HashSet;
|
||||
|
||||
fn main() {
|
||||
let assets = HighlightingAssets::new();
|
||||
let mut config = Config {
|
||||
term_width: 100, // must be greater than 13 to enable style=numbers
|
||||
colored_output: true,
|
||||
true_color: true,
|
||||
output_components: OutputComponents(with_header()),
|
||||
..Default::default()
|
||||
};
|
||||
let mut add_file = |file: &'static str| config.files.push(InputFile::Ordinary(file));
|
||||
|
||||
add_file("Cargo.toml");
|
||||
|
||||
let print = || Controller::new(&config, &assets).run();
|
||||
print().expect("no error");
|
||||
}
|
||||
|
||||
fn with_header() -> HashSet<OutputComponent> {
|
||||
[OutputComponent::Header, OutputComponent::Grid]
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect()
|
||||
}
|
Loading…
Reference in New Issue