on master help sign in
Add Diff syntax highlight test
commitb6e729abeb37306d70d791d79dcb4bcf03c2c299 authorBenjamin Neff <benjamin@coding4coffee.ch> dateThu 8 Oct 2020, 01:24 (6 years ago) parent5fe9868
2 files changed+706
tests/syntax-tests/highlighted/Diff/82e7786e747b1fcfac1f963ae6415a22ec9caae1.diff+353 tests/syntax-tests/source/Diff/82e7786e747b1fcfac1f963ae6415a22ec9caae1.diff+353
tests/syntax-tests/highlighted/Diff/82e7786e747b1fcfac1f963ae6415a22ec9caae1.diffnew file+353
@@ -0,0 +1,353 @@
1+diff --git a/CHANGELOG.md b/CHANGELOG.md
2+index ced88213..973eba9a 100644
3+--- a/CHANGELOG.md
4++++ b/CHANGELOG.md
5+@@ -2,6 +2,11 @@
6+ 
7+ 
8+ ## Features
9++
10++- Add a new `--diff` option that can be used to only show lines surrounding
11++ Git changes, i.e. added, removed or modified lines. The amount of additional
12++ context can be controlled with `--diff-context=N`. See #23 and #940
13++
14+ ## Bugfixes
15+ ## Other
16+ ## `bat` as a library
17+diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs
18+index e5221455..f0f519ea 100644
19+--- a/src/bin/bat/app.rs
20++++ b/src/bin/bat/app.rs
21+@@ -15,7 +15,7 @@ use console::Term;
22+ 
23+ use bat::{
24+ assets::HighlightingAssets,
25+- config::Config,
26++ config::{Config, VisibleLines},
27+ error::*,
28+ input::Input,
29+ line_range::{HighlightedLineRanges, LineRange, LineRanges},
30+@@ -196,13 +196,23 @@ impl App {
31+ }
32+ })
33+ .unwrap_or_else(|| String::from(HighlightingAssets::default_theme())),
34+- line_ranges: self
35+- .matches
36+- .values_of("line-range")
37+- .map(|vs| vs.map(LineRange::from).collect())
38+- .transpose()?
39+- .map(LineRanges::from)
40+- .unwrap_or_default(),
41++ visible_lines: if self.matches.is_present("diff") {
42++ VisibleLines::DiffContext(
43++ self.matches
44++ .value_of("diff-context")
45++ .and_then(|t| t.parse().ok())
46++ .unwrap_or(2),
47++ )
48++ } else {
49++ VisibleLines::Ranges(
50++ self.matches
51++ .values_of("line-range")
52++ .map(|vs| vs.map(LineRange::from).collect())
53++ .transpose()?
54++ .map(LineRanges::from)
55++ .unwrap_or_default(),
56++ )
57++ },
58+ style_components,
59+ syntax_mapping,
60+ pager: self.matches.value_of("pager"),
61+diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs
62+index c7344991..85edefde 100644
63+--- a/src/bin/bat/clap_app.rs
64++++ b/src/bin/bat/clap_app.rs
65+@@ -105,6 +105,34 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
66+ data to bat from STDIN when bat does not otherwise know \
67+ the filename."),
68+ )
69++ .arg(
70++ Arg::with_name("diff")
71++ .long("diff")
72++ .help("Only show lines that have been added/removed/modified.")
73++ .long_help(
74++ "Only show lines that have been added/removed/modified with respect \
75++ to the Git index. Use --diff-context=N to control how much context you want to see.",
76++ ),
77++ )
78++ .arg(
79++ Arg::with_name("diff-context")
80++ .long("diff-context")
81++ .overrides_with("diff-context")
82++ .takes_value(true)
83++ .value_name("N")
84++ .validator(
85++ |n| {
86++ n.parse::<usize>()
87++ .map_err(|_| "must be a number")
88++ .map(|_| ()) // Convert to Result<(), &str>
89++ .map_err(|e| e.to_string())
90++ }, // Convert to Result<(), String>
91++ )
92++ .hidden_short_help(true)
93++ .long_help(
94++ "Include N lines of context around added/removed/modified lines when using '--diff'.",
95++ ),
96++ )
97+ .arg(
98+ Arg::with_name("tabs")
99+ .long("tabs")
100+@@ -339,6 +367,7 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
101+ .takes_value(true)
102+ .number_of_values(1)
103+ .value_name("N:M")
104++ .conflicts_with("diff")
105+ .help("Only print the lines from N to M.")
106+ .long_help(
107+ "Only print the specified range of lines for each file. \
108+diff --git a/src/config.rs b/src/config.rs
109+index d5df9910..3c24b77f 100644
110+--- a/src/config.rs
111++++ b/src/config.rs
112+@@ -5,6 +5,32 @@ use crate::style::StyleComponents;
113+ use crate::syntax_mapping::SyntaxMapping;
114+ use crate::wrapping::WrappingMode;
115+ 
116++#[derive(Debug, Clone)]
117++pub enum VisibleLines {
118++ /// Show all lines which are included in the line ranges
119++ Ranges(LineRanges),
120++
121++ #[cfg(feature = "git")]
122++ /// Only show lines surrounding added/deleted/modified lines
123++ DiffContext(usize),
124++}
125++
126++impl VisibleLines {
127++ pub fn diff_context(&self) -> bool {
128++ match self {
129++ Self::Ranges(_) => false,
130++ #[cfg(feature = "git")]
131++ Self::DiffContext(_) => true,
132++ }
133++ }
134++}
135++
136++impl Default for VisibleLines {
137++ fn default() -> Self {
138++ VisibleLines::Ranges(LineRanges::default())
139++ }
140++}
141++
142+ #[derive(Debug, Clone, Default)]
143+ pub struct Config<'a> {
144+ /// The explicitly configured language, if any
145+@@ -39,8 +65,8 @@ pub struct Config<'a> {
146+ #[cfg(feature = "paging")]
147+ pub paging_mode: PagingMode,
148+ 
149+- /// Specifies the lines that should be printed
150+- pub line_ranges: LineRanges,
151++ /// Specifies which lines should be printed
152++ pub visible_lines: VisibleLines,
153+ 
154+ /// The syntax highlighting theme
155+ pub theme: String,
156+@@ -62,10 +88,7 @@ pub struct Config<'a> {
157+ fn default_config_should_include_all_lines() {
158+ use crate::line_range::RangeCheckResult;
159+ 
160+- assert_eq!(
161+- Config::default().line_ranges.check(17),
162+- RangeCheckResult::InRange
163+- );
164++ assert_eq!(LineRanges::default().check(17), RangeCheckResult::InRange);
165+ }
166+ 
167+ #[test]
168+diff --git a/src/controller.rs b/src/controller.rs
169+index 09c6ec2a..f636d5fd 100644
170+--- a/src/controller.rs
171++++ b/src/controller.rs
172+@@ -1,9 +1,13 @@
173+ use std::io::{self, Write};
174+ 
175+ use crate::assets::HighlightingAssets;
176+-use crate::config::Config;
177++use crate::config::{Config, VisibleLines};
178++#[cfg(feature = "git")]
179++use crate::diff::{get_git_diff, LineChanges};
180+ use crate::error::*;
181+ use crate::input::{Input, InputReader, OpenedInput};
182++#[cfg(feature = "git")]
183++use crate::line_range::LineRange;
184+ use crate::line_range::{LineRanges, RangeCheckResult};
185+ use crate::output::OutputType;
186+ #[cfg(feature = "paging")]
187+@@ -68,6 +72,32 @@ impl<'b> Controller<'b> {
188+ no_errors = false;
189+ }
190+ Ok(mut opened_input) => {
191++ #[cfg(feature = "git")]
192++ let line_changes = if self.config.visible_lines.diff_context()
193++ || (!self.config.loop_through && self.config.style_components.changes())
194++ {
195++ if let crate::input::OpenedInputKind::OrdinaryFile(ref path) =
196++ opened_input.kind
197++ {
198++ let diff = get_git_diff(path);
199++
200++ if self.config.visible_lines.diff_context()
201++ && diff
202++ .as_ref()
203++ .map(|changes| changes.is_empty())
204++ .unwrap_or(false)
205++ {
206++ continue;
207++ }
208++
209++ diff
210++ } else {
211++ None
212++ }
213++ } else {
214++ None
215++ };
216++
217+ let mut printer: Box<dyn Printer> = if self.config.loop_through {
218+ Box::new(SimplePrinter::new())
219+ } else {
220+@@ -75,10 +105,18 @@ impl<'b> Controller<'b> {
221+ &self.config,
222+ &self.assets,
223+ &mut opened_input,
224++ #[cfg(feature = "git")]
225++ &line_changes,
226+ ))
227+ };
228+ 
229+- let result = self.print_file(&mut *printer, writer, &mut opened_input);
230++ let result = self.print_file(
231++ &mut *printer,
232++ writer,
233++ &mut opened_input,
234++ #[cfg(feature = "git")]
235++ &line_changes,
236++ );
237+ 
238+ if let Err(error) = result {
239+ handle_error(&error);
240+@@ -96,13 +134,31 @@ impl<'b> Controller<'b> {
241+ printer: &mut dyn Printer,
242+ writer: &mut dyn Write,
243+ input: &mut OpenedInput,
244++ #[cfg(feature = "git")] line_changes: &Option<LineChanges>,
245+ ) -> Result<()> {
246+ if !input.reader.first_line.is_empty() || self.config.style_components.header() {
247+ printer.print_header(writer, input)?;
248+ }
249+ 
250+ if !input.reader.first_line.is_empty() {
251+- self.print_file_ranges(printer, writer, &mut input.reader, &self.config.line_ranges)?;
252++ let line_ranges = match self.config.visible_lines {
253++ VisibleLines::Ranges(ref line_ranges) => line_ranges.clone(),
254++ #[cfg(feature = "git")]
255++ VisibleLines::DiffContext(context) => {
256++ let mut line_ranges: Vec<LineRange> = vec![];
257++
258++ if let Some(line_changes) = line_changes {
259++ for line in line_changes.keys() {
260++ let line = *line as usize;
261++ line_ranges.push(LineRange::new(line - context, line + context));
262++ }
263++ }
264++
265++ LineRanges::from(line_ranges)
266++ }
267++ };
268++
269++ self.print_file_ranges(printer, writer, &mut input.reader, &line_ranges)?;
270+ }
271+ printer.print_footer(writer, input)?;
272+ 
273+diff --git a/src/pretty_printer.rs b/src/pretty_printer.rs
274+index 0c78ea90..13bd5dbc 100644
275+--- a/src/pretty_printer.rs
276++++ b/src/pretty_printer.rs
277+@@ -6,7 +6,7 @@ use syntect::parsing::SyntaxReference;
278+ 
279+ use crate::{
280+ assets::HighlightingAssets,
281+- config::Config,
282++ config::{Config, VisibleLines},
283+ controller::Controller,
284+ error::Result,
285+ input::Input,
286+@@ -205,7 +205,7 @@ impl<'a> PrettyPrinter<'a> {
287+ 
288+ /// Specify the lines that should be printed (default: all)
289+ pub fn line_ranges(&mut self, ranges: LineRanges) -> &mut Self {
290+- self.config.line_ranges = ranges;
291++ self.config.visible_lines = VisibleLines::Ranges(ranges);
292+ self
293+ }
294+ 
295+diff --git a/src/printer.rs b/src/printer.rs
296+index 5eed437e..2b245cfd 100644
297+--- a/src/printer.rs
298++++ b/src/printer.rs
299+@@ -24,7 +24,7 @@ use crate::config::Config;
300+ use crate::decorations::LineChangesDecoration;
301+ use crate::decorations::{Decoration, GridBorderDecoration, LineNumberDecoration};
302+ #[cfg(feature = "git")]
303+-use crate::diff::{get_git_diff, LineChanges};
304++use crate::diff::LineChanges;
305+ use crate::error::*;
306+ use crate::input::OpenedInput;
307+ use crate::line_range::RangeCheckResult;
308+@@ -90,7 +90,7 @@ pub(crate) struct InteractivePrinter<'a> {
309+ ansi_prefix_sgr: String,
310+ content_type: Option<ContentType>,
311+ #[cfg(feature = "git")]
312+- pub line_changes: Option<LineChanges>,
313++ pub line_changes: &'a Option<LineChanges>,
314+ highlighter: Option<HighlightLines<'a>>,
315+ syntax_set: &'a SyntaxSet,
316+ background_color_highlight: Option<Color>,
317+@@ -101,6 +101,7 @@ impl<'a> InteractivePrinter<'a> {
318+ config: &'a Config,
319+ assets: &'a HighlightingAssets,
320+ input: &mut OpenedInput,
321++ #[cfg(feature = "git")] line_changes: &'a Option<LineChanges>,
322+ ) -> Self {
323+ let theme = assets.get_theme(&config.theme);
324+ 
325+@@ -145,9 +146,6 @@ impl<'a> InteractivePrinter<'a> {
326+ panel_width = 0;
327+ }
328+ 
329+- #[cfg(feature = "git")]
330+- let mut line_changes = None;
331+-
332+ let highlighter = if input
333+ .reader
334+ .content_type
335+@@ -155,18 +153,6 @@ impl<'a> InteractivePrinter<'a> {
336+ {
337+ None
338+ } else {
339+- // Get the Git modifications
340+- #[cfg(feature = "git")]
341+- {
342+- use crate::input::OpenedInputKind;
343+-
344+- if config.style_components.changes() {
345+- if let OpenedInputKind::OrdinaryFile(ref path) = input.kind {
346+- line_changes = get_git_diff(path);
347+- }
348+- }
349+- }
350+-
351+ // Determine the type of syntax for highlighting
352+ let syntax = assets.get_syntax(config.language, input, &config.syntax_mapping);
353+ Some(HighlightLines::new(syntax, theme))
tests/syntax-tests/source/Diff/82e7786e747b1fcfac1f963ae6415a22ec9caae1.diffnew file+353
@@ -0,0 +1,353 @@
1+diff --git a/CHANGELOG.md b/CHANGELOG.md
2+index ced88213..973eba9a 100644
3+--- a/CHANGELOG.md
4++++ b/CHANGELOG.md
5+@@ -2,6 +2,11 @@
6+
7+
8+ ## Features
9++
10++- Add a new `--diff` option that can be used to only show lines surrounding
11++ Git changes, i.e. added, removed or modified lines. The amount of additional
12++ context can be controlled with `--diff-context=N`. See #23 and #940
13++
14+ ## Bugfixes
15+ ## Other
16+ ## `bat` as a library
17+diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs
18+index e5221455..f0f519ea 100644
19+--- a/src/bin/bat/app.rs
20++++ b/src/bin/bat/app.rs
21+@@ -15,7 +15,7 @@ use console::Term;
22+
23+ use bat::{
24+ assets::HighlightingAssets,
25+- config::Config,
26++ config::{Config, VisibleLines},
27+ error::*,
28+ input::Input,
29+ line_range::{HighlightedLineRanges, LineRange, LineRanges},
30+@@ -196,13 +196,23 @@ impl App {
31+ }
32+ })
33+ .unwrap_or_else(|| String::from(HighlightingAssets::default_theme())),
34+- line_ranges: self
35+- .matches
36+- .values_of("line-range")
37+- .map(|vs| vs.map(LineRange::from).collect())
38+- .transpose()?
39+- .map(LineRanges::from)
40+- .unwrap_or_default(),
41++ visible_lines: if self.matches.is_present("diff") {
42++ VisibleLines::DiffContext(
43++ self.matches
44++ .value_of("diff-context")
45++ .and_then(|t| t.parse().ok())
46++ .unwrap_or(2),
47++ )
48++ } else {
49++ VisibleLines::Ranges(
50++ self.matches
51++ .values_of("line-range")
52++ .map(|vs| vs.map(LineRange::from).collect())
53++ .transpose()?
54++ .map(LineRanges::from)
55++ .unwrap_or_default(),
56++ )
57++ },
58+ style_components,
59+ syntax_mapping,
60+ pager: self.matches.value_of("pager"),
61+diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs
62+index c7344991..85edefde 100644
63+--- a/src/bin/bat/clap_app.rs
64++++ b/src/bin/bat/clap_app.rs
65+@@ -105,6 +105,34 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
66+ data to bat from STDIN when bat does not otherwise know \
67+ the filename."),
68+ )
69++ .arg(
70++ Arg::with_name("diff")
71++ .long("diff")
72++ .help("Only show lines that have been added/removed/modified.")
73++ .long_help(
74++ "Only show lines that have been added/removed/modified with respect \
75++ to the Git index. Use --diff-context=N to control how much context you want to see.",
76++ ),
77++ )
78++ .arg(
79++ Arg::with_name("diff-context")
80++ .long("diff-context")
81++ .overrides_with("diff-context")
82++ .takes_value(true)
83++ .value_name("N")
84++ .validator(
85++ |n| {
86++ n.parse::<usize>()
87++ .map_err(|_| "must be a number")
88++ .map(|_| ()) // Convert to Result<(), &str>
89++ .map_err(|e| e.to_string())
90++ }, // Convert to Result<(), String>
91++ )
92++ .hidden_short_help(true)
93++ .long_help(
94++ "Include N lines of context around added/removed/modified lines when using '--diff'.",
95++ ),
96++ )
97+ .arg(
98+ Arg::with_name("tabs")
99+ .long("tabs")
100+@@ -339,6 +367,7 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
101+ .takes_value(true)
102+ .number_of_values(1)
103+ .value_name("N:M")
104++ .conflicts_with("diff")
105+ .help("Only print the lines from N to M.")
106+ .long_help(
107+ "Only print the specified range of lines for each file. \
108+diff --git a/src/config.rs b/src/config.rs
109+index d5df9910..3c24b77f 100644
110+--- a/src/config.rs
111++++ b/src/config.rs
112+@@ -5,6 +5,32 @@ use crate::style::StyleComponents;
113+ use crate::syntax_mapping::SyntaxMapping;
114+ use crate::wrapping::WrappingMode;
115+
116++#[derive(Debug, Clone)]
117++pub enum VisibleLines {
118++ /// Show all lines which are included in the line ranges
119++ Ranges(LineRanges),
120++
121++ #[cfg(feature = "git")]
122++ /// Only show lines surrounding added/deleted/modified lines
123++ DiffContext(usize),
124++}
125++
126++impl VisibleLines {
127++ pub fn diff_context(&self) -> bool {
128++ match self {
129++ Self::Ranges(_) => false,
130++ #[cfg(feature = "git")]
131++ Self::DiffContext(_) => true,
132++ }
133++ }
134++}
135++
136++impl Default for VisibleLines {
137++ fn default() -> Self {
138++ VisibleLines::Ranges(LineRanges::default())
139++ }
140++}
141++
142+ #[derive(Debug, Clone, Default)]
143+ pub struct Config<'a> {
144+ /// The explicitly configured language, if any
145+@@ -39,8 +65,8 @@ pub struct Config<'a> {
146+ #[cfg(feature = "paging")]
147+ pub paging_mode: PagingMode,
148+
149+- /// Specifies the lines that should be printed
150+- pub line_ranges: LineRanges,
151++ /// Specifies which lines should be printed
152++ pub visible_lines: VisibleLines,
153+
154+ /// The syntax highlighting theme
155+ pub theme: String,
156+@@ -62,10 +88,7 @@ pub struct Config<'a> {
157+ fn default_config_should_include_all_lines() {
158+ use crate::line_range::RangeCheckResult;
159+
160+- assert_eq!(
161+- Config::default().line_ranges.check(17),
162+- RangeCheckResult::InRange
163+- );
164++ assert_eq!(LineRanges::default().check(17), RangeCheckResult::InRange);
165+ }
166+
167+ #[test]
168+diff --git a/src/controller.rs b/src/controller.rs
169+index 09c6ec2a..f636d5fd 100644
170+--- a/src/controller.rs
171++++ b/src/controller.rs
172+@@ -1,9 +1,13 @@
173+ use std::io::{self, Write};
174+
175+ use crate::assets::HighlightingAssets;
176+-use crate::config::Config;
177++use crate::config::{Config, VisibleLines};
178++#[cfg(feature = "git")]
179++use crate::diff::{get_git_diff, LineChanges};
180+ use crate::error::*;
181+ use crate::input::{Input, InputReader, OpenedInput};
182++#[cfg(feature = "git")]
183++use crate::line_range::LineRange;
184+ use crate::line_range::{LineRanges, RangeCheckResult};
185+ use crate::output::OutputType;
186+ #[cfg(feature = "paging")]
187+@@ -68,6 +72,32 @@ impl<'b> Controller<'b> {
188+ no_errors = false;
189+ }
190+ Ok(mut opened_input) => {
191++ #[cfg(feature = "git")]
192++ let line_changes = if self.config.visible_lines.diff_context()
193++ || (!self.config.loop_through && self.config.style_components.changes())
194++ {
195++ if let crate::input::OpenedInputKind::OrdinaryFile(ref path) =
196++ opened_input.kind
197++ {
198++ let diff = get_git_diff(path);
199++
200++ if self.config.visible_lines.diff_context()
201++ && diff
202++ .as_ref()
203++ .map(|changes| changes.is_empty())
204++ .unwrap_or(false)
205++ {
206++ continue;
207++ }
208++
209++ diff
210++ } else {
211++ None
212++ }
213++ } else {
214++ None
215++ };
216++
217+ let mut printer: Box<dyn Printer> = if self.config.loop_through {
218+ Box::new(SimplePrinter::new())
219+ } else {
220+@@ -75,10 +105,18 @@ impl<'b> Controller<'b> {
221+ &self.config,
222+ &self.assets,
223+ &mut opened_input,
224++ #[cfg(feature = "git")]
225++ &line_changes,
226+ ))
227+ };
228+
229+- let result = self.print_file(&mut *printer, writer, &mut opened_input);
230++ let result = self.print_file(
231++ &mut *printer,
232++ writer,
233++ &mut opened_input,
234++ #[cfg(feature = "git")]
235++ &line_changes,
236++ );
237+
238+ if let Err(error) = result {
239+ handle_error(&error);
240+@@ -96,13 +134,31 @@ impl<'b> Controller<'b> {
241+ printer: &mut dyn Printer,
242+ writer: &mut dyn Write,
243+ input: &mut OpenedInput,
244++ #[cfg(feature = "git")] line_changes: &Option<LineChanges>,
245+ ) -> Result<()> {
246+ if !input.reader.first_line.is_empty() || self.config.style_components.header() {
247+ printer.print_header(writer, input)?;
248+ }
249+
250+ if !input.reader.first_line.is_empty() {
251+- self.print_file_ranges(printer, writer, &mut input.reader, &self.config.line_ranges)?;
252++ let line_ranges = match self.config.visible_lines {
253++ VisibleLines::Ranges(ref line_ranges) => line_ranges.clone(),
254++ #[cfg(feature = "git")]
255++ VisibleLines::DiffContext(context) => {
256++ let mut line_ranges: Vec<LineRange> = vec![];
257++
258++ if let Some(line_changes) = line_changes {
259++ for line in line_changes.keys() {
260++ let line = *line as usize;
261++ line_ranges.push(LineRange::new(line - context, line + context));
262++ }
263++ }
264++
265++ LineRanges::from(line_ranges)
266++ }
267++ };
268++
269++ self.print_file_ranges(printer, writer, &mut input.reader, &line_ranges)?;
270+ }
271+ printer.print_footer(writer, input)?;
272+
273+diff --git a/src/pretty_printer.rs b/src/pretty_printer.rs
274+index 0c78ea90..13bd5dbc 100644
275+--- a/src/pretty_printer.rs
276++++ b/src/pretty_printer.rs
277+@@ -6,7 +6,7 @@ use syntect::parsing::SyntaxReference;
278+
279+ use crate::{
280+ assets::HighlightingAssets,
281+- config::Config,
282++ config::{Config, VisibleLines},
283+ controller::Controller,
284+ error::Result,
285+ input::Input,
286+@@ -205,7 +205,7 @@ impl<'a> PrettyPrinter<'a> {
287+
288+ /// Specify the lines that should be printed (default: all)
289+ pub fn line_ranges(&mut self, ranges: LineRanges) -> &mut Self {
290+- self.config.line_ranges = ranges;
291++ self.config.visible_lines = VisibleLines::Ranges(ranges);
292+ self
293+ }
294+
295+diff --git a/src/printer.rs b/src/printer.rs
296+index 5eed437e..2b245cfd 100644
297+--- a/src/printer.rs
298++++ b/src/printer.rs
299+@@ -24,7 +24,7 @@ use crate::config::Config;
300+ use crate::decorations::LineChangesDecoration;
301+ use crate::decorations::{Decoration, GridBorderDecoration, LineNumberDecoration};
302+ #[cfg(feature = "git")]
303+-use crate::diff::{get_git_diff, LineChanges};
304++use crate::diff::LineChanges;
305+ use crate::error::*;
306+ use crate::input::OpenedInput;
307+ use crate::line_range::RangeCheckResult;
308+@@ -90,7 +90,7 @@ pub(crate) struct InteractivePrinter<'a> {
309+ ansi_prefix_sgr: String,
310+ content_type: Option<ContentType>,
311+ #[cfg(feature = "git")]
312+- pub line_changes: Option<LineChanges>,
313++ pub line_changes: &'a Option<LineChanges>,
314+ highlighter: Option<HighlightLines<'a>>,
315+ syntax_set: &'a SyntaxSet,
316+ background_color_highlight: Option<Color>,
317+@@ -101,6 +101,7 @@ impl<'a> InteractivePrinter<'a> {
318+ config: &'a Config,
319+ assets: &'a HighlightingAssets,
320+ input: &mut OpenedInput,
321++ #[cfg(feature = "git")] line_changes: &'a Option<LineChanges>,
322+ ) -> Self {
323+ let theme = assets.get_theme(&config.theme);
324+
325+@@ -145,9 +146,6 @@ impl<'a> InteractivePrinter<'a> {
326+ panel_width = 0;
327+ }
328+
329+- #[cfg(feature = "git")]
330+- let mut line_changes = None;
331+-
332+ let highlighter = if input
333+ .reader
334+ .content_type
335+@@ -155,18 +153,6 @@ impl<'a> InteractivePrinter<'a> {
336+ {
337+ None
338+ } else {
339+- // Get the Git modifications
340+- #[cfg(feature = "git")]
341+- {
342+- use crate::input::OpenedInputKind;
343+-
344+- if config.style_components.changes() {
345+- if let OpenedInputKind::OrdinaryFile(ref path) = input.kind {
346+- line_changes = get_git_diff(path);
347+- }
348+- }
349+- }
350+-
351+ // Determine the type of syntax for highlighting
352+ let syntax = assets.get_syntax(config.language, input, &config.syntax_mapping);
353+ Some(HighlightLines::new(syntax, theme))