on master help sign in
Add all builder options
commit5e5cb89da6e778bb896b8bcc99caa1e1a65f18f3 authorsharkdp <davidpeter@web.de> dateTue 21 Apr 2020, 20:21 (7 years ago) parent057e4ec
1 file changed+58−3
src/pretty_printer.rs+58−3
src/pretty_printer.rs+58−3
@@ -1,11 +1,17 @@
11use std::ffi::OsStr;
22
33use crate::{
4− config::{Config, InputFile, OrdinaryFile, StyleComponents, WrappingMode},
4+ config::{
5+ Config, HighlightedLineRanges, InputFile, LineRanges, OrdinaryFile, StyleComponents,
6+ SyntaxMapping, WrappingMode,
7+ },
58 errors::Result,
69 Controller, HighlightingAssets,
710};
811
12+#[cfg(feature = "paging")]
13+use crate::config::PagingMode;
14+
915pub struct PrettyPrinter<'a> {
1016 config: Config<'a>,
1117 assets: HighlightingAssets,
@@ -46,6 +52,11 @@ impl<'a> PrettyPrinter<'a> {
4652 self
4753 }
4854
55+ pub fn language(&mut self, language: &'a str) -> &mut Self {
56+ self.config.language = Some(language);
57+ self
58+ }
59+
4960 /// The character width of the terminal (default: unlimited)
5061 pub fn term_width(&mut self, width: usize) -> &mut Self {
5162 self.config.term_width = width;
@@ -77,8 +88,52 @@ impl<'a> PrettyPrinter<'a> {
7788 }
7889
7990 /// Text wrapping mode (default: do not wrap)
80− pub fn wrapping_mode(&mut self, wrapping_mode: WrappingMode) -> &mut Self {
81− self.config.wrapping_mode = wrapping_mode;
91+ pub fn wrapping_mode(&mut self, mode: WrappingMode) -> &mut Self {
92+ self.config.wrapping_mode = mode;
93+ self
94+ }
95+
96+ /// Whether or not to use ANSI italics (default: off)
97+ pub fn use_italics(&mut self, yes: bool) -> &mut Self {
98+ self.config.use_italic_text = yes;
99+ self
100+ }
101+
102+ /// If and how to use a pager (default: no paging)
103+ #[cfg(feature = "paging")]
104+ pub fn paging_mode(&mut self, mode: PagingMode) -> &mut Self {
105+ self.config.paging_mode = mode;
106+ self
107+ }
108+
109+ /// Specify the command to start the pager (default: use "less")
110+ #[cfg(feature = "paging")]
111+ pub fn pager(&mut self, cmd: &'a str) -> &mut Self {
112+ self.config.pager = Some(cmd);
113+ self
114+ }
115+
116+ /// Specify the lines that should be printed (default: all)
117+ pub fn line_ranges(&mut self, ranges: LineRanges) -> &mut Self {
118+ self.config.line_ranges = ranges;
119+ self
120+ }
121+
122+ /// Specify which lines should be highlighted (default: none)
123+ pub fn highlighted_lines(&mut self, ranges: HighlightedLineRanges) -> &mut Self {
124+ self.config.highlighted_lines = ranges;
125+ self
126+ }
127+
128+ /// Specify the highlighting theme
129+ pub fn theme(&mut self, theme: impl AsRef<str>) -> &mut Self {
130+ self.config.theme = theme.as_ref().to_owned();
131+ self
132+ }
133+
134+ /// Specify custom file extension / file name to syntax mappings
135+ pub fn syntax_mapping(&mut self, mapping: SyntaxMapping<'a>) -> &mut Self {
136+ self.config.syntax_mapping = mapping;
82137 self
83138 }
84139