Skip to content

Commit

Permalink
apply icons_format only once in the begining
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Verevkin committed Feb 25, 2021
1 parent b02f464 commit c03d3bc
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ use crate::themes::Theme;
pub struct SharedConfig {
pub theme: Rc<Theme>,
icons: Rc<HashMap<String, String>>,
icons_format: String,
pub scrolling: Scrolling,
}

impl SharedConfig {
pub fn new(config: &Config) -> Self {
let mut icons = config.icons.clone();
// Apply `icons_format`
for icon in icons.values_mut() {
*icon = config.icons_format.replace("{icon}", icon);
}
Self {
theme: Rc::new(config.theme.clone()),
icons: Rc::new(config.icons.clone()),
icons_format: config.icons_format.clone(),
icons: Rc::new(icons),
scrolling: config.scrolling,
}
}
Expand Down Expand Up @@ -59,12 +62,8 @@ impl SharedConfig {
}

pub fn get_icon(&self, icon: &str) -> Option<String> {
// TODO: return Sting instead of Option
Some(
self.icons_format
.clone()
.replace("{icon}", self.icons.get(icon).unwrap_or(&String::default())),
)
// TODO return `Option<&String>`
self.icons.get(icon).cloned()
}
}

Expand All @@ -73,7 +72,6 @@ impl Default for SharedConfig {
Self {
theme: Rc::new(Theme::default()),
icons: Rc::new(icons::default()),
icons_format: " {icon} ".to_string(),
scrolling: Scrolling::default(),
}
}
Expand All @@ -84,7 +82,6 @@ impl Clone for SharedConfig {
Self {
theme: Rc::clone(&self.theme),
icons: Rc::clone(&self.icons),
icons_format: self.icons_format.clone(),
scrolling: self.scrolling,
}
}
Expand Down

0 comments on commit c03d3bc

Please sign in to comment.