mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-11 08:08:29 +01:00
replace trait object BufRead by generic
This commit is contained in:
parent
94ccc646e8
commit
037861e588
@ -86,25 +86,26 @@ fn print_file(
|
|||||||
printer: &mut Printer,
|
printer: &mut Printer,
|
||||||
filename: Option<&str>,
|
filename: Option<&str>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let stdin = io::stdin(); // TODO: this is not always needed
|
printer.print_header(filename)?;
|
||||||
{
|
|
||||||
let reader: Box<BufRead> = match filename {
|
|
||||||
None => Box::new(stdin.lock()),
|
|
||||||
Some(filename) => Box::new(BufReader::new(File::open(filename)?)),
|
|
||||||
};
|
|
||||||
|
|
||||||
let highlighter = HighlightLines::new(syntax, theme);
|
let highlighter = HighlightLines::new(syntax, theme);
|
||||||
|
match filename {
|
||||||
printer.print_header(filename)?;
|
None => {
|
||||||
print_file_ranges(printer, reader, highlighter, &printer.config.line_range)?;
|
let stdin = io::stdin(); // TODO: this is not always needed
|
||||||
printer.print_footer()?;
|
print_file_ranges(printer, stdin.lock(), highlighter, &printer.config.line_range)?;
|
||||||
|
},
|
||||||
|
Some(filename) => {
|
||||||
|
print_file_ranges(printer, BufReader::new(File::open(filename)?), highlighter, &printer.config.line_range)?
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printer.print_footer()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_file_ranges<'a>(
|
fn print_file_ranges<T: BufRead>(
|
||||||
printer: &mut Printer,
|
printer: &mut Printer,
|
||||||
mut reader: Box<BufRead + 'a>,
|
mut reader: T,
|
||||||
mut highlighter: HighlightLines,
|
mut highlighter: HighlightLines,
|
||||||
line_ranges: &Option<LineRange>,
|
line_ranges: &Option<LineRange>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
Loading…
Reference in New Issue
Block a user