Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

## Other

- Fix Clippy lints, see #1661 (@mohamed-abdelnour)


## Syntaxes

Expand Down
2 changes: 1 addition & 1 deletion src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl HighlightingAssets {
bat_warning!("Theme '{}' is deprecated, using 'ansi' instead.", theme);
return self.get_theme("ansi");
}
if theme != "" {
if !theme.is_empty() {
bat_warning!("Unknown theme '{}', using default.", theme)
}
&self.theme_set.themes[self.fallback_theme.unwrap_or_else(|| Self::default_theme())]
Expand Down
27 changes: 15 additions & 12 deletions src/pager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,21 @@ pub(crate) fn get_pager(config_pager: Option<&str>) -> Result<Option<Pager>, Par
Some((bin, args)) => {
let kind = PagerKind::from_bin(bin);

let use_less_instead = match (&source, &kind) {
// 'more' and 'most' do not supports colors; automatically use 'less' instead
// if the problematic pager came from the generic PAGER env var
(PagerSource::EnvVarPager, PagerKind::More) => true,
(PagerSource::EnvVarPager, PagerKind::Most) => true,

// If PAGER=bat, silently use 'less' instead to prevent recursion ...
(PagerSource::EnvVarPager, PagerKind::Bat) => true,

// Never silently use less if BAT_PAGER or --pager has been specified
_ => false,
};
// Is false if the given expression does not match any of the
// patterns; this ensures 'less' is never silently used if BAT_PAGER
// or --pager has been specified.
let use_less_instead = matches!(
(&source, &kind),
// 'more' and 'most' do not supports colors; automatically use
// 'less' instead if the problematic pager came from the
// generic PAGER env var
(PagerSource::EnvVarPager, PagerKind::More)
| (PagerSource::EnvVarPager, PagerKind::Most)

// If PAGER=bat, silently use 'less' instead to prevent
// recursion ...
| (PagerSource::EnvVarPager, PagerKind::Bat)
);
Copy link
Owner

@sharkdp sharkdp May 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally think this is quite a bit harder to read now. The previous match isn't great either. Maybe this should be written with an outer if clause instead?

let use_less_instead = if source == PagerSource::EnvVarPager {
  // full comment here
  matches!(&kind, PagerKind::More | PagerKind::Most | …)
} else {
  false
};


Ok(Some(if use_less_instead {
let no_args = vec![];
Expand Down
21 changes: 11 additions & 10 deletions src/pretty_printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ pub struct PrettyPrinter<'a> {

impl<'a> PrettyPrinter<'a> {
pub fn new() -> Self {
let mut config = Config::default();

config.colored_output = true;
config.true_color = true;
let config = Config {
colored_output: true,
true_color: true,
..Default::default()
};

PrettyPrinter {
inputs: vec![],
Expand Down Expand Up @@ -335,14 +336,14 @@ impl<'a> Input<'a> {
}
}

impl<'a> Into<Input<'a>> for input::Input<'a> {
fn into(self) -> Input<'a> {
Input { input: self }
impl<'a> From<input::Input<'a>> for Input<'a> {
fn from(input: input::Input<'a>) -> Self {
Self { input }
}
}

impl<'a> Into<input::Input<'a>> for Input<'a> {
fn into(self) -> input::Input<'a> {
self.input
impl<'a> From<Input<'a>> for input::Input<'a> {
fn from(Input { input }: Input<'a>) -> Self {
input
}
}
12 changes: 8 additions & 4 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,10 @@ impl<'a> Printer for InteractivePrinter<'a> {

if text.len() != text_trimmed.len() {
if let Some(background_color) = background_color {
let mut ansi_style = Style::default();
ansi_style.background = to_ansi_color(background_color, true_color);
let ansi_style = Style {
background: to_ansi_color(background_color, true_color),
..Default::default()
};
let width = if cursor_total <= cursor_max {
cursor_max - cursor_total + 1
} else {
Expand Down Expand Up @@ -588,8 +590,10 @@ impl<'a> Printer for InteractivePrinter<'a> {
}

if let Some(background_color) = background_color {
let mut ansi_style = Style::default();
ansi_style.background = to_ansi_color(background_color, self.config.true_color);
let ansi_style = Style {
background: to_ansi_color(background_color, self.config.true_color),
..Default::default()
};

write!(
handle,
Expand Down