From 3015ebfba1c1e95f8fd664a7cd9c7cbbd7bc3dcf Mon Sep 17 00:00:00 2001 From: Tom Milligan Date: Mon, 12 Oct 2020 08:40:01 +0100 Subject: [PATCH] disable rule when grid enabled, and print warning --- src/bin/bat/app.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 8249e3c9..8d09618c 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -288,8 +288,8 @@ impl App { fn style_components(&self) -> Result { let matches = &self.matches; - Ok(StyleComponents( - if matches.value_of("decorations") == Some("never") { + let mut styled_components = + StyleComponents(if matches.value_of("decorations") == Some("never") { HashSet::new() } else if matches.is_present("number") { [StyleComponent::LineNumbers].iter().cloned().collect() @@ -323,7 +323,17 @@ impl App { acc.extend(components.iter().cloned()); acc }) - }, - )) + }); + + // If `grid` is set, remove `rule` as it is a subset of `grid`, and print a warning. + if styled_components.grid() && styled_components.0.remove(&StyleComponent::Rule) { + use ansi_term::Colour::Yellow; + eprintln!( + "{}: Style 'rule' is a subset of style 'grid', 'rule' will not be visible.", + Yellow.paint("[bat warning]"), + ); + } + + Ok(styled_components) } }