mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 22:47:43 +02:00
Clean up unnecessary macro use (#8607)
Some minor code cleanup. We've accumulated a few macros over the years that arguably don't need to be macros. This PR removes 4 macros by either: 1. Inlining the macro 2. Replacing the macro with a local function 3. Replacing the macro with a closure
This commit is contained in:
@ -20,22 +20,26 @@ impl From<Style> for NuStyle {
|
||||
}
|
||||
|
||||
fn style_get_attr(s: Style) -> Option<String> {
|
||||
macro_rules! check {
|
||||
($attrs:expr, $b:expr, $c:expr) => {
|
||||
if $b {
|
||||
$attrs.push($c);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let mut attrs = String::new();
|
||||
|
||||
check!(attrs, s.is_blink, 'l');
|
||||
check!(attrs, s.is_bold, 'b');
|
||||
check!(attrs, s.is_dimmed, 'd');
|
||||
check!(attrs, s.is_reverse, 'r');
|
||||
check!(attrs, s.is_strikethrough, 's');
|
||||
check!(attrs, s.is_underline, 'u');
|
||||
if s.is_blink {
|
||||
attrs.push('l');
|
||||
};
|
||||
if s.is_bold {
|
||||
attrs.push('b');
|
||||
};
|
||||
if s.is_dimmed {
|
||||
attrs.push('d');
|
||||
};
|
||||
if s.is_reverse {
|
||||
attrs.push('r');
|
||||
};
|
||||
if s.is_strikethrough {
|
||||
attrs.push('s');
|
||||
};
|
||||
if s.is_underline {
|
||||
attrs.push('u');
|
||||
};
|
||||
|
||||
if attrs.is_empty() {
|
||||
None
|
||||
|
@ -21,13 +21,6 @@ pub enum ComputableStyle {
|
||||
Closure(Value),
|
||||
}
|
||||
|
||||
// macro used for adding initial values to the style hashmap
|
||||
macro_rules! initial {
|
||||
($a:expr, $b:expr) => {
|
||||
($a.to_string(), ComputableStyle::Static($b))
|
||||
};
|
||||
}
|
||||
|
||||
// An alias for the mapping used internally by StyleComputer.
|
||||
pub type StyleMapping = HashMap<String, ComputableStyle>;
|
||||
//
|
||||
@ -153,6 +146,12 @@ impl<'a> StyleComputer<'a> {
|
||||
pub fn from_config(engine_state: &'a EngineState, stack: &'a Stack) -> StyleComputer<'a> {
|
||||
let config = engine_state.get_config();
|
||||
|
||||
macro_rules! initial {
|
||||
($a:expr, $b:expr) => {
|
||||
($a.to_string(), ComputableStyle::Static($b))
|
||||
};
|
||||
}
|
||||
|
||||
// Create the hashmap
|
||||
let mut map: StyleMapping = HashMap::from([
|
||||
initial!("separator", Color::White.normal()),
|
||||
|
Reference in New Issue
Block a user