on master help sign in
Introduce bat_warning! helper macro
47bb4a9Martin Nordholts
src/assets.rs+3−12
@@ -11,6 +11,7 @@ use syntect::parsing::{SyntaxReference, SyntaxSet, SyntaxSetBuilder};
11use path_abs::PathAbs;
11use path_abs::PathAbs;
12
12
13use crate::assets_metadata::AssetsMetadata;
13use crate::assets_metadata::AssetsMetadata;
14+use crate::bat_warning;
14use crate::error::*;
15use crate::error::*;
15use crate::input::{InputReader, OpenedInput, OpenedInputKind};
16use crate::input::{InputReader, OpenedInput, OpenedInputKind};
16use crate::syntax_mapping::{MappingTarget, SyntaxMapping};
17use crate::syntax_mapping::{MappingTarget, SyntaxMapping};
@@ -190,21 +191,11 @@ impl HighlightingAssets {
190 Some(theme) => theme,
191 Some(theme) => theme,
191 None => {
192 None => {
192 if theme == "ansi-light" || theme == "ansi-dark" {
193 if theme == "ansi-light" || theme == "ansi-dark" {
193− use ansi_term::Colour::Yellow;
194− eprintln!(
195− "{}: Theme '{}' is deprecated, using 'ansi' instead.",
194+ bat_warning!("Theme '{}' is deprecated, using 'ansi' instead.", theme);
196− Yellow.paint("[bat warning]"),
197− theme
198− );
199 return self.get_theme("ansi");
195 return self.get_theme("ansi");
200 }
196 }
201 if theme != "" {
197 if theme != "" {
202− use ansi_term::Colour::Yellow;
203− eprintln!(
204− "{}: Unknown theme '{}', using default.",
198+ bat_warning!("Unknown theme '{}', using default.", theme)
205− Yellow.paint("[bat warning]"),
206− theme
207− );
208 }
199 }
209 &self.theme_set.themes[self.fallback_theme.unwrap_or_else(|| Self::default_theme())]
200 &self.theme_set.themes[self.fallback_theme.unwrap_or_else(|| Self::default_theme())]
210 }
201 }
src/bin/bat/app.rs+2−5
@@ -16,6 +16,7 @@ use console::Term;
16use crate::input::{new_file_input, new_stdin_input};
16use crate::input::{new_file_input, new_stdin_input};
17use bat::{
17use bat::{
18 assets::HighlightingAssets,
18 assets::HighlightingAssets,
19+ bat_warning,
19 config::{Config, VisibleLines},
20 config::{Config, VisibleLines},
20 error::*,
21 error::*,
21 input::Input,
22 input::Input,
@@ -322,11 +323,7 @@ impl App {
322
323
323 // If `grid` is set, remove `rule` as it is a subset of `grid`, and print a warning.
324 // If `grid` is set, remove `rule` as it is a subset of `grid`, and print a warning.
324 if styled_components.grid() && styled_components.0.remove(&StyleComponent::Rule) {
325 if styled_components.grid() && styled_components.0.remove(&StyleComponent::Rule) {
325− use ansi_term::Colour::Yellow;
326− eprintln!(
327− "{}: Style 'rule' is a subset of style 'grid', 'rule' will not be visible.",
326+ bat_warning!("Style 'rule' is a subset of style 'grid', 'rule' will not be visible.");
328− Yellow.paint("[bat warning]"),
329− );
330 }
327 }
331
328
332 Ok(styled_components)
329 Ok(styled_components)
src/lib.rs+2
@@ -19,6 +19,8 @@
19//! .unwrap();
19//! .unwrap();
20//! ```
20//! ```
21
21
22+mod macros;
23+
22pub mod assets;
24pub mod assets;
23pub mod assets_metadata;
25pub mod assets_metadata;
24pub mod config;
26pub mod config;
src/macros.rsnew file+7
@@ -0,0 +1,7 @@
1+#[macro_export]
2+macro_rules! bat_warning {
3+ ($($arg:tt)*) => ({
4+ use ansi_term::Colour::Yellow;
5+ eprintln!("{}: {}", Yellow.paint("[bat warning]"), format!($($arg)*));
6+ })
7+}