Rename InputFile => Input

This commit is contained in:
sharkdp 2020-04-21 21:19:06 +02:00 committed by David Peter
parent 1dc328ad49
commit f8d0956893
9 changed files with 82 additions and 84 deletions

View File

@ -10,7 +10,7 @@ use syntect::parsing::{SyntaxReference, SyntaxSet, SyntaxSetBuilder};
use crate::assets_metadata::AssetsMetadata; use crate::assets_metadata::AssetsMetadata;
use crate::errors::*; use crate::errors::*;
use crate::inputfile::{InputFile, InputFileReader}; use crate::input::{Input, InputReader};
use crate::syntax_mapping::{MappingTarget, SyntaxMapping}; use crate::syntax_mapping::{MappingTarget, SyntaxMapping};
#[derive(Debug)] #[derive(Debug)]
@ -188,13 +188,13 @@ impl HighlightingAssets {
pub(crate) fn get_syntax( pub(crate) fn get_syntax(
&self, &self,
language: Option<&str>, language: Option<&str>,
file: &InputFile, file: &Input,
reader: &mut InputFileReader, reader: &mut InputReader,
mapping: &SyntaxMapping, mapping: &SyntaxMapping,
) -> &SyntaxReference { ) -> &SyntaxReference {
let syntax = match (language, file) { let syntax = match (language, file) {
(Some(language), _) => self.syntax_set.find_syntax_by_token(language), (Some(language), _) => self.syntax_set.find_syntax_by_token(language),
(None, InputFile::Ordinary(ofile)) => { (None, Input::Ordinary(ofile)) => {
let path = Path::new(ofile.provided_path()); let path = Path::new(ofile.provided_path());
let line_syntax = self.get_first_line_syntax(reader); let line_syntax = self.get_first_line_syntax(reader);
@ -212,14 +212,14 @@ impl HighlightingAssets {
} }
} }
} }
(None, InputFile::StdIn(None)) => String::from_utf8(reader.first_line.clone()) (None, Input::StdIn(None)) => String::from_utf8(reader.first_line.clone())
.ok() .ok()
.and_then(|l| self.syntax_set.find_syntax_by_first_line(&l)), .and_then(|l| self.syntax_set.find_syntax_by_first_line(&l)),
(None, InputFile::StdIn(Some(file_name))) => self (None, Input::StdIn(Some(file_name))) => self
.get_extension_syntax(&file_name) .get_extension_syntax(&file_name)
.or(self.get_first_line_syntax(reader)), .or(self.get_first_line_syntax(reader)),
(_, InputFile::ThemePreviewFile) => self.syntax_set.find_syntax_by_name("Rust"), (_, Input::ThemePreviewFile) => self.syntax_set.find_syntax_by_name("Rust"),
(None, InputFile::FromReader(s, _)) => None, (None, Input::FromReader(_, _)) => unimplemented!(),
}; };
syntax.unwrap_or_else(|| self.syntax_set.find_syntax_plain_text()) syntax.unwrap_or_else(|| self.syntax_set.find_syntax_plain_text())
@ -238,7 +238,7 @@ impl HighlightingAssets {
}) })
} }
fn get_first_line_syntax(&self, reader: &mut InputFileReader) -> Option<&SyntaxReference> { fn get_first_line_syntax(&self, reader: &mut InputReader) -> Option<&SyntaxReference> {
String::from_utf8(reader.first_line.clone()) String::from_utf8(reader.first_line.clone())
.ok() .ok()
.and_then(|l| self.syntax_set.find_syntax_by_first_line(&l)) .and_then(|l| self.syntax_set.find_syntax_by_first_line(&l))
@ -249,7 +249,7 @@ impl HighlightingAssets {
mod tests { mod tests {
use super::*; use super::*;
use crate::inputfile::OrdinaryFile; use crate::input::OrdinaryFile;
use std::ffi::{OsStr, OsString}; use std::ffi::{OsStr, OsString};
use std::fs::File; use std::fs::File;
@ -281,11 +281,11 @@ mod tests {
writeln!(temp_file, "{}", first_line).unwrap(); writeln!(temp_file, "{}", first_line).unwrap();
} }
let input_file = InputFile::Ordinary(OrdinaryFile::from_path(file_path.as_os_str())); let input = Input::Ordinary(OrdinaryFile::from_path(file_path.as_os_str()));
let syntax = self.assets.get_syntax( let syntax = self.assets.get_syntax(
None, None,
&input_file, &input,
&mut input_file.get_reader(io::stdin().lock()).unwrap(), &mut input.get_reader(io::stdin().lock()).unwrap(),
&self.syntax_mapping, &self.syntax_mapping,
); );
@ -305,11 +305,11 @@ mod tests {
} }
fn syntax_for_stdin_with_content(&self, file_name: &str, content: &[u8]) -> String { fn syntax_for_stdin_with_content(&self, file_name: &str, content: &[u8]) -> String {
let input_file = InputFile::StdIn(Some(OsString::from(file_name))); let input = Input::StdIn(Some(OsString::from(file_name)));
let syntax = self.assets.get_syntax( let syntax = self.assets.get_syntax(
None, None,
&input_file, &input,
&mut input_file.get_reader(content).unwrap(), &mut input.get_reader(content).unwrap(),
&self.syntax_mapping, &self.syntax_mapping,
); );
syntax.name.clone() syntax.name.clone()

View File

@ -15,8 +15,8 @@ use console::Term;
use bat::{ use bat::{
config::{ config::{
Config, HighlightedLineRanges, InputFile, LineRange, LineRanges, MappingTarget, Config, HighlightedLineRanges, Input, LineRange, LineRanges, MappingTarget, OrdinaryFile,
OrdinaryFile, PagingMode, StyleComponent, StyleComponents, SyntaxMapping, WrappingMode, PagingMode, StyleComponent, StyleComponents, SyntaxMapping, WrappingMode,
}, },
errors::*, errors::*,
HighlightingAssets, HighlightingAssets,
@ -73,7 +73,7 @@ impl App {
Ok(clap_app::build_app(interactive_output).get_matches_from(args)) Ok(clap_app::build_app(interactive_output).get_matches_from(args))
} }
pub fn config(&self, inputs: &[InputFile]) -> Result<Config> { pub fn config(&self, inputs: &[Input]) -> Result<Config> {
let style_components = self.style_components()?; let style_components = self.style_components()?;
let paging_mode = match self.matches.value_of("paging") { let paging_mode = match self.matches.value_of("paging") {
@ -84,7 +84,7 @@ impl App {
// If we have -pp as an option when in auto mode, the pager should be disabled. // If we have -pp as an option when in auto mode, the pager should be disabled.
PagingMode::Never PagingMode::Never
} else if inputs.iter().any(|f| { } else if inputs.iter().any(|f| {
if let InputFile::StdIn(None) = f { if let Input::StdIn(None) = f {
true true
} else { } else {
false false
@ -226,7 +226,7 @@ impl App {
}) })
} }
pub fn inputs(&self) -> Result<Vec<InputFile>> { pub fn inputs(&self) -> Result<Vec<Input>> {
// verify equal length of file-names and input FILEs // verify equal length of file-names and input FILEs
match self.matches.values_of("file-name") { match self.matches.values_of("file-name") {
Some(ref filenames) Some(ref filenames)
@ -251,7 +251,7 @@ impl App {
let files: Option<Vec<&OsStr>> = self.matches.values_of_os("FILE").map(|vs| vs.collect()); let files: Option<Vec<&OsStr>> = self.matches.values_of_os("FILE").map(|vs| vs.collect());
if files.is_none() { if files.is_none() {
return Ok(vec![InputFile::StdIn( return Ok(vec![Input::StdIn(
filenames_or_none.nth(0).unwrap().map(|f| f.to_owned()), filenames_or_none.nth(0).unwrap().map(|f| f.to_owned()),
)]); )]);
} }
@ -264,13 +264,13 @@ impl App {
for (input, name) in files_or_none.zip(filenames_or_none) { for (input, name) in files_or_none.zip(filenames_or_none) {
if let Some(input) = input { if let Some(input) = input {
if input.to_str().unwrap_or_default() == "-" { if input.to_str().unwrap_or_default() == "-" {
file_input.push(InputFile::StdIn(name.map(|n| n.to_owned()))); file_input.push(Input::StdIn(name.map(|n| n.to_owned())));
} else { } else {
let mut ofile = OrdinaryFile::from_path(input); let mut ofile = OrdinaryFile::from_path(input);
if let Some(path) = name { if let Some(path) = name {
ofile.set_provided_path(path); ofile.set_provided_path(path);
} }
file_input.push(InputFile::Ordinary(ofile)) file_input.push(Input::Ordinary(ofile))
} }
} }
} }

View File

@ -26,7 +26,7 @@ use clap::crate_version;
use directories::PROJECT_DIRS; use directories::PROJECT_DIRS;
use bat::{ use bat::{
config::{Config, InputFile, OrdinaryFile, StyleComponent, StyleComponents}, config::{Config, Input, OrdinaryFile, StyleComponent, StyleComponents},
errors::*, errors::*,
Controller, HighlightingAssets, Controller, HighlightingAssets,
}; };
@ -134,7 +134,7 @@ pub fn list_themes(cfg: &Config) -> Result<()> {
)?; )?;
config.theme = theme.to_string(); config.theme = theme.to_string();
Controller::new(&config, &assets) Controller::new(&config, &assets)
.run(vec![InputFile::ThemePreviewFile]) .run(vec![Input::ThemePreviewFile])
.ok(); .ok();
writeln!(stdout)?; writeln!(stdout)?;
} }
@ -147,7 +147,7 @@ pub fn list_themes(cfg: &Config) -> Result<()> {
Ok(()) Ok(())
} }
fn run_controller(inputs: Vec<InputFile>, config: &Config) -> Result<bool> { fn run_controller(inputs: Vec<Input>, config: &Config) -> Result<bool> {
let assets = assets_from_cache_or_binary()?; let assets = assets_from_cache_or_binary()?;
let controller = Controller::new(&config, &assets); let controller = Controller::new(&config, &assets);
controller.run(inputs) controller.run(inputs)
@ -167,10 +167,10 @@ fn run() -> Result<bool> {
run_cache_subcommand(cache_matches)?; run_cache_subcommand(cache_matches)?;
Ok(true) Ok(true)
} else { } else {
let inputs = vec![InputFile::Ordinary(OrdinaryFile::from_path(OsStr::new( let inputs = vec![Input::Ordinary(OrdinaryFile::from_path(OsStr::new(
"cache", "cache",
)))]; )))];
let mut config = app.config(&inputs)?; let config = app.config(&inputs)?;
run_controller(inputs, &config) run_controller(inputs, &config)
} }

View File

@ -1,5 +1,5 @@
pub use crate::inputfile::InputFile; pub use crate::input::Input;
pub use crate::inputfile::OrdinaryFile; pub use crate::input::OrdinaryFile;
pub use crate::line_range::{HighlightedLineRanges, LineRange, LineRanges}; pub use crate::line_range::{HighlightedLineRanges, LineRange, LineRanges};
pub use crate::style::{StyleComponent, StyleComponents}; pub use crate::style::{StyleComponent, StyleComponents};
pub use crate::syntax_mapping::{MappingTarget, SyntaxMapping}; pub use crate::syntax_mapping::{MappingTarget, SyntaxMapping};

View File

@ -5,7 +5,7 @@ use crate::config::Config;
#[cfg(feature = "paging")] #[cfg(feature = "paging")]
use crate::config::PagingMode; use crate::config::PagingMode;
use crate::errors::*; use crate::errors::*;
use crate::inputfile::{InputFile, InputFileReader}; use crate::input::{Input, InputReader};
use crate::line_range::{LineRanges, RangeCheckResult}; use crate::line_range::{LineRanges, RangeCheckResult};
use crate::output::OutputType; use crate::output::OutputType;
use crate::printer::{InteractivePrinter, Printer, SimplePrinter}; use crate::printer::{InteractivePrinter, Printer, SimplePrinter};
@ -20,13 +20,13 @@ impl<'b> Controller<'b> {
Controller { config, assets } Controller { config, assets }
} }
pub fn run(&self, inputs: Vec<InputFile>) -> Result<bool> { pub fn run(&self, inputs: Vec<Input>) -> Result<bool> {
self.run_with_error_handler(inputs, default_error_handler) self.run_with_error_handler(inputs, default_error_handler)
} }
pub fn run_with_error_handler( pub fn run_with_error_handler(
&self, &self,
inputs: Vec<InputFile>, inputs: Vec<Input>,
handle_error: impl Fn(&Error), handle_error: impl Fn(&Error),
) -> Result<bool> { ) -> Result<bool> {
let mut output_type; let mut output_type;
@ -39,7 +39,7 @@ impl<'b> Controller<'b> {
let mut paging_mode = self.config.paging_mode; let mut paging_mode = self.config.paging_mode;
if self.config.paging_mode != PagingMode::Never { if self.config.paging_mode != PagingMode::Never {
let call_pager = inputs.iter().any(|file| { let call_pager = inputs.iter().any(|file| {
if let InputFile::Ordinary(ofile) = file { if let Input::Ordinary(ofile) = file {
return Path::new(ofile.provided_path()).exists(); return Path::new(ofile.provided_path()).exists();
} else { } else {
return true; return true;
@ -60,8 +60,8 @@ impl<'b> Controller<'b> {
let writer = output_type.handle()?; let writer = output_type.handle()?;
let mut no_errors: bool = true; let mut no_errors: bool = true;
for input_file in inputs.into_iter() { for input in inputs.into_iter() {
match input_file.get_reader(io::stdin().lock()) { match input.get_reader(io::stdin().lock()) {
Err(error) => { Err(error) => {
handle_error(&error); handle_error(&error);
no_errors = false; no_errors = false;
@ -69,15 +69,15 @@ impl<'b> Controller<'b> {
Ok(mut reader) => { Ok(mut reader) => {
let result = if self.config.loop_through { let result = if self.config.loop_through {
let mut printer = SimplePrinter::new(); let mut printer = SimplePrinter::new();
self.print_file(reader, &mut printer, writer, &input_file) self.print_file(reader, &mut printer, writer, &input)
} else { } else {
let mut printer = InteractivePrinter::new( let mut printer = InteractivePrinter::new(
&self.config, &self.config,
&self.assets, &self.assets,
&input_file, &input,
&mut reader, &mut reader,
); );
self.print_file(reader, &mut printer, writer, &input_file) self.print_file(reader, &mut printer, writer, &input)
}; };
if let Err(error) = result { if let Err(error) = result {
@ -93,13 +93,13 @@ impl<'b> Controller<'b> {
fn print_file<'a, P: Printer>( fn print_file<'a, P: Printer>(
&self, &self,
reader: InputFileReader, reader: InputReader,
printer: &mut P, printer: &mut P,
writer: &mut dyn Write, writer: &mut dyn Write,
input_file: &InputFile, input: &Input,
) -> Result<()> { ) -> Result<()> {
if !reader.first_line.is_empty() || self.config.style_components.header() { if !reader.first_line.is_empty() || self.config.style_components.header() {
printer.print_header(writer, input_file)?; printer.print_header(writer, input)?;
} }
if !reader.first_line.is_empty() { if !reader.first_line.is_empty() {
@ -114,7 +114,7 @@ impl<'b> Controller<'b> {
&self, &self,
printer: &mut P, printer: &mut P,
writer: &mut dyn Write, writer: &mut dyn Write,
mut reader: InputFileReader, mut reader: InputReader,
line_ranges: &LineRanges, line_ranges: &LineRanges,
) -> Result<()> { ) -> Result<()> {
let mut line_buffer = Vec::new(); let mut line_buffer = Vec::new();

View File

@ -8,14 +8,14 @@ use crate::errors::*;
const THEME_PREVIEW_FILE: &[u8] = include_bytes!("../assets/theme_preview.rs"); const THEME_PREVIEW_FILE: &[u8] = include_bytes!("../assets/theme_preview.rs");
pub struct InputFileReader<'a> { pub struct InputReader<'a> {
inner: Box<dyn BufRead + 'a>, inner: Box<dyn BufRead + 'a>,
pub(crate) first_line: Vec<u8>, pub(crate) first_line: Vec<u8>,
pub(crate) content_type: Option<ContentType>, pub(crate) content_type: Option<ContentType>,
} }
impl<'a> InputFileReader<'a> { impl<'a> InputReader<'a> {
fn new<R: BufRead + 'a>(mut reader: R) -> InputFileReader<'a> { fn new<R: BufRead + 'a>(mut reader: R) -> InputReader<'a> {
let mut first_line = vec![]; let mut first_line = vec![];
reader.read_until(b'\n', &mut first_line).ok(); reader.read_until(b'\n', &mut first_line).ok();
@ -29,7 +29,7 @@ impl<'a> InputFileReader<'a> {
reader.read_until(0x00, &mut first_line).ok(); reader.read_until(0x00, &mut first_line).ok();
} }
InputFileReader { InputReader {
inner: Box::new(reader), inner: Box::new(reader),
first_line, first_line,
content_type, content_type,
@ -77,18 +77,18 @@ impl OrdinaryFile {
} }
} }
pub enum InputFile { pub enum Input {
StdIn(Option<OsString>), StdIn(Option<OsString>),
Ordinary(OrdinaryFile), Ordinary(OrdinaryFile),
FromReader(Box<dyn Read>, Option<OsString>), FromReader(Box<dyn Read>, Option<OsString>),
ThemePreviewFile, ThemePreviewFile,
} }
impl InputFile { impl Input {
pub(crate) fn get_reader<'a, R: BufRead + 'a>(&self, stdin: R) -> Result<InputFileReader<'a>> { pub(crate) fn get_reader<'a, R: BufRead + 'a>(&self, stdin: R) -> Result<InputReader<'a>> {
match self { match self {
InputFile::StdIn(_) => Ok(InputFileReader::new(stdin)), Input::StdIn(_) => Ok(InputReader::new(stdin)),
InputFile::Ordinary(ofile) => { Input::Ordinary(ofile) => {
let file = File::open(&ofile.path) let file = File::open(&ofile.path)
.map_err(|e| format!("'{}': {}", ofile.path.to_string_lossy(), e))?; .map_err(|e| format!("'{}': {}", ofile.path.to_string_lossy(), e))?;
@ -98,10 +98,10 @@ impl InputFile {
); );
} }
Ok(InputFileReader::new(BufReader::new(file))) Ok(InputReader::new(BufReader::new(file)))
} }
InputFile::ThemePreviewFile => Ok(InputFileReader::new(THEME_PREVIEW_FILE)), Input::ThemePreviewFile => Ok(InputReader::new(THEME_PREVIEW_FILE)),
InputFile::FromReader(reader, _) => unimplemented!(), //Ok(InputFileReader::new(BufReader::new(reader))), Input::FromReader(_, _) => unimplemented!(), //Ok(InputReader::new(BufReader::new(reader))),
} }
} }
} }
@ -109,7 +109,7 @@ impl InputFile {
#[test] #[test]
fn basic() { fn basic() {
let content = b"#!/bin/bash\necho hello"; let content = b"#!/bin/bash\necho hello";
let mut reader = InputFileReader::new(&content[..]); let mut reader = InputReader::new(&content[..]);
assert_eq!(b"#!/bin/bash\n", &reader.first_line[..]); assert_eq!(b"#!/bin/bash\n", &reader.first_line[..]);
@ -138,7 +138,7 @@ fn basic() {
#[test] #[test]
fn utf16le() { fn utf16le() {
let content = b"\xFF\xFE\x73\x00\x0A\x00\x64\x00"; let content = b"\xFF\xFE\x73\x00\x0A\x00\x64\x00";
let mut reader = InputFileReader::new(&content[..]); let mut reader = InputReader::new(&content[..]);
assert_eq!(b"\xFF\xFE\x73\x00\x0A\x00", &reader.first_line[..]); assert_eq!(b"\xFF\xFE\x73\x00\x0A\x00", &reader.first_line[..]);

View File

@ -8,7 +8,7 @@ pub(crate) mod controller;
mod decorations; mod decorations;
mod diff; mod diff;
pub mod errors; pub mod errors;
pub(crate) mod inputfile; pub(crate) mod input;
mod less; mod less;
pub(crate) mod line_range; pub(crate) mod line_range;
mod output; mod output;

View File

@ -2,7 +2,7 @@ use std::ffi::OsStr;
use crate::{ use crate::{
config::{ config::{
Config, HighlightedLineRanges, InputFile, LineRanges, OrdinaryFile, StyleComponents, Config, HighlightedLineRanges, Input, LineRanges, OrdinaryFile, StyleComponents,
SyntaxMapping, WrappingMode, SyntaxMapping, WrappingMode,
}, },
errors::Result, errors::Result,
@ -13,7 +13,7 @@ use crate::{
use crate::config::PagingMode; use crate::config::PagingMode;
pub struct PrettyPrinter<'a> { pub struct PrettyPrinter<'a> {
inputs: Vec<InputFile>, inputs: Vec<Input>,
config: Config<'a>, config: Config<'a>,
assets: HighlightingAssets, assets: HighlightingAssets,
} }
@ -35,7 +35,7 @@ impl<'a> PrettyPrinter<'a> {
/// Add a file which should be pretty-printed /// Add a file which should be pretty-printed
pub fn file(&mut self, path: &OsStr) -> &mut Self { pub fn file(&mut self, path: &OsStr) -> &mut Self {
self.inputs self.inputs
.push(InputFile::Ordinary(OrdinaryFile::from_path(path))); .push(Input::Ordinary(OrdinaryFile::from_path(path)));
self self
} }
@ -47,7 +47,7 @@ impl<'a> PrettyPrinter<'a> {
{ {
for path in paths { for path in paths {
self.inputs self.inputs
.push(InputFile::Ordinary(OrdinaryFile::from_path(path.as_ref()))); .push(Input::Ordinary(OrdinaryFile::from_path(path.as_ref())));
} }
self self
} }

View File

@ -27,14 +27,14 @@ use crate::decorations::{Decoration, GridBorderDecoration, LineNumberDecoration}
#[cfg(feature = "git")] #[cfg(feature = "git")]
use crate::diff::{get_git_diff, LineChanges}; use crate::diff::{get_git_diff, LineChanges};
use crate::errors::*; use crate::errors::*;
use crate::inputfile::{InputFile, InputFileReader}; use crate::input::{Input, InputReader};
use crate::line_range::RangeCheckResult; use crate::line_range::RangeCheckResult;
use crate::preprocessor::{expand_tabs, replace_nonprintable}; use crate::preprocessor::{expand_tabs, replace_nonprintable};
use crate::terminal::{as_terminal_escaped, to_ansi_color}; use crate::terminal::{as_terminal_escaped, to_ansi_color};
use crate::wrap::WrappingMode; use crate::wrap::WrappingMode;
pub trait Printer { pub trait Printer {
fn print_header(&mut self, handle: &mut dyn Write, file: &InputFile) -> Result<()>; fn print_header(&mut self, handle: &mut dyn Write, file: &Input) -> Result<()>;
fn print_footer(&mut self, handle: &mut dyn Write) -> Result<()>; fn print_footer(&mut self, handle: &mut dyn Write) -> Result<()>;
fn print_snip(&mut self, handle: &mut dyn Write) -> Result<()>; fn print_snip(&mut self, handle: &mut dyn Write) -> Result<()>;
@ -57,7 +57,7 @@ impl SimplePrinter {
} }
impl Printer for SimplePrinter { impl Printer for SimplePrinter {
fn print_header(&mut self, _handle: &mut dyn Write, _file: &InputFile) -> Result<()> { fn print_header(&mut self, _handle: &mut dyn Write, _file: &Input) -> Result<()> {
Ok(()) Ok(())
} }
@ -101,8 +101,8 @@ impl<'a> InteractivePrinter<'a> {
pub fn new( pub fn new(
config: &'a Config, config: &'a Config,
assets: &'a HighlightingAssets, assets: &'a HighlightingAssets,
file: &InputFile, file: &Input,
reader: &mut InputFileReader, reader: &mut InputReader,
) -> Self { ) -> Self {
let theme = assets.get_theme(&config.theme); let theme = assets.get_theme(&config.theme);
@ -160,7 +160,7 @@ impl<'a> InteractivePrinter<'a> {
#[cfg(feature = "git")] #[cfg(feature = "git")]
{ {
if config.style_components.changes() { if config.style_components.changes() {
if let InputFile::Ordinary(ofile) = file { if let Input::Ordinary(ofile) = file {
line_changes = get_git_diff(ofile.provided_path()); line_changes = get_git_diff(ofile.provided_path());
} }
} }
@ -230,23 +230,23 @@ impl<'a> InteractivePrinter<'a> {
} }
impl<'a> Printer for InteractivePrinter<'a> { impl<'a> Printer for InteractivePrinter<'a> {
fn print_header(&mut self, handle: &mut dyn Write, file: &InputFile) -> Result<()> { fn print_header(&mut self, handle: &mut dyn Write, file: &Input) -> Result<()> {
if !self.config.style_components.header() { if !self.config.style_components.header() {
if Some(ContentType::BINARY) == self.content_type && !self.config.show_nonprintable { if Some(ContentType::BINARY) == self.content_type && !self.config.show_nonprintable {
let input = match file { let input = match file {
InputFile::Ordinary(ofile) => { Input::Ordinary(ofile) => {
format!("file '{}'", &ofile.provided_path().to_string_lossy()) format!("file '{}'", &ofile.provided_path().to_string_lossy())
} }
InputFile::StdIn(Some(name)) => format!( Input::StdIn(Some(name)) => format!(
"STDIN (with name '{}')", "STDIN (with name '{}')",
name.to_string_lossy().into_owned() name.to_string_lossy().into_owned()
), ),
InputFile::StdIn(None) => "STDIN".to_owned(), Input::StdIn(None) => "STDIN".to_owned(),
InputFile::ThemePreviewFile => "".to_owned(), Input::ThemePreviewFile => "".to_owned(),
InputFile::FromReader(_, Some(name)) => { Input::FromReader(_, Some(name)) => {
format!("file '{}'", name.to_string_lossy()) format!("file '{}'", name.to_string_lossy())
} }
InputFile::FromReader(_, None) => "READER".to_owned(), Input::FromReader(_, None) => "READER".to_owned(),
}; };
writeln!( writeln!(
@ -281,19 +281,17 @@ impl<'a> Printer for InteractivePrinter<'a> {
} }
let (prefix, name) = match file { let (prefix, name) = match file {
InputFile::Ordinary(ofile) => ( Input::Ordinary(ofile) => (
"File: ", "File: ",
Cow::from(ofile.provided_path().to_string_lossy().to_owned()), Cow::from(ofile.provided_path().to_string_lossy().to_owned()),
), ),
InputFile::StdIn(Some(name)) => { Input::StdIn(Some(name)) => ("File: ", Cow::from(name.to_string_lossy().to_owned())),
Input::StdIn(None) => ("File: ", Cow::from("STDIN".to_owned())),
Input::ThemePreviewFile => ("", Cow::from("")),
Input::FromReader(_, Some(name)) => {
("File: ", Cow::from(name.to_string_lossy().to_owned())) ("File: ", Cow::from(name.to_string_lossy().to_owned()))
} }
InputFile::StdIn(None) => ("File: ", Cow::from("STDIN".to_owned())), Input::FromReader(_, None) => ("File: ", Cow::from("READER".to_owned())),
InputFile::ThemePreviewFile => ("", Cow::from("")),
InputFile::FromReader(_, Some(name)) => {
("File: ", Cow::from(name.to_string_lossy().to_owned()))
}
InputFile::FromReader(_, None) => ("File: ", Cow::from("READER".to_owned())),
}; };
let mode = match self.content_type { let mode = match self.content_type {