1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-03-16 07:38:42 +00:00

Hide everything but content for plain option style

fix #5
This commit is contained in:
Nakul Chaudhari 2018-05-03 22:21:45 +02:00 committed by David Peter
parent 7df9a5fe82
commit 9dca3126b3

View File

@ -118,6 +118,9 @@ fn print_file<P: AsRef<Path>>(
let (_, term_width) = term.size(); let (_, term_width) = term.size();
let term_width = term_width as usize; let term_width = term_width as usize;
// Show file name and bars for all but plain style
match options.style {
OptionsStyle::LineNumbers | OptionsStyle::Full => {
print_horizontal_line(&mut handle, '┬', term_width)?; print_horizontal_line(&mut handle, '┬', term_width)?;
writeln!( writeln!(
@ -129,6 +132,10 @@ fn print_file<P: AsRef<Path>>(
)?; )?;
print_horizontal_line(&mut handle, '┼', term_width)?; print_horizontal_line(&mut handle, '┼', term_width)?;
}
OptionsStyle::Plain => {}
};
for (idx, maybe_line) in reader.lines().enumerate() { for (idx, maybe_line) in reader.lines().enumerate() {
let line_nr = idx + 1; let line_nr = idx + 1;
@ -147,23 +154,34 @@ fn print_file<P: AsRef<Path>>(
Style::default().paint(" ") Style::default().paint(" ")
}; };
match options.style {
// Show only content for plain style
OptionsStyle::Plain => writeln!(
handle,
"{}", as_terminal_escaped(&regions, options.true_color))?,
_ =>
writeln!( writeln!(
handle, handle,
"{} {} {} {}", "{} {} {} {}",
Fixed(244).paint(match options.style { Fixed(244).paint(format!("{:4}", line_nr)),
OptionsStyle::Plain => " ".to_owned(), // Show git modificiation markers only for full style
_ => format!("{:4}", line_nr),
}),
match options.style { match options.style {
OptionsStyle::Full => line_change, OptionsStyle::Full => line_change,
_ => Style::default().paint(" "), _ => Style::default().paint(" "),
}, },
Fixed(GRID_COLOR).paint(""), Fixed(GRID_COLOR).paint(""),
as_terminal_escaped(&regions, options.true_color) as_terminal_escaped(&regions, options.true_color)
)?; )?
}
} }
print_horizontal_line(&mut handle, '┴', term_width)?; // Show bars for all but plain style
match options.style {
OptionsStyle::LineNumbers | OptionsStyle::Full =>
print_horizontal_line(&mut handle, '┴', term_width)?,
OptionsStyle::Plain => {}
};
Ok(()) Ok(())
} }