1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-03-14 06:38:24 +00:00

Add simple style option to enable/disable additional info

Remove previously added options to disable
* line number
* git modification marker
* file name

fix #5
This commit is contained in:
Nakul Chaudhari 2018-05-03 18:14:41 +02:00
parent 3939de4075
commit ada0b6ac50

View File

@ -55,11 +55,15 @@ mod errors {
use errors::*; use errors::*;
enum OptionsStyle {
Plain,
LineNumbers,
Full,
}
struct Options { struct Options {
true_color: bool, true_color: bool,
file_name: bool, style: OptionsStyle,
line_number: bool,
git_modification_marker: bool,
} }
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
@ -104,17 +108,15 @@ 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;
if options.file_name { print_horizontal_line(&mut handle, '┬', term_width)?;
print_horizontal_line(&mut handle, '┬', term_width)?;
writeln!( writeln!(
handle, handle,
"{}{} File {}", "{}{} File {}",
" ".repeat(PANEL_WIDTH), " ".repeat(PANEL_WIDTH),
Fixed(GRID_COLOR).paint(""), Fixed(GRID_COLOR).paint(""),
White.bold().paint(filename.as_ref().to_string_lossy()) White.bold().paint(filename.as_ref().to_string_lossy())
)?; )?;
}
print_horizontal_line(&mut handle, '┼', term_width)?; print_horizontal_line(&mut handle, '┼', term_width)?;
@ -138,15 +140,13 @@ fn print_file<P: AsRef<Path>>(
writeln!( writeln!(
handle, handle,
"{} {} {} {}", "{} {} {} {}",
Fixed(244).paint(if options.line_number { Fixed(244).paint(match options.style {
format!("{:4}", line_nr) OptionsStyle::Plain => " ".to_owned(),
} else { _ => format!("{:4}", line_nr),
" ".to_owned()
}), }),
if options.git_modification_marker { match options.style {
line_change OptionsStyle::Full => line_change,
} else { _ => 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)
@ -364,23 +364,12 @@ fn run() -> Result<()> {
.empty_values(false), .empty_values(false),
) )
.arg( .arg(
Arg::with_name("disable-file-name") Arg::with_name("style")
.short("f") .short("s")
.long("disable-file-name") .long("style")
.help("Disable file name"), .possible_values(&["plain", "line-numbers", "full"])
) .default_value("full")
.arg( .help("Additional info to display alongwith content"))
Arg::with_name("disable-line-number")
.short("n")
.long("disable-line-number")
.help("Disable line number"),
)
.arg(
Arg::with_name("disable-git-modfication-marker")
.short("g")
.long("disable-git-modfication-marker")
.help("Disable git modfication marker"),
)
.subcommand( .subcommand(
SubCommand::with_name("init-cache") SubCommand::with_name("init-cache")
.about("Load syntax definitions and themes into cache"), .about("Load syntax definitions and themes into cache"),
@ -397,9 +386,11 @@ fn run() -> Result<()> {
_ => { _ => {
let options = Options { let options = Options {
true_color: is_truecolor_terminal(), true_color: is_truecolor_terminal(),
file_name: !app_matches.is_present("disable-file-name"), style: match app_matches.value_of("style").unwrap() {
line_number: !app_matches.is_present("disable-line-number"), "plain" => OptionsStyle::Plain,
git_modification_marker: !app_matches.is_present("disable-git-modfication-marker"), "line-numbers" => OptionsStyle::LineNumbers,
_ => OptionsStyle::Full
},
}; };
let assets = let assets =
@ -430,7 +421,7 @@ fn main() {
if let Err(error) = result { if let Err(error) = result {
match error { match error {
Error(ErrorKind::Io(ref io_error), _) Error(ErrorKind::Io(ref io_error), _)
if io_error.kind() == io::ErrorKind::BrokenPipe => {} if io_error.kind() == io::ErrorKind::BrokenPipe => {}
_ => { _ => {
eprintln!("{}: {}", Red.paint("[bat error]"), error); eprintln!("{}: {}", Red.paint("[bat error]"), error);