1
0
mirror of https://github.com/sharkdp/bat synced 2026-08-11 20:11:43 +00:00

Implementation of 'bat --diff'

This adds a new `--diff` option that can be used to only show lines
close to Git changes (added/removed/modified lines). The amount of
additional context can be controlled with `--diff-context=N`.

closes #23
This commit is contained in:
sharkdp
2020-04-23 23:39:30 +02:00
committed by David Peter
parent 0064321323
commit 82e7786e74
7 changed files with 145 additions and 36 deletions
+18 -8
View File
@@ -15,7 +15,7 @@ use console::Term;
use bat::{
assets::HighlightingAssets,
config::Config,
config::{Config, VisibleLines},
error::*,
input::Input,
line_range::{HighlightedLineRanges, LineRange, LineRanges},
@@ -196,13 +196,23 @@ impl App {
}
})
.unwrap_or_else(|| String::from(HighlightingAssets::default_theme())),
line_ranges: self
.matches
.values_of("line-range")
.map(|vs| vs.map(LineRange::from).collect())
.transpose()?
.map(LineRanges::from)
.unwrap_or_default(),
visible_lines: if self.matches.is_present("diff") {
VisibleLines::DiffContext(
self.matches
.value_of("diff-context")
.and_then(|t| t.parse().ok())
.unwrap_or(2),
)
} else {
VisibleLines::Ranges(
self.matches
.values_of("line-range")
.map(|vs| vs.map(LineRange::from).collect())
.transpose()?
.map(LineRanges::from)
.unwrap_or_default(),
)
},
style_components,
syntax_mapping,
pager: self.matches.value_of("pager"),