1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-01 10:52:24 +01:00

Merge remote-tracking branch 'origin/master' into fix-1063

This commit is contained in:
Martin Nordholts
2021-01-10 11:56:03 +01:00
22 changed files with 323 additions and 106 deletions

View File

@@ -150,10 +150,10 @@ impl App {
wrapping_mode: if self.interactive_output || maybe_term_width.is_some() {
match self.matches.value_of("wrap") {
Some("character") => WrappingMode::Character,
Some("never") => WrappingMode::NoWrapping,
Some("never") => WrappingMode::NoWrapping(true),
Some("auto") | None => {
if style_components.plain() {
WrappingMode::NoWrapping
WrappingMode::NoWrapping(false)
} else {
WrappingMode::Character
}
@@ -163,7 +163,7 @@ impl App {
} else {
// We don't have the tty width when piping to another program.
// There's no point in wrapping when this is the case.
WrappingMode::NoWrapping
WrappingMode::NoWrapping(false)
},
colored_output: self.matches.is_present("force-colorization")
|| match self.matches.value_of("color") {

View File

@@ -2,7 +2,7 @@ use bat::input::Input;
use std::ffi::OsStr;
pub fn new_file_input<'a>(file: &'a OsStr, name: Option<&'a OsStr>) -> Input<'a> {
named(Input::ordinary_file(file), name.or_else(|| Some(file)))
named(Input::ordinary_file(file), name.or(Some(file)))
}
pub fn new_stdin_input(name: Option<&OsStr>) -> Input {

View File

@@ -205,7 +205,7 @@ pub fn list_themes(cfg: &Config) -> Result<()> {
and are added to the cache with `bat cache --build`. \
For more information, see:\n\n \
https://github.com/sharkdp/bat#adding-new-themes",
config_file().join("themes").to_string_lossy()
PROJECT_DIRS.config_dir().join("themes").to_string_lossy()
)?;
} else {
for theme in assets.themes() {
@@ -237,10 +237,10 @@ fn run() -> Result<bool> {
.info(EnvironmentVariables::list(&[
"SHELL",
"PAGER",
"BAT_PAGER",
"BAT_CACHE_PATH",
"BAT_CONFIG_PATH",
"BAT_OPTS",
"BAT_PAGER",
"BAT_STYLE",
"BAT_TABS",
"BAT_THEME",
@@ -248,6 +248,7 @@ fn run() -> Result<bool> {
"XDG_CACHE_HOME",
"COLORTERM",
"NO_COLOR",
"MANPAGER",
]))
.info(FileContent::new("Config file", config_file()))
.info(CompileTimeInformation::default())

View File

@@ -137,11 +137,7 @@ impl<'a> Input<'a> {
}
pub fn is_stdin(&self) -> bool {
if let InputKind::StdIn = self.kind {
true
} else {
false
}
matches!(self.kind, InputKind::StdIn)
}
pub fn with_name(mut self, provided_name: Option<&OsStr>) -> Self {

View File

@@ -81,7 +81,7 @@ impl OutputType {
p.arg("--quit-if-one-screen");
}
if wrapping_mode == WrappingMode::NoWrapping {
if wrapping_mode == WrappingMode::NoWrapping(true) {
p.arg("--chop-long-lines");
}
@@ -121,11 +121,7 @@ impl OutputType {
#[cfg(feature = "paging")]
pub(crate) fn is_pager(&self) -> bool {
if let OutputType::Pager(_) = self {
true
} else {
false
}
matches!(self, OutputType::Pager(_))
}
#[cfg(not(feature = "paging"))]

View File

@@ -320,6 +320,12 @@ impl<'a> PrettyPrinter<'a> {
}
}
impl Default for PrettyPrinter<'_> {
fn default() -> Self {
Self::new()
}
}
/// An input source for the pretty printer.
pub struct Input<'a> {
input: input::Input<'a>,

View File

@@ -424,7 +424,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
}
// Line contents.
if self.config.wrapping_mode == WrappingMode::NoWrapping {
if matches!(self.config.wrapping_mode, WrappingMode::NoWrapping(_)) {
let true_color = self.config.true_color;
let colored_output = self.config.colored_output;
let italics = self.config.use_italic_text;

View File

@@ -1,11 +1,12 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WrappingMode {
Character,
NoWrapping,
// The bool specifies whether wrapping has been explicitly disabled by the user via --wrap=never
NoWrapping(bool),
}
impl Default for WrappingMode {
fn default() -> Self {
WrappingMode::NoWrapping
WrappingMode::NoWrapping(false)
}
}