From 5d425609a869421d7168621d94bb9867028471a1 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 | 102 ++++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 47 deletions(-) diff --git a/gen/src/airline.rs b/gen/src/airline.rs index 1fbf490..d9ba65a 100644 --- a/gen/src/airline.rs +++ b/gen/src/airline.rs @@ -24,59 +24,67 @@ 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) - }; - } - - mode_colors!(normal { - label: ("bg", "gold"), - info: ("gold", "hiddenfg"), - main: ("yellow", "bglight"), - modified: Some("green"), - modified_main: Some("whitegreen"), - }); + let mut modes = HashMap::new(); + let mut mode_colors = |name, colors| assert_eq!(modes.insert(name, colors), None); - mode_colors!(insert { - label: ("bg", "skyblue"), - info: ("skyblue", "hiddenfg"), - main: ("whiteblue", "bglight"), - modified: None, - modified_main: None, - }); + mode_colors( + "normal", + ModeColors { + label: ("bg", "gold"), + info: ("gold", "hiddenfg"), + main: ("yellow", "bglight"), + modified: Some("green"), + modified_main: Some("whitegreen"), + }, + ); - mode_colors!(visual { - label: ("bg", "kakezakura"), - info: ("kakezakura", "hiddenfg"), - main: ("whitepink", "bglight"), - modified: Some("sakura"), - modified_main: None, - }); + mode_colors( + "insert", + ModeColors { + label: ("bg", "skyblue"), + info: ("skyblue", "hiddenfg"), + main: ("whiteblue", "bglight"), + modified: None, + modified_main: None, + }, + ); - mode_colors!(replace { - label: ("bg", "red"), - info: ("red", "hiddenfg"), - main: ("whitered", "bglight"), - modified: Some("crimson"), - modified_main: None, - }); + mode_colors( + "visual", + ModeColors { + label: ("bg", "kakezakura"), + info: ("kakezakura", "hiddenfg"), + main: ("whitepink", "bglight"), + modified: Some("sakura"), + modified_main: None, + }, + ); - mode_colors!(inactive { - label: ("weakfg", "bglight"), - info: ("weakfg", "bglight"), - main: ("weakfg", "bglight"), - modified: None, - modified_main: None, - }); + mode_colors( + "replace", + ModeColors { + label: ("bg", "red"), + info: ("red", "hiddenfg"), + main: ("whitered", "bglight"), + modified: Some("crimson"), + modified_main: None, + }, + ); - m + 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"),