mirror of
https://github.com/sharkdp/bat.git
synced 2025-04-15 23:30:35 +01:00
Add --style option to disable line numbers and git markers (#43)
closes #5
This commit is contained in:
parent
4bba08062c
commit
7df9a5fe82
41
src/main.rs
41
src/main.rs
@ -46,7 +46,7 @@ lazy_static! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod errors {
|
mod errors {
|
||||||
error_chain!{
|
error_chain! {
|
||||||
foreign_links {
|
foreign_links {
|
||||||
Io(::std::io::Error);
|
Io(::std::io::Error);
|
||||||
}
|
}
|
||||||
@ -55,8 +55,15 @@ mod errors {
|
|||||||
|
|
||||||
use errors::*;
|
use errors::*;
|
||||||
|
|
||||||
|
enum OptionsStyle {
|
||||||
|
Plain,
|
||||||
|
LineNumbers,
|
||||||
|
Full,
|
||||||
|
}
|
||||||
|
|
||||||
struct Options<'a> {
|
struct Options<'a> {
|
||||||
true_color: bool,
|
true_color: bool,
|
||||||
|
style: OptionsStyle,
|
||||||
language: Option<&'a str>,
|
language: Option<&'a str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +102,9 @@ fn print_file<P: AsRef<Path>>(
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let reader = BufReader::new(File::open(filename.as_ref())?);
|
let reader = BufReader::new(File::open(filename.as_ref())?);
|
||||||
let syntax = match options.language {
|
let syntax = match options.language {
|
||||||
Some(language) => syntax_set.syntaxes().iter()
|
Some(language) => syntax_set
|
||||||
|
.syntaxes()
|
||||||
|
.iter()
|
||||||
.find(|syntax| syntax.name.eq_ignore_ascii_case(language)),
|
.find(|syntax| syntax.name.eq_ignore_ascii_case(language)),
|
||||||
None => syntax_set.find_syntax_for_file(filename.as_ref())?,
|
None => syntax_set.find_syntax_for_file(filename.as_ref())?,
|
||||||
};
|
};
|
||||||
@ -141,8 +150,14 @@ fn print_file<P: AsRef<Path>>(
|
|||||||
writeln!(
|
writeln!(
|
||||||
handle,
|
handle,
|
||||||
"{} {} {} {}",
|
"{} {} {} {}",
|
||||||
Fixed(244).paint(format!("{:4}", line_nr)),
|
Fixed(244).paint(match options.style {
|
||||||
line_change,
|
OptionsStyle::Plain => " ".to_owned(),
|
||||||
|
_ => format!("{:4}", line_nr),
|
||||||
|
}),
|
||||||
|
match options.style {
|
||||||
|
OptionsStyle::Full => line_change,
|
||||||
|
_ => Style::default().paint(" "),
|
||||||
|
},
|
||||||
Fixed(GRID_COLOR).paint("│"),
|
Fixed(GRID_COLOR).paint("│"),
|
||||||
as_terminal_escaped(®ions, options.true_color)
|
as_terminal_escaped(®ions, options.true_color)
|
||||||
)?;
|
)?;
|
||||||
@ -352,11 +367,12 @@ fn run() -> Result<()> {
|
|||||||
.setting(AppSettings::DisableVersion)
|
.setting(AppSettings::DisableVersion)
|
||||||
.max_term_width(90)
|
.max_term_width(90)
|
||||||
.about(crate_description!())
|
.about(crate_description!())
|
||||||
.arg(Arg::with_name("language")
|
.arg(
|
||||||
|
Arg::with_name("language")
|
||||||
.short("l")
|
.short("l")
|
||||||
.long("language")
|
.long("language")
|
||||||
.help("Language of the file(s)")
|
.help("Language of the file(s)")
|
||||||
.takes_value(true)
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("FILE")
|
Arg::with_name("FILE")
|
||||||
@ -364,6 +380,14 @@ fn run() -> Result<()> {
|
|||||||
.multiple(true)
|
.multiple(true)
|
||||||
.empty_values(false),
|
.empty_values(false),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("style")
|
||||||
|
.short("s")
|
||||||
|
.long("style")
|
||||||
|
.possible_values(&["plain", "line-numbers", "full"])
|
||||||
|
.default_value("full")
|
||||||
|
.help("Additional info to display alongwith content"),
|
||||||
|
)
|
||||||
.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"),
|
||||||
@ -380,6 +404,11 @@ fn run() -> Result<()> {
|
|||||||
_ => {
|
_ => {
|
||||||
let options = Options {
|
let options = Options {
|
||||||
true_color: is_truecolor_terminal(),
|
true_color: is_truecolor_terminal(),
|
||||||
|
style: match app_matches.value_of("style").unwrap() {
|
||||||
|
"plain" => OptionsStyle::Plain,
|
||||||
|
"line-numbers" => OptionsStyle::LineNumbers,
|
||||||
|
_ => OptionsStyle::Full,
|
||||||
|
},
|
||||||
language: app_matches.value_of("language"),
|
language: app_matches.value_of("language"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user