Skip to content

Commit

Permalink
add "material-nf" icon set, add icons_format config option
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Verevkin committed Feb 24, 2021
1 parent ffc2c38 commit 3665743
Show file tree
Hide file tree
Showing 2 changed files with 358 additions and 266 deletions.
27 changes: 21 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ use crate::icons;
use crate::input::MouseButton;
use crate::themes::Theme;

////////////////

#[derive(Debug)]
pub struct SharedConfig {
pub theme: Rc<Theme>,
pub icons: Rc<HashMap<String, String>>,
icons: Rc<HashMap<String, String>>,
icons_format: String,
pub scrolling: Scrolling,
}

Expand All @@ -28,6 +27,7 @@ impl SharedConfig {
Self {
theme: Rc::new(config.theme.clone()),
icons: Rc::new(config.icons.clone()),
icons_format: config.icons_format.clone(),
scrolling: config.scrolling,
}
}
Expand Down Expand Up @@ -59,7 +59,12 @@ impl SharedConfig {
}

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

Expand All @@ -68,6 +73,7 @@ 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 @@ -78,13 +84,12 @@ impl Clone for SharedConfig {
Self {
theme: Rc::clone(&self.theme),
icons: Rc::clone(&self.icons),
icons_format: self.icons_format.clone(),
scrolling: self.scrolling,
}
}
}

///////////////////

#[derive(Deserialize, Debug, Clone)]
pub struct Config {
#[serde(default = "icons::default", deserialize_with = "deserialize_icons")]
Expand All @@ -93,6 +98,9 @@ pub struct Config {
#[serde(default = "Theme::default")]
pub theme: Theme,

#[serde(default = "Config::default_icons_format")]
pub icons_format: String,

#[serde(default = "Scrolling::default")]
pub scrolling: Scrolling,
/// Direction of scrolling, "natural" or "reverse".
Expand All @@ -104,11 +112,18 @@ pub struct Config {
pub blocks: Vec<(String, value::Value)>,
}

impl Config {
fn default_icons_format() -> String {
" {icon} ".to_string()
}
}

impl Default for Config {
fn default() -> Self {
Config {
icons: icons::default(),
theme: Theme::default(),
icons_format: Config::default_icons_format(),
scrolling: Scrolling::default(),
blocks: Vec::new(),
}
Expand Down
Loading

0 comments on commit 3665743

Please sign in to comment.