on master help sign in
Merge branch 'master' of https://github.com/tskinn/bat into tskinn-master
a236a9bsharkdp
src/app.rs+8
@@ -77,7 +77,11 @@ pub struct Config<'a> {
77 /// Command to start the pager
77 /// Command to start the pager
78 pub pager: Option<&'a str>,
78 pub pager: Option<&'a str>,
79
79
80+ /// Whether or not to use ANSI italics
80 pub use_italic_text: bool,
81 pub use_italic_text: bool,
82+
83+ /// A line to highlight
84+ pub highlight_line: Option<usize>,
81}
85}
82
86
83fn is_truecolor_terminal() -> bool {
87fn is_truecolor_terminal() -> bool {
@@ -264,6 +268,10 @@ impl App {
264 Some("always") => true,
268 Some("always") => true,
265 _ => false,
269 _ => false,
266 },
270 },
271+ highlight_line: self
272+ .matches
273+ .value_of("highlight-line")
274+ .and_then(|w| w.parse().ok()),
267 })
275 })
268 }
276 }
269
277
src/clap_app.rs+11
@@ -188,6 +188,17 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
188 '--line-range 40:' prints lines 40 to the end of the file",
188 '--line-range 40:' prints lines 40 to the end of the file",
189 ),
189 ),
190 )
190 )
191+ .arg(
192+ Arg::with_name("highlight-line")
193+ .long("highlight-line")
194+ .overrides_with("highlight-line")
195+ .takes_value(true)
196+ .value_name("N")
197+ .help("Highlight a line.")
198+ .long_help(
199+ "Highlight the Nth line. The background color is changed to create contrast.",
200+ ),
201+ )
191 .arg(
202 .arg(
192 Arg::with_name("color")
203 Arg::with_name("color")
193 .long("color")
204 .long("color")
src/printer.rs+16−3
@@ -7,6 +7,7 @@ use ansi_term::Style;
7use console::AnsiCodeIterator;
7use console::AnsiCodeIterator;
8
8
9use syntect::easy::HighlightLines;
9use syntect::easy::HighlightLines;
10+use syntect::highlighting::Color;
10use syntect::highlighting::Theme;
11use syntect::highlighting::Theme;
11use syntect::parsing::SyntaxSet;
12use syntect::parsing::SyntaxSet;
12
13
@@ -79,6 +80,7 @@ pub struct InteractivePrinter<'a> {
79 pub line_changes: Option<LineChanges>,
80 pub line_changes: Option<LineChanges>,
80 highlighter: Option<HighlightLines<'a>>,
81 highlighter: Option<HighlightLines<'a>>,
81 syntax_set: &'a SyntaxSet,
82 syntax_set: &'a SyntaxSet,
83+ background_highlight: Option<Color>,
82}
84}
83
85
84impl<'a> InteractivePrinter<'a> {
86impl<'a> InteractivePrinter<'a> {
@@ -90,6 +92,8 @@ impl<'a> InteractivePrinter<'a> {
90 ) -> Self {
92 ) -> Self {
91 let theme = assets.get_theme(&config.theme);
93 let theme = assets.get_theme(&config.theme);
92
94
95+ let background_highlight = theme.settings.line_highlight;
96+
93 let colors = if config.colored_output {
97 let colors = if config.colored_output {
94 Colors::colored(theme, config.true_color)
98 Colors::colored(theme, config.true_color)
95 } else {
99 } else {
@@ -156,6 +160,7 @@ impl<'a> InteractivePrinter<'a> {
156 line_changes,
160 line_changes,
157 highlighter,
161 highlighter,
158 syntax_set: &assets.syntax_set,
162 syntax_set: &assets.syntax_set,
163+ background_highlight,
159 }
164 }
160 }
165 }
161
166
@@ -301,6 +306,12 @@ impl<'a> Printer for InteractivePrinter<'a> {
301 }
306 }
302 }
307 }
303
308
309+ // Line highlighting
310+ let background = self.config.highlight_line
311+ .filter(|line| *line == line_number)
312+ .map(|_| self.background_highlight)
313+ .unwrap();
314+
304 // Line contents.
315 // Line contents.
305 if self.config.output_wrap == OutputWrap::None {
316 if self.config.output_wrap == OutputWrap::None {
306 let true_color = self.config.true_color;
317 let true_color = self.config.true_color;
@@ -313,7 +324,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
313 write!(
324 write!(
314 handle,
325 handle,
315 "{}",
326 "{}",
316− as_terminal_escaped(style, text_trimmed, true_color, colored_output, italics,)
327+ as_terminal_escaped(style, text_trimmed, true_color, colored_output, italics, background)
317 )?;
328 )?;
318 write!(handle, "{}", &text[text_trimmed.len()..])?;
329 write!(handle, "{}", &text[text_trimmed.len()..])?;
319 }
330 }
@@ -370,7 +381,8 @@ impl<'a> Printer for InteractivePrinter<'a> {
370 ),
381 ),
371 self.config.true_color,
382 self.config.true_color,
372 self.config.colored_output,
383 self.config.colored_output,
373− self.config.use_italic_text
384+ self.config.use_italic_text,
385+ background
374 )
386 )
375 )?;
387 )?;
376 break;
388 break;
@@ -410,7 +422,8 @@ impl<'a> Printer for InteractivePrinter<'a> {
410 ),
422 ),
411 self.config.true_color,
423 self.config.true_color,
412 self.config.colored_output,
424 self.config.colored_output,
413− self.config.use_italic_text
425+ self.config.use_italic_text,
426+ background
414 ),
427 ),
415 panel_wrap.clone().unwrap()
428 panel_wrap.clone().unwrap()
416 )?;
429 )?;
src/terminal.rs+3−1
@@ -19,8 +19,9 @@ pub fn as_terminal_escaped(
19 true_color: bool,
19 true_color: bool,
20 colored: bool,
20 colored: bool,
21 italics: bool,
21 italics: bool,
22+ background_color: Option<highlighting::Color>,
22) -> String {
23) -> String {
23− let style = if !colored {
24+ let mut style = if !colored {
24 Style::default()
25 Style::default()
25 } else {
26 } else {
26 let color = to_ansi_color(style.foreground, true_color);
27 let color = to_ansi_color(style.foreground, true_color);
@@ -36,5 +37,6 @@ pub fn as_terminal_escaped(
36 }
37 }
37 };
38 };
38
39
40+ style.background = background_color.map(|c| to_ansi_color(c, true_color));
39 style.paint(text).to_string()
41 style.paint(text).to_string()
40}
42}