1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-12 00:02:28 +01:00

Moved user_provided_filename to be contained within OrdinaryFile struct

This commit is contained in:
Kyle Criddle
2020-04-04 18:49:55 -06:00
committed by David Peter
parent a3f8140fbe
commit 04fa84aea7
9 changed files with 143 additions and 127 deletions

View File

@@ -34,12 +34,7 @@ use crate::terminal::{as_terminal_escaped, to_ansi_color};
use crate::wrap::OutputWrap;
pub trait Printer {
fn print_header(
&mut self,
handle: &mut dyn Write,
file: InputFile,
file_name: Option<&str>,
) -> Result<()>;
fn print_header(&mut self, handle: &mut dyn Write, file: InputFile) -> Result<()>;
fn print_footer(&mut self, handle: &mut dyn Write) -> Result<()>;
fn print_snip(&mut self, handle: &mut dyn Write) -> Result<()>;
@@ -62,12 +57,7 @@ impl SimplePrinter {
}
impl Printer for SimplePrinter {
fn print_header(
&mut self,
_handle: &mut dyn Write,
_file: InputFile,
_file_name: Option<&str>,
) -> Result<()> {
fn print_header(&mut self, _handle: &mut dyn Write, _file: InputFile) -> Result<()> {
Ok(())
}
@@ -112,7 +102,6 @@ impl<'a> InteractivePrinter<'a> {
config: &'a Config,
assets: &'a HighlightingAssets,
file: InputFile,
file_name: Option<&str>,
reader: &mut InputFileReader,
) -> Self {
let theme = assets.get_theme(&config.theme);
@@ -171,20 +160,14 @@ impl<'a> InteractivePrinter<'a> {
#[cfg(feature = "git")]
{
if config.style_components.changes() {
if let InputFile::Ordinary(filename) = file {
line_changes = get_git_diff(filename);
if let InputFile::Ordinary(ofile) = file {
line_changes = get_git_diff(ofile.filename());
}
}
}
// Determine the type of syntax for highlighting
let syntax = assets.get_syntax(
config.language,
file,
file_name,
reader,
&config.syntax_mapping,
);
let syntax = assets.get_syntax(config.language, file, reader, &config.syntax_mapping);
Some(HighlightLines::new(syntax, theme))
};
@@ -247,20 +230,16 @@ impl<'a> InteractivePrinter<'a> {
}
impl<'a> Printer for InteractivePrinter<'a> {
fn print_header(
&mut self,
handle: &mut dyn Write,
file: InputFile,
file_name: Option<&str>,
) -> Result<()> {
fn print_header(&mut self, handle: &mut dyn Write, file: InputFile) -> Result<()> {
if !self.config.style_components.header() {
if Some(ContentType::BINARY) == self.content_type && !self.config.show_nonprintable {
let input = match file {
InputFile::Ordinary(filename) => format!(
"file '{}'",
file_name.unwrap_or(&filename.to_string_lossy())
),
_ => file_name.unwrap_or("STDIN").to_owned(),
InputFile::Ordinary(ofile) => {
format!("file '{}'", &ofile.filename().to_string_lossy())
}
InputFile::StdIn(Some(name)) => name.to_str().unwrap().to_string(),
InputFile::StdIn(None) => "STDIN".to_owned(),
InputFile::ThemePreviewFile => "".to_owned(),
};
writeln!(
@@ -295,11 +274,15 @@ impl<'a> Printer for InteractivePrinter<'a> {
}
let (prefix, name) = match file {
InputFile::Ordinary(filename) => (
InputFile::Ordinary(ofile) => (
"File: ",
Cow::from(file_name.unwrap_or(&filename.to_string_lossy()).to_owned()),
Cow::from(ofile.filename().to_string_lossy().to_owned()),
),
_ => ("File: ", Cow::from(file_name.unwrap_or("STDIN").to_owned())),
InputFile::StdIn(Some(name)) => {
("File: ", Cow::from(name.to_string_lossy().to_owned()))
}
InputFile::StdIn(None) => ("File: ", Cow::from("STDIN".to_owned())),
InputFile::ThemePreviewFile => ("", Cow::from("")),
};
let mode = match self.content_type {