diff --git a/src/assets.rs b/src/assets.rs index 734c6d20..5e0c0644 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -11,6 +11,7 @@ use syntect::parsing::{SyntaxReference, SyntaxSet, SyntaxSetBuilder}; use path_abs::PathAbs; use crate::assets_metadata::AssetsMetadata; +use crate::bat_warning; use crate::error::*; use crate::input::{InputReader, OpenedInput, OpenedInputKind}; use crate::syntax_mapping::{MappingTarget, SyntaxMapping}; @@ -190,21 +191,11 @@ impl HighlightingAssets { Some(theme) => theme, None => { if theme == "ansi-light" || theme == "ansi-dark" { - use ansi_term::Colour::Yellow; - eprintln!( - "{}: Theme '{}' is deprecated, using 'ansi' instead.", - Yellow.paint("[bat warning]"), - theme - ); + bat_warning!("Theme '{}' is deprecated, using 'ansi' instead.", theme); return self.get_theme("ansi"); } if theme != "" { - use ansi_term::Colour::Yellow; - eprintln!( - "{}: Unknown theme '{}', using default.", - Yellow.paint("[bat warning]"), - theme - ); + bat_warning!("Unknown theme '{}', using default.", theme) } &self.theme_set.themes[self.fallback_theme.unwrap_or_else(|| Self::default_theme())] } diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index c7b9d81d..3d0df0ec 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -16,6 +16,7 @@ use console::Term; use crate::input::{new_file_input, new_stdin_input}; use bat::{ assets::HighlightingAssets, + bat_warning, config::{Config, VisibleLines}, error::*, input::Input, @@ -322,11 +323,7 @@ impl App { // 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]"), - ); + bat_warning!("Style 'rule' is a subset of style 'grid', 'rule' will not be visible."); } Ok(styled_components) diff --git a/src/lib.rs b/src/lib.rs index 6d6dd206..d0d1fe0c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,6 +19,8 @@ //! .unwrap(); //! ``` +mod macros; + pub mod assets; pub mod assets_metadata; pub mod config; diff --git a/src/macros.rs b/src/macros.rs new file mode 100644 index 00000000..beb63ea7 --- /dev/null +++ b/src/macros.rs @@ -0,0 +1,7 @@ +#[macro_export] +macro_rules! bat_warning { + ($($arg:tt)*) => ({ + use ansi_term::Colour::Yellow; + eprintln!("{}: {}", Yellow.paint("[bat warning]"), format!($($arg)*)); + }) +}