mirror of
https://github.com/sharkdp/bat.git
synced 2025-02-21 20:38:44 +00:00
Skip non-file inputs when using --diff
This commit is contained in:
parent
8e18786556
commit
23afc8e90c
@ -16,7 +16,7 @@ pub enum VisibleLines {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl VisibleLines {
|
impl VisibleLines {
|
||||||
pub fn diff_context(&self) -> bool {
|
pub fn diff_mode(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Ranges(_) => false,
|
Self::Ranges(_) => false,
|
||||||
#[cfg(feature = "git")]
|
#[cfg(feature = "git")]
|
||||||
|
@ -73,26 +73,30 @@ impl<'b> Controller<'b> {
|
|||||||
}
|
}
|
||||||
Ok(mut opened_input) => {
|
Ok(mut opened_input) => {
|
||||||
#[cfg(feature = "git")]
|
#[cfg(feature = "git")]
|
||||||
let line_changes = if self.config.visible_lines.diff_context()
|
let line_changes = if self.config.visible_lines.diff_mode()
|
||||||
|| (!self.config.loop_through && self.config.style_components.changes())
|
|| (!self.config.loop_through && self.config.style_components.changes())
|
||||||
{
|
{
|
||||||
if let crate::input::OpenedInputKind::OrdinaryFile(ref path) =
|
match opened_input.kind {
|
||||||
opened_input.kind
|
crate::input::OpenedInputKind::OrdinaryFile(ref path) => {
|
||||||
{
|
let diff = get_git_diff(path);
|
||||||
let diff = get_git_diff(path);
|
|
||||||
|
|
||||||
if self.config.visible_lines.diff_context()
|
// Skip files without Git modifications
|
||||||
&& diff
|
if self.config.visible_lines.diff_mode()
|
||||||
.as_ref()
|
&& diff
|
||||||
.map(|changes| changes.is_empty())
|
.as_ref()
|
||||||
.unwrap_or(false)
|
.map(|changes| changes.is_empty())
|
||||||
{
|
.unwrap_or(false)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
diff
|
||||||
|
}
|
||||||
|
_ if self.config.visible_lines.diff_mode() => {
|
||||||
|
// Skip non-file inputs in diff mode
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
_ => None,
|
||||||
diff
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@ -134,7 +138,7 @@ impl<'b> Controller<'b> {
|
|||||||
printer: &mut dyn Printer,
|
printer: &mut dyn Printer,
|
||||||
writer: &mut dyn Write,
|
writer: &mut dyn Write,
|
||||||
input: &mut OpenedInput,
|
input: &mut OpenedInput,
|
||||||
#[cfg(feature = "git")] line_changes: &Option<LineChanges>,
|
line_changes: &Option<LineChanges>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if !input.reader.first_line.is_empty() || self.config.style_components.header() {
|
if !input.reader.first_line.is_empty() || self.config.style_components.header() {
|
||||||
printer.print_header(writer, input)?;
|
printer.print_header(writer, input)?;
|
||||||
|
@ -101,7 +101,7 @@ impl<'a> InteractivePrinter<'a> {
|
|||||||
config: &'a Config,
|
config: &'a Config,
|
||||||
assets: &'a HighlightingAssets,
|
assets: &'a HighlightingAssets,
|
||||||
input: &mut OpenedInput,
|
input: &mut OpenedInput,
|
||||||
#[cfg(feature = "git")] line_changes: &'a Option<LineChanges>,
|
line_changes: &'a Option<LineChanges>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let theme = assets.get_theme(&config.theme);
|
let theme = assets.get_theme(&config.theme);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user