@@ -34,7 +34,12 @@ use crate::terminal::{as_terminal_escaped, to_ansi_color};
34use crate::wrap::OutputWrap;
34use crate::wrap::OutputWrap;
36pub trait Printer {
36pub trait Printer {
37− fn print_header(&mut self, handle: &mut dyn Write, file: InputFile) -> Result<()>;
39+ handle: &mut dyn Write,
41+ file_name: Option<&str>,
38 fn print_footer(&mut self, handle: &mut dyn Write) -> Result<()>;
43 fn print_footer(&mut self, handle: &mut dyn Write) -> Result<()>;
40 fn print_snip(&mut self, handle: &mut dyn Write) -> Result<()>;
45 fn print_snip(&mut self, handle: &mut dyn Write) -> Result<()>;
@@ -57,7 +62,12 @@ impl SimplePrinter {
59impl Printer for SimplePrinter {
64impl Printer for SimplePrinter {
60− fn print_header(&mut self, _handle: &mut dyn Write, _file: InputFile) -> Result<()> {
67+ _handle: &mut dyn Write,
69+ _file_name: Option<&str>,
@@ -224,14 +234,20 @@ impl<'a> InteractivePrinter<'a> {
226impl<'a> Printer for InteractivePrinter<'a> {
236impl<'a> Printer for InteractivePrinter<'a> {
227− fn print_header(&mut self, handle: &mut dyn Write, file: InputFile) -> Result<()> {
239+ handle: &mut dyn Write,
241+ file_name: Option<&str>,
228 if !self.config.style_components.header() {
243 if !self.config.style_components.header() {
229 if Some(ContentType::BINARY) == self.content_type && !self.config.show_nonprintable {
244 if Some(ContentType::BINARY) == self.content_type && !self.config.show_nonprintable {
230 let input = match file {
245 let input = match file {
231− InputFile::Ordinary(filename) => {
246+ InputFile::Ordinary(filename) => format!(
232− format!("file '{}'", filename.to_string_lossy())
248+ file_name.unwrap_or(&filename.to_string_lossy())
234− _ => "STDIN".into(),
250+ _ => file_name.unwrap_or("STDIN").to_owned(),
237 writeln!(
253 writeln!(
@@ -266,8 +282,11 @@ impl<'a> Printer for InteractivePrinter<'a> {
268 let (prefix, name) = match file {
284 let (prefix, name) = match file {
269− InputFile::Ordinary(filename) => ("File: ", filename.to_string_lossy()),
285+ InputFile::Ordinary(filename) => (
287+ Cow::from(file_name.unwrap_or(&filename.to_string_lossy()).to_owned()),
270− _ => ("", Cow::from("STDIN")),
289+ _ => ("File: ", Cow::from(file_name.unwrap_or("STDIN").to_owned())),
273 let mode = match self.content_type {
292 let mode = match self.content_type {