Always call the syntax highlighter

This commit is contained in:
sharkdp 2018-08-23 23:35:57 +02:00
parent 226d9a573a
commit 627181bcb6
2 changed files with 16 additions and 5 deletions

View File

@ -77,16 +77,18 @@ impl<'b> Controller<'b> {
match line_ranges {
&Some(ref range) => {
if line_number < range.lower {
// skip line
// Call the printer in case we need to call the syntax highlighter
// for this line. However, set `out_of_range` to `true`.
printer.print_line(true, writer, line_number, &line_buffer)?;
} else if line_number > range.upper {
// no more lines in range
// no more lines in range, exit early
break;
} else {
printer.print_line(writer, line_number, &line_buffer)?;
printer.print_line(false, writer, line_number, &line_buffer)?;
}
}
&None => {
printer.print_line(writer, line_number, &line_buffer)?;
printer.print_line(false, writer, line_number, &line_buffer)?;
}
}

View File

@ -24,6 +24,7 @@ pub trait Printer {
fn print_footer(&mut self, handle: &mut Write) -> Result<()>;
fn print_line(
&mut self,
out_of_range: bool,
handle: &mut Write,
line_number: usize,
line_buffer: &[u8],
@ -49,11 +50,14 @@ impl Printer for SimplePrinter {
fn print_line(
&mut self,
out_of_range: bool,
handle: &mut Write,
_line_number: usize,
line_buffer: &[u8],
) -> Result<()> {
handle.write(line_buffer)?;
if !out_of_range {
handle.write(line_buffer)?;
}
Ok(())
}
}
@ -188,6 +192,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
fn print_line(
&mut self,
out_of_range: bool,
handle: &mut Write,
line_number: usize,
line_buffer: &[u8],
@ -195,6 +200,10 @@ impl<'a> Printer for InteractivePrinter<'a> {
let line = String::from_utf8_lossy(&line_buffer);
let regions = self.highlighter.highlight(line.as_ref());
if out_of_range {
return Ok(());
}
let mut cursor: usize = 0;
let mut cursor_max: usize = self.config.term_width;
let mut panel_wrap: Option<String> = None;