mirror of
https://github.com/sharkdp/bat
synced 2024-11-27 06:10:20 +00:00
printer.rs: De-duplicate code to highlight long lines
We do this to only have one invocation of `highlighter.highlight(...)` so we don't need to change to `highlighter.highlight_line(...)` in two places in #2181.
This commit is contained in:
parent
05ebf5ed26
commit
0851bbbb28
1 changed files with 13 additions and 10 deletions
|
@ -445,18 +445,21 @@ impl<'a> Printer for InteractivePrinter<'a> {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// skip syntax highlighting on long lines
|
// skip syntax highlighting on long lines
|
||||||
if line.len() > 1024 * 16 {
|
let too_long = line.len() > 1024 * 16;
|
||||||
let mut empty = highlighter_from_set
|
|
||||||
|
let for_highlighting: &str = if too_long { "\n" } else { &line };
|
||||||
|
|
||||||
|
let mut highlighted_line = highlighter_from_set
|
||||||
.highlighter
|
.highlighter
|
||||||
.highlight(&"\n", highlighter_from_set.syntax_set);
|
.highlight(for_highlighting, highlighter_from_set.syntax_set);
|
||||||
empty[0].1 = line.as_ref();
|
|
||||||
empty
|
if too_long {
|
||||||
} else {
|
highlighted_line[0].1 = &line;
|
||||||
highlighter_from_set
|
|
||||||
.highlighter
|
|
||||||
.highlight(&line, highlighter_from_set.syntax_set)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
highlighted_line
|
||||||
};
|
};
|
||||||
|
|
||||||
if out_of_range {
|
if out_of_range {
|
||||||
|
|
Loading…
Reference in a new issue