mirror of
https://github.com/sharkdp/bat.git
synced 2025-09-09 14:52:25 +01:00
Add 2 examples
This commit is contained in:
committed by
David Peter
parent
2253d07341
commit
1e19404736
33
examples/using_controller.rs
Normal file
33
examples/using_controller.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
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");
|
||||
// add_file("build.rs");
|
||||
|
||||
let print = || Controller::new(&config, &assets).run();
|
||||
print().expect("no error");
|
||||
}
|
||||
|
||||
fn with_header() -> HashSet<OutputComponent> {
|
||||
[OutputComponent::Header, OutputComponent::Grid]
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect()
|
||||
}
|
Reference in New Issue
Block a user