@@ -0,0 +1,44 @@
1+use std::ffi::OsStr;
2+
3+use crate::{
4+ config::{Config, InputFile, OrdinaryFile},
5+ errors::Result,
6+ Controller, HighlightingAssets,
7+};
8+
9+pub struct PrettyPrinter<'a> {
10+ config: Config<'a>,
11+ assets: HighlightingAssets,
12+}
13+
14+impl<'a> PrettyPrinter<'a> {
15+ pub fn new() -> Self {
16+ let mut config = Config::default();
17+
18+ config.colored_output = true;
19+ config.true_color = true;
20+
21+ PrettyPrinter {
22+ config,
23+ assets: HighlightingAssets::from_binary(),
24+ }
25+ }
26+
27+ pub fn file(&'a mut self, path: &'a OsStr) -> &'a mut Self {
28+ self.config
29+ .files
30+ .push(InputFile::Ordinary(OrdinaryFile::from_path(path)));
31+ self
32+ }
33+
34+ /// Whether or not the output should be colorized (default: true)
35+ pub fn colored_output(&mut self, yes: bool) -> &mut Self {
36+ self.config.colored_output = yes;
37+ self
38+ }
39+
40+ pub fn run(&'a self) -> Result<bool> {
41+ let controller = Controller::new(&self.config, &self.assets);
42+ controller.run()
43+ }
44+}