1
0
mirror of https://github.com/sharkdp/bat synced 2026-07-31 18:21:43 +00:00

add line-range

This commit is contained in:
Taylor Skinner
2018-05-31 21:08:29 -06:00
committed by David Peter
parent 50209bfe21
commit 6691786d82
3 changed files with 55 additions and 3 deletions
+14 -1
View File
@@ -96,12 +96,25 @@ fn print_file(
printer.print_header(filename)?;
let mut buffer = Vec::new();
while reader.read_until(b'\n', &mut buffer)? > 0 {
{
let line = String::from_utf8_lossy(&buffer);
let regions = highlighter.highlight(line.as_ref());
printer.print_line(&regions)?;
if printer.config.line_range.is_some() {
if printer.line_number + 1 < printer.config.line_range.unwrap().0 {
// skip line
printer.line_number += 1;
} else if printer.line_number >= printer.config.line_range.unwrap().1 {
// no more lines in range
break;
} else {
printer.print_line(&regions)?;
}
} else {
printer.print_line(&regions)?;
}
}
buffer.clear();
}