mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-19 04:21:06 +00:00
Allow fluent style
This commit is contained in:
parent
f8d0956893
commit
3bacfc5184
@ -4,16 +4,14 @@ use bat::{PrettyPrinter, StyleComponent, StyleComponents};
|
|||||||
use console::Term;
|
use console::Term;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut printer = PrettyPrinter::new();
|
PrettyPrinter::new()
|
||||||
|
|
||||||
printer
|
|
||||||
.term_width(Term::stdout().size().1 as usize)
|
.term_width(Term::stdout().size().1 as usize)
|
||||||
.style_components(StyleComponents::new(&[
|
.style_components(StyleComponents::new(&[
|
||||||
StyleComponent::Header,
|
StyleComponent::Header,
|
||||||
StyleComponent::Grid,
|
StyleComponent::Grid,
|
||||||
StyleComponent::Numbers,
|
StyleComponent::Numbers,
|
||||||
]))
|
]))
|
||||||
.files(std::env::args_os().skip(1));
|
.input_files(std::env::args_os().skip(1))
|
||||||
|
.run()
|
||||||
printer.run().expect("no errors");
|
.expect("no errors");
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,8 @@ use std::ffi::OsStr;
|
|||||||
fn main() {
|
fn main() {
|
||||||
let path_to_this_file = OsStr::new(file!());
|
let path_to_this_file = OsStr::new(file!());
|
||||||
|
|
||||||
let mut printer = PrettyPrinter::new();
|
PrettyPrinter::new()
|
||||||
|
.input_file(path_to_this_file)
|
||||||
printer.file(path_to_this_file);
|
.run()
|
||||||
|
.expect("no errors");
|
||||||
printer.run().expect("no errors");
|
|
||||||
}
|
}
|
||||||
|
@ -33,14 +33,14 @@ impl<'a> PrettyPrinter<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Add a file which should be pretty-printed
|
/// Add a file which should be pretty-printed
|
||||||
pub fn file(&mut self, path: &OsStr) -> &mut Self {
|
pub fn input_file(&mut self, path: &OsStr) -> &mut Self {
|
||||||
self.inputs
|
self.inputs
|
||||||
.push(Input::Ordinary(OrdinaryFile::from_path(path)));
|
.push(Input::Ordinary(OrdinaryFile::from_path(path)));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add multiple files which should be pretty-printed
|
/// Add multiple files which should be pretty-printed
|
||||||
pub fn files<I, P>(&mut self, paths: I) -> &mut Self
|
pub fn input_files<I, P>(&mut self, paths: I) -> &mut Self
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = P>,
|
I: IntoIterator<Item = P>,
|
||||||
P: AsRef<OsStr>,
|
P: AsRef<OsStr>,
|
||||||
@ -52,6 +52,7 @@ impl<'a> PrettyPrinter<'a> {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Specify the syntax file which should be used (default: auto-detect)
|
||||||
pub fn language(&mut self, language: &'a str) -> &mut Self {
|
pub fn language(&mut self, language: &'a str) -> &mut Self {
|
||||||
self.config.language = Some(language);
|
self.config.language = Some(language);
|
||||||
self
|
self
|
||||||
@ -81,7 +82,7 @@ impl<'a> PrettyPrinter<'a> {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Configure style elements (grid, line numbers, ...)
|
/// Configure style elements like grid or line numbers (default: "full" style)
|
||||||
pub fn style_components(&mut self, components: StyleComponents) -> &mut Self {
|
pub fn style_components(&mut self, components: StyleComponents) -> &mut Self {
|
||||||
self.config.style_components = components;
|
self.config.style_components = components;
|
||||||
self
|
self
|
||||||
@ -137,8 +138,14 @@ impl<'a> PrettyPrinter<'a> {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(self) -> Result<bool> {
|
/// Pretty-print all specified inputs. This method will drain all stored inputs.
|
||||||
|
/// If you want to call 'run' multiple times, you have to call the appropriate
|
||||||
|
/// input_* methods again.
|
||||||
|
pub fn run(&mut self) -> Result<bool> {
|
||||||
|
let mut inputs: Vec<Input> = vec![];
|
||||||
|
std::mem::swap(&mut inputs, &mut self.inputs);
|
||||||
|
|
||||||
let controller = Controller::new(&self.config, &self.assets);
|
let controller = Controller::new(&self.config, &self.assets);
|
||||||
controller.run(self.inputs)
|
controller.run(inputs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user