@@ -9,6 +9,8 @@ use console::AnsiCodeIterator;
99use syntect::easy::HighlightLines;
1010use syntect::highlighting::Theme;
1111
12+use content_inspector::{self, ContentType};
13+
1214use app::Config;
1315use assets::HighlightingAssets;
1416use decorations::{Decoration, GridBorderDecoration, LineChangesDecoration, LineNumberDecoration};
@@ -69,8 +71,9 @@ pub struct InteractivePrinter<'a> {
6971 decorations: Vec<Box<dyn Decoration>>,
7072 panel_width: usize,
7173 ansi_prefix_sgr: String,
74+ content_type: ContentType,
7275 pub line_changes: Option<LineChanges>,
73− highlighter: HighlightLines<'a>,
76+ highlighter: Option<HighlightLines<'a>>,
7477}
7578
7679impl<'a> InteractivePrinter<'a> {
@@ -118,19 +121,28 @@ impl<'a> InteractivePrinter<'a> {
118121 panel_width = 0;
119122 }
120123
121− // Get the Git modifications
122− let line_changes = if config.output_components.changes() {
123− match file {
124− InputFile::Ordinary(filename) => get_git_diff(filename),
125− _ => None,
126− }
127− } else {
124+ // Determine file content type
125+ let content_type = content_inspector::inspect(&reader.first_line[..]);
126+
127+ let mut line_changes = None;
128+
129+ let highlighter = if content_type.is_binary() {
128130 None
129− };
131+ } else {
132+ // Get the Git modifications
133+ line_changes = if config.output_components.changes() {
134+ match file {
135+ InputFile::Ordinary(filename) => get_git_diff(filename),
136+ _ => None,
137+ }
138+ } else {
139+ None
140+ };
130141
131− // Determine the type of syntax for highlighting
132− let syntax = assets.get_syntax(config.language, file, reader);
133− let highlighter = HighlightLines::new(syntax, theme);
142+ // Determine the type of syntax for highlighting
143+ let syntax = assets.get_syntax(config.language, file, reader);
144+ Some(HighlightLines::new(syntax, theme))
145+ };
134146
135147 InteractivePrinter {
136148 panel_width,
@@ -138,6 +150,7 @@ impl<'a> InteractivePrinter<'a> {
138150 config,
139151 decorations,
140152 ansi_prefix_sgr: String::new(),
153+ content_type,
141154 line_changes,
142155 highlighter,
143156 }
@@ -194,17 +207,33 @@ impl<'a> Printer for InteractivePrinter<'a> {
194207 _ => ("", "STDIN"),
195208 };
196209
197− writeln!(handle, "{}{}", prefix, self.colors.filename.paint(name))?;
210+ let mode = if self.content_type.is_binary() {
211+ " <BINARY>"
212+ } else {
213+ ""
214+ };
215+
216+ writeln!(
217+ handle,
218+ "{}{}{}",
219+ prefix,
220+ self.colors.filename.paint(name),
221+ mode
222+ )?;
198223
199224 if self.config.output_components.grid() {
200− self.print_horizontal_line(handle, '┼')?;
225+ if self.content_type.is_text() {
226+ self.print_horizontal_line(handle, '┼')?;
227+ } else {
228+ self.print_horizontal_line(handle, '┴')?;
229+ }
201230 }
202231
203232 Ok(())
204233 }
205234
206235 fn print_footer(&mut self, handle: &mut Write) -> Result<()> {
207− if self.config.output_components.grid() {
236+ if self.config.output_components.grid() && self.content_type.is_text() {
208237 self.print_horizontal_line(handle, '┴')
209238 } else {
210239 Ok(())
@@ -219,7 +248,15 @@ impl<'a> Printer for InteractivePrinter<'a> {
219248 line_buffer: &[u8],
220249 ) -> Result<()> {
221250 let line = String::from_utf8_lossy(&line_buffer).to_string();
222− let regions = self.highlighter.highlight(line.as_ref());
251+ let regions = {
252+ let highlighter = match self.highlighter {
253+ Some(ref mut highlighter) => highlighter,
254+ _ => {
255+ return Ok(());
256+ }
257+ };
258+ highlighter.highlight(line.as_ref())
259+ };
223260
224261 if out_of_range {
225262 return Ok(());