@@ -27,14 +27,14 @@ use crate::decorations::{Decoration, GridBorderDecoration, LineNumberDecoration}
2727#[cfg(feature = "git")]
2828use crate::diff::{get_git_diff, LineChanges};
2929use crate::errors::*;
30−use crate::input::{Input, InputReader};
30+use crate::input::{Input, InputDescription, InputReader};
3131use crate::line_range::RangeCheckResult;
3232use crate::preprocessor::{expand_tabs, replace_nonprintable};
3333use crate::terminal::{as_terminal_escaped, to_ansi_color};
3434use crate::wrap::WrappingMode;
3535
3636pub trait Printer {
37− fn print_header(&mut self, handle: &mut dyn Write, file: &Input) -> Result<()>;
37+ fn print_header(&mut self, handle: &mut dyn Write, input: &InputDescription) -> Result<()>;
3838 fn print_footer(&mut self, handle: &mut dyn Write) -> Result<()>;
3939
4040 fn print_snip(&mut self, handle: &mut dyn Write) -> Result<()>;
@@ -57,7 +57,7 @@ impl SimplePrinter {
5757}
5858
5959impl Printer for SimplePrinter {
60− fn print_header(&mut self, _handle: &mut dyn Write, _file: &Input) -> Result<()> {
60+ fn print_header(&mut self, _handle: &mut dyn Write, input: &InputDescription) -> Result<()> {
6161 Ok(())
6262 }
6363
@@ -101,7 +101,7 @@ impl<'a> InteractivePrinter<'a> {
101101 pub fn new(
102102 config: &'a Config,
103103 assets: &'a HighlightingAssets,
104− file: &Input,
104+ input: &Input,
105105 reader: &mut InputReader,
106106 ) -> Self {
107107 let theme = assets.get_theme(&config.theme);
@@ -160,14 +160,14 @@ impl<'a> InteractivePrinter<'a> {
160160 #[cfg(feature = "git")]
161161 {
162162 if config.style_components.changes() {
163− if let Input::Ordinary(ofile) = file {
163+ if let Input::Ordinary(ofile) = input {
164164 line_changes = get_git_diff(ofile.provided_path());
165165 }
166166 }
167167 }
168168
169169 // Determine the type of syntax for highlighting
170− let syntax = assets.get_syntax(config.language, file, reader, &config.syntax_mapping);
170+ let syntax = assets.get_syntax(config.language, input, reader, &config.syntax_mapping);
171171 Some(HighlightLines::new(syntax, theme))
172172 };
173173
@@ -230,32 +230,20 @@ impl<'a> InteractivePrinter<'a> {
230230}
231231
232232impl<'a> Printer for InteractivePrinter<'a> {
233− fn print_header(&mut self, handle: &mut dyn Write, file: &Input) -> Result<()> {
233+ fn print_header(
234+ &mut self,
235+ handle: &mut dyn Write,
236+ description: &InputDescription,
237+ ) -> Result<()> {
234238 if !self.config.style_components.header() {
235239 if Some(ContentType::BINARY) == self.content_type && !self.config.show_nonprintable {
236− let input = match file {
237− Input::Ordinary(ofile) => {
238− format!("file '{}'", &ofile.provided_path().to_string_lossy())
239− }
240− Input::StdIn(Some(name)) => format!(
241− "STDIN (with name '{}')",
242− name.to_string_lossy().into_owned()
243− ),
244− Input::StdIn(None) => "STDIN".to_owned(),
245− Input::ThemePreviewFile => "".to_owned(),
246− Input::FromReader(_, Some(name)) => {
247− format!("file '{}'", name.to_string_lossy())
248− }
249− Input::FromReader(_, None) => "READER".to_owned(),
250− };
251−
252240 writeln!(
253241 handle,
254242 "{}: Binary content from {} will not be printed to the terminal \
255243 (but will be present if the output of 'bat' is piped). You can use 'bat -A' \
256244 to show the binary file contents.",
257245 Yellow.paint("[bat warning]"),
258− input
246+ description.full,
259247 )?;
260248 } else {
261249 if self.config.style_components.grid() {
@@ -280,20 +268,6 @@ impl<'a> Printer for InteractivePrinter<'a> {
280268 write!(handle, "{}", " ".repeat(self.panel_width))?;
281269 }
282270
283− let (prefix, name) = match file {
284− Input::Ordinary(ofile) => (
285− "File: ",
286− Cow::from(ofile.provided_path().to_string_lossy().to_owned()),
287− ),
288− Input::StdIn(Some(name)) => ("File: ", Cow::from(name.to_string_lossy().to_owned())),
289− Input::StdIn(None) => ("File: ", Cow::from("STDIN".to_owned())),
290− Input::ThemePreviewFile => ("", Cow::from("")),
291− Input::FromReader(_, Some(name)) => {
292− ("File: ", Cow::from(name.to_string_lossy().to_owned()))
293− }
294− Input::FromReader(_, None) => ("File: ", Cow::from("READER".to_owned())),
295− };
296−
297271 let mode = match self.content_type {
298272 Some(ContentType::BINARY) => " <BINARY>",
299273 Some(ContentType::UTF_16LE) => " <UTF-16LE>",
@@ -305,8 +279,8 @@ impl<'a> Printer for InteractivePrinter<'a> {
305279 writeln!(
306280 handle,
307281 "{}{}{}",
308− prefix,
309− self.colors.filename.paint(name),
282+ description.prefix,
283+ self.colors.filename.paint(&description.name),
310284 mode
311285 )?;
312286