mirror of
https://github.com/sharkdp/bat.git
synced 2025-03-20 01:28:49 +00:00
Add style for line-changes only
This commit is contained in:
parent
418b3c5ea1
commit
287123c6ce
17
src/main.rs
17
src/main.rs
@ -57,6 +57,7 @@ use errors::*;
|
|||||||
|
|
||||||
enum OptionsStyle {
|
enum OptionsStyle {
|
||||||
Plain,
|
Plain,
|
||||||
|
LineChanges,
|
||||||
LineNumbers,
|
LineNumbers,
|
||||||
Full,
|
Full,
|
||||||
}
|
}
|
||||||
@ -162,7 +163,7 @@ 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
|
// Show file name and bars for line-numbers and full styles
|
||||||
match options.style {
|
match options.style {
|
||||||
OptionsStyle::LineNumbers | OptionsStyle::Full => {
|
OptionsStyle::LineNumbers | OptionsStyle::Full => {
|
||||||
print_horizontal_line(&mut handle, '┬', term_width)?;
|
print_horizontal_line(&mut handle, '┬', term_width)?;
|
||||||
@ -177,7 +178,7 @@ fn print_file<P: AsRef<Path>>(
|
|||||||
|
|
||||||
print_horizontal_line(handle, '┼', term_width)?;
|
print_horizontal_line(handle, '┼', term_width)?;
|
||||||
}
|
}
|
||||||
OptionsStyle::Plain => {}
|
OptionsStyle::LineChanges | OptionsStyle::Plain => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -204,6 +205,13 @@ fn print_file<P: AsRef<Path>>(
|
|||||||
OptionsStyle::Plain => writeln!(
|
OptionsStyle::Plain => writeln!(
|
||||||
handle,
|
handle,
|
||||||
"{}", as_terminal_escaped(®ions, options.true_color))?,
|
"{}", as_terminal_escaped(®ions, options.true_color))?,
|
||||||
|
// Show content and git diff for line-changes style
|
||||||
|
OptionsStyle::LineChanges => writeln!(
|
||||||
|
handle,
|
||||||
|
"{} {}",
|
||||||
|
line_change,
|
||||||
|
as_terminal_escaped(®ions, options.true_color)
|
||||||
|
)?,
|
||||||
_ =>
|
_ =>
|
||||||
writeln!(
|
writeln!(
|
||||||
handle,
|
handle,
|
||||||
@ -224,7 +232,7 @@ fn print_file<P: AsRef<Path>>(
|
|||||||
match options.style {
|
match options.style {
|
||||||
OptionsStyle::LineNumbers | OptionsStyle::Full =>
|
OptionsStyle::LineNumbers | OptionsStyle::Full =>
|
||||||
print_horizontal_line(handle, '┴', term_width)?,
|
print_horizontal_line(handle, '┴', term_width)?,
|
||||||
OptionsStyle::Plain => {}
|
OptionsStyle::LineChanges | OptionsStyle::Plain => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -448,7 +456,7 @@ fn run() -> Result<()> {
|
|||||||
Arg::with_name("style")
|
Arg::with_name("style")
|
||||||
.short("s")
|
.short("s")
|
||||||
.long("style")
|
.long("style")
|
||||||
.possible_values(&["plain", "line-numbers", "full"])
|
.possible_values(&["plain", "line-changes", "line-numbers", "full"])
|
||||||
.default_value("full")
|
.default_value("full")
|
||||||
.help("Additional info to display alongwith content"),
|
.help("Additional info to display alongwith content"),
|
||||||
)
|
)
|
||||||
@ -470,6 +478,7 @@ fn run() -> Result<()> {
|
|||||||
true_color: is_truecolor_terminal(),
|
true_color: is_truecolor_terminal(),
|
||||||
style: match app_matches.value_of("style").unwrap() {
|
style: match app_matches.value_of("style").unwrap() {
|
||||||
"plain" => OptionsStyle::Plain,
|
"plain" => OptionsStyle::Plain,
|
||||||
|
"line-changes" => OptionsStyle::LineChanges,
|
||||||
"line-numbers" => OptionsStyle::LineNumbers,
|
"line-numbers" => OptionsStyle::LineNumbers,
|
||||||
_ => OptionsStyle::Full,
|
_ => OptionsStyle::Full,
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user