mirror of
https://github.com/ilyakooo0/bat.git
synced 2024-09-12 00:17:28 +03:00
Move git changes support behind a feature
This commit is contained in:
parent
570805bc98
commit
4e11abdf9b
@ -23,10 +23,12 @@ application = [
|
||||
"atty",
|
||||
"clap",
|
||||
"dirs",
|
||||
"git",
|
||||
"lazy_static",
|
||||
"liquid",
|
||||
"wild",
|
||||
]
|
||||
git = ["git2"] # Support indicating git modifications
|
||||
|
||||
[dependencies]
|
||||
atty = { version = "0.2.14", optional = true }
|
||||
@ -44,6 +46,7 @@ globset = "0.4"
|
||||
|
||||
[dependencies.git2]
|
||||
version = "0.13"
|
||||
optional = true
|
||||
default-features = false
|
||||
|
||||
[dependencies.syntect]
|
||||
|
1
ci/script.bash
vendored
1
ci/script.bash
vendored
@ -15,3 +15,4 @@ fi
|
||||
|
||||
# Check bat-as-a-library, which has a smaller set of dependencies
|
||||
cargo check --target "$TARGET" --verbose --lib --no-default-features
|
||||
cargo check --target "$TARGET" --verbose --lib --no-default-features --features git
|
||||
|
@ -1,3 +1,4 @@
|
||||
#[cfg(feature = "git")]
|
||||
use crate::diff::LineChange;
|
||||
use crate::printer::{Colors, InteractivePrinter};
|
||||
use ansi_term::Style;
|
||||
@ -68,6 +69,7 @@ impl Decoration for LineNumberDecoration {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "git")]
|
||||
pub struct LineChangesDecoration {
|
||||
cached_none: DecorationText,
|
||||
cached_added: DecorationText,
|
||||
@ -76,6 +78,7 @@ pub struct LineChangesDecoration {
|
||||
cached_modified: DecorationText,
|
||||
}
|
||||
|
||||
#[cfg(feature = "git")]
|
||||
impl LineChangesDecoration {
|
||||
#[inline]
|
||||
fn generate_cached(style: Style, text: &str) -> DecorationText {
|
||||
@ -96,6 +99,7 @@ impl LineChangesDecoration {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "git")]
|
||||
impl Decoration for LineChangesDecoration {
|
||||
fn generate(
|
||||
&self,
|
||||
|
@ -1,3 +1,5 @@
|
||||
#![cfg(feature = "git")]
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::ffi::OsStr;
|
||||
use std::fs;
|
||||
|
@ -21,11 +21,11 @@ use unicode_width::UnicodeWidthChar;
|
||||
|
||||
use crate::assets::HighlightingAssets;
|
||||
use crate::config::Config;
|
||||
use crate::decorations::{
|
||||
Decoration, GridBorderDecoration, LineChangesDecoration, LineNumberDecoration,
|
||||
};
|
||||
use crate::diff::get_git_diff;
|
||||
use crate::diff::LineChanges;
|
||||
use crate::decorations::{Decoration, GridBorderDecoration, LineNumberDecoration};
|
||||
#[cfg(feature = "git")]
|
||||
use crate::decorations::LineChangesDecoration;
|
||||
#[cfg(feature = "git")]
|
||||
use crate::diff::{get_git_diff, LineChanges};
|
||||
use crate::errors::*;
|
||||
use crate::inputfile::{InputFile, InputFileReader};
|
||||
use crate::line_range::RangeCheckResult;
|
||||
@ -100,6 +100,7 @@ pub struct InteractivePrinter<'a> {
|
||||
panel_width: usize,
|
||||
ansi_prefix_sgr: String,
|
||||
content_type: Option<ContentType>,
|
||||
#[cfg(feature = "git")]
|
||||
pub line_changes: Option<LineChanges>,
|
||||
highlighter: Option<HighlightLines<'a>>,
|
||||
syntax_set: &'a SyntaxSet,
|
||||
@ -130,8 +131,11 @@ impl<'a> InteractivePrinter<'a> {
|
||||
decorations.push(Box::new(LineNumberDecoration::new(&colors)));
|
||||
}
|
||||
|
||||
if config.style_components.changes() {
|
||||
decorations.push(Box::new(LineChangesDecoration::new(&colors)));
|
||||
#[cfg(feature = "git")]
|
||||
{
|
||||
if config.style_components.changes() {
|
||||
decorations.push(Box::new(LineChangesDecoration::new(&colors)));
|
||||
}
|
||||
}
|
||||
|
||||
let mut panel_width: usize =
|
||||
@ -153,6 +157,7 @@ impl<'a> InteractivePrinter<'a> {
|
||||
panel_width = 0;
|
||||
}
|
||||
|
||||
#[cfg(feature = "git")]
|
||||
let mut line_changes = None;
|
||||
|
||||
let highlighter = if reader
|
||||
@ -162,14 +167,14 @@ impl<'a> InteractivePrinter<'a> {
|
||||
None
|
||||
} else {
|
||||
// Get the Git modifications
|
||||
line_changes = if config.style_components.changes() {
|
||||
match file {
|
||||
InputFile::Ordinary(filename) => get_git_diff(filename),
|
||||
_ => None,
|
||||
#[cfg(feature = "git")]
|
||||
{
|
||||
if config.style_components.changes() {
|
||||
if let InputFile::Ordinary(filename) = file {
|
||||
line_changes = get_git_diff(filename);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
}
|
||||
|
||||
// Determine the type of syntax for highlighting
|
||||
let syntax = assets.get_syntax(config.language, file, reader, &config.syntax_mapping);
|
||||
@ -183,6 +188,7 @@ impl<'a> InteractivePrinter<'a> {
|
||||
decorations,
|
||||
content_type: reader.content_type,
|
||||
ansi_prefix_sgr: String::new(),
|
||||
#[cfg(feature = "git")]
|
||||
line_changes,
|
||||
highlighter,
|
||||
syntax_set: &assets.syntax_set,
|
||||
|
@ -68,6 +68,7 @@ impl StyleComponents {
|
||||
StyleComponents(components.iter().cloned().collect())
|
||||
}
|
||||
|
||||
#[cfg(feature = "git")]
|
||||
pub fn changes(&self) -> bool {
|
||||
self.0.contains(&StyleComponent::Changes)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user