1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-02-21 12:28:30 +00:00

Colorize the whole line

This commit is contained in:
sharkdp 2018-12-16 21:53:15 +01:00
parent 6b92814ea0
commit cf7ed042c1

View File

@ -293,17 +293,15 @@ impl<'a> Printer for InteractivePrinter<'a> {
let mut panel_wrap: Option<String> = None; let mut panel_wrap: Option<String> = None;
// Line highlighting // Line highlighting
let background_color = if self let highlight_this_line = self
.config .config
.highlight_lines .highlight_lines
.iter() .iter()
.find(|&&l| l == line_number) .any(|&l| l == line_number);
.is_some()
{ let background_color = self
self.background_color_highlight .background_color_highlight
} else { .filter(|_| highlight_this_line);
None
};
// Line decorations. // Line decorations.
if self.panel_width > 0 { if self.panel_width > 0 {
@ -340,7 +338,20 @@ impl<'a> Printer for InteractivePrinter<'a> {
background_color background_color
) )
)?; )?;
write!(handle, "{}", &text[text_trimmed.len()..])?;
if text.len() != text_trimmed.len() {
if let Some(background_color) = background_color {
let mut ansi_style = Style::default();
ansi_style.background = Some(to_ansi_color(background_color, true_color));
let width = if cursor_total <= cursor_max {
cursor_max - cursor_total + 1
} else {
0
};
write!(handle, "{}", ansi_style.paint(" ".repeat(width)))?;
}
write!(handle, "{}", &text[text_trimmed.len()..])?;
}
} }
if line.bytes().next_back() != Some(b'\n') { if line.bytes().next_back() != Some(b'\n') {
@ -450,6 +461,17 @@ impl<'a> Printer for InteractivePrinter<'a> {
} }
} }
if let Some(background_color) = background_color {
let mut ansi_style = Style::default();
ansi_style.background =
Some(to_ansi_color(background_color, self.config.true_color));
write!(
handle,
"{}",
ansi_style.paint(" ".repeat(cursor_max - cursor))
)?;
}
write!(handle, "\n")?; write!(handle, "\n")?;
} }