From 17284226b28b6d172fc5af30d1614fa0a70b1bd5 Mon Sep 17 00:00:00 2001 From: rhysd Date: Thu, 28 Nov 2024 20:10:47 +0900 Subject: [PATCH] replace a macro with closure --- gen/src/airline.rs | 106 +++++++++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 51 deletions(-) diff --git a/gen/src/airline.rs b/gen/src/airline.rs index 1fbf490..0770ba5 100644 --- a/gen/src/airline.rs +++ b/gen/src/airline.rs @@ -24,59 +24,63 @@ pub struct AirlineTheme<'a> { impl<'a> AirlineTheme<'a> { pub fn new(palette: &'a Palette) -> Self { // Note: Pairs of strings are color names of (fg, bg) - Self { - palette, - modes: { - let mut m = HashMap::new(); - - macro_rules! mode_colors { - ($name:ident { $($n:ident: $e:expr,)+ }) => { - assert_eq!(m.insert(stringify!($name), ModeColors { $($n: $e,)+ }), None) - }; - } + let mut modes = HashMap::new(); + let mut mode_colors = |name, colors| assert_eq!(modes.insert(name, colors), None); - mode_colors!(normal { - label: ("bg", "gold"), - info: ("gold", "hiddenfg"), - main: ("yellow", "bglight"), - modified: Some("green"), - modified_main: Some("whitegreen"), - }); - - mode_colors!(insert { - label: ("bg", "skyblue"), - info: ("skyblue", "hiddenfg"), - main: ("whiteblue", "bglight"), - modified: None, - modified_main: None, - }); - - mode_colors!(visual { - label: ("bg", "kakezakura"), - info: ("kakezakura", "hiddenfg"), - main: ("whitepink", "bglight"), - modified: Some("sakura"), - modified_main: None, - }); - - mode_colors!(replace { - label: ("bg", "red"), - info: ("red", "hiddenfg"), - main: ("whitered", "bglight"), - modified: Some("crimson"), - modified_main: None, - }); - - mode_colors!(inactive { - label: ("weakfg", "bglight"), - info: ("weakfg", "bglight"), - main: ("weakfg", "bglight"), - modified: None, - modified_main: None, - }); - - m + mode_colors( + "normal", + ModeColors { + label: ("bg", "gold"), + info: ("gold", "hiddenfg"), + main: ("yellow", "bglight"), + modified: Some("green"), + modified_main: Some("whitegreen"), }, + ); + mode_colors( + "insert", + ModeColors { + label: ("bg", "skyblue"), + info: ("skyblue", "hiddenfg"), + main: ("whiteblue", "bglight"), + modified: None, + modified_main: None, + }, + ); + mode_colors( + "visual", + ModeColors { + label: ("bg", "kakezakura"), + info: ("kakezakura", "hiddenfg"), + main: ("whitepink", "bglight"), + modified: Some("sakura"), + modified_main: None, + }, + ); + mode_colors( + "replace", + ModeColors { + label: ("bg", "red"), + info: ("red", "hiddenfg"), + main: ("whitered", "bglight"), + modified: Some("crimson"), + modified_main: None, + }, + ); + mode_colors( + "inactive", + ModeColors { + label: ("weakfg", "bglight"), + info: ("weakfg", "bglight"), + main: ("weakfg", "bglight"), + modified: None, + modified_main: None, + }, + ); + + Self { + palette, + modes, paste: "mikan", info_mod: "hiddenfg", error: ("bg", "red"),