1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-16 18:22:28 +01:00

Initial verison of PrettyPrinter builder

This commit is contained in:
sharkdp
2020-04-21 19:08:19 +02:00
committed by David Peter
parent 319ab779ee
commit 27974616bf
4 changed files with 53 additions and 16 deletions

44
src/pretty_printer.rs Normal file
View File

@@ -0,0 +1,44 @@
use std::ffi::OsStr;
use crate::{
config::{Config, InputFile, OrdinaryFile},
errors::Result,
Controller, HighlightingAssets,
};
pub struct PrettyPrinter<'a> {
config: Config<'a>,
assets: HighlightingAssets,
}
impl<'a> PrettyPrinter<'a> {
pub fn new() -> Self {
let mut config = Config::default();
config.colored_output = true;
config.true_color = true;
PrettyPrinter {
config,
assets: HighlightingAssets::from_binary(),
}
}
pub fn file(&'a mut self, path: &'a OsStr) -> &'a mut Self {
self.config
.files
.push(InputFile::Ordinary(OrdinaryFile::from_path(path)));
self
}
/// Whether or not the output should be colorized (default: true)
pub fn colored_output(&mut self, yes: bool) -> &mut Self {
self.config.colored_output = yes;
self
}
pub fn run(&'a self) -> Result<bool> {
let controller = Controller::new(&self.config, &self.assets);
controller.run()
}
}