themes: Rename Theme struct to Themes

memfd
Manos Pitsidianakis 2020-06-02 02:47:02 +03:00
parent 5144fb6b6b
commit 9c0ee76ff4
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
4 changed files with 18 additions and 18 deletions

View File

@ -241,7 +241,7 @@ fn run_app() -> Result<()> {
return Ok(()); return Ok(());
} }
"--print-default-theme" => { "--print-default-theme" => {
print!("{}", conf::Theme::default().key_to_string("dark", false)); print!("{}", conf::Themes::default().key_to_string("dark", false));
return Ok(()); return Ok(());
} }
"--print-documentation" => { "--print-documentation" => {

View File

@ -150,7 +150,7 @@ pub struct MailUIConf {
#[serde(default)] #[serde(default)]
pub tags: TagsSettingsOverride, pub tags: TagsSettingsOverride,
#[serde(default)] #[serde(default)]
pub theme: Option<Theme>, pub themes: Option<Themes>,
#[serde(default)] #[serde(default)]
pub pgp: PGPSettingsOverride, pub pgp: PGPSettingsOverride,
} }
@ -386,11 +386,11 @@ impl FileSettings {
} }
} }
let Theme { let Themes {
light: default_light, light: default_light,
dark: default_dark, dark: default_dark,
.. ..
} = Theme::default(); } = Themes::default();
for (k, v) in default_light.into_iter() { for (k, v) in default_light.into_iter() {
if !s.terminal.themes.light.contains_key(&k) { if !s.terminal.themes.light.contains_key(&k) {
s.terminal.themes.light.insert(k, v); s.terminal.themes.light.insert(k, v);

View File

@ -22,7 +22,7 @@
//! Settings for terminal display //! Settings for terminal display
use super::deserializers::non_empty_string; use super::deserializers::non_empty_string;
use super::Theme; use super::Themes;
use super::ToggleFlag; use super::ToggleFlag;
/// Settings for terminal display /// Settings for terminal display
@ -31,7 +31,7 @@ use super::ToggleFlag;
pub struct TerminalSettings { pub struct TerminalSettings {
/// light, dark /// light, dark
pub theme: String, pub theme: String,
pub themes: Theme, pub themes: Themes,
pub ascii_drawing: bool, pub ascii_drawing: bool,
pub use_color: ToggleFlag, pub use_color: ToggleFlag,
#[serde(deserialize_with = "non_empty_string")] #[serde(deserialize_with = "non_empty_string")]
@ -42,7 +42,7 @@ impl Default for TerminalSettings {
fn default() -> Self { fn default() -> Self {
TerminalSettings { TerminalSettings {
theme: "dark".to_string(), theme: "dark".to_string(),
themes: Theme::default(), themes: Themes::default(),
ascii_drawing: false, ascii_drawing: false,
use_color: ToggleFlag::InternalVal(true), use_color: ToggleFlag::InternalVal(true),
window_title: Some("meli".to_string()), window_title: Some("meli".to_string()),

View File

@ -325,13 +325,13 @@ impl<'de> Deserialize<'de> for ThemeValue<Color> {
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Theme { pub struct Themes {
pub light: HashMap<Cow<'static, str>, ThemeAttributeInner>, pub light: HashMap<Cow<'static, str>, ThemeAttributeInner>,
pub dark: HashMap<Cow<'static, str>, ThemeAttributeInner>, pub dark: HashMap<Cow<'static, str>, ThemeAttributeInner>,
pub other_themes: HashMap<String, HashMap<Cow<'static, str>, ThemeAttributeInner>>, pub other_themes: HashMap<String, HashMap<Cow<'static, str>, ThemeAttributeInner>>,
} }
impl<'de> Deserialize<'de> for Theme { impl<'de> Deserialize<'de> for Themes {
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where where
D: Deserializer<'de>, D: Deserializer<'de>,
@ -355,7 +355,7 @@ impl<'de> Deserialize<'de> for Theme {
attrs: Option<ThemeValue<Attr>>, attrs: Option<ThemeValue<Attr>>,
} }
let mut ret = Theme::default(); let mut ret = Themes::default();
let mut s = <ThemeOptions>::deserialize(deserializer)?; let mut s = <ThemeOptions>::deserialize(deserializer)?;
for tk in s.other_themes.keys() { for tk in s.other_themes.keys() {
ret.other_themes.insert(tk.clone(), ret.dark.clone()); ret.other_themes.insert(tk.clone(), ret.dark.clone());
@ -415,7 +415,7 @@ impl<'de> Deserialize<'de> for Theme {
} }
} }
impl Theme { impl Themes {
fn validate_keys( fn validate_keys(
name: &str, name: &str,
theme: &HashMap<Cow<'static, str>, ThemeAttributeInner>, theme: &HashMap<Cow<'static, str>, ThemeAttributeInner>,
@ -484,10 +484,10 @@ impl Theme {
} }
pub fn validate(&self) -> Result<()> { pub fn validate(&self) -> Result<()> {
let hash_set: HashSet<&'static str> = DEFAULT_KEYS.into_iter().map(|k| *k).collect(); let hash_set: HashSet<&'static str> = DEFAULT_KEYS.into_iter().map(|k| *k).collect();
Theme::validate_keys("light", &self.light, &hash_set)?; Themes::validate_keys("light", &self.light, &hash_set)?;
Theme::validate_keys("dark", &self.dark, &hash_set)?; Themes::validate_keys("dark", &self.dark, &hash_set)?;
for (name, t) in self.other_themes.iter() { for (name, t) in self.other_themes.iter() {
Theme::validate_keys(name, t, &hash_set)?; Themes::validate_keys(name, t, &hash_set)?;
} }
if let Err(err) = is_cyclic(&self.light) { if let Err(err) = is_cyclic(&self.light) {
return Err(MeliError::new(format!( return Err(MeliError::new(format!(
@ -563,8 +563,8 @@ impl Theme {
} }
} }
impl Default for Theme { impl Default for Themes {
fn default() -> Theme { fn default() -> Themes {
let mut light = HashMap::default(); let mut light = HashMap::default();
let mut dark = HashMap::default(); let mut dark = HashMap::default();
let other_themes = HashMap::default(); let other_themes = HashMap::default();
@ -906,7 +906,7 @@ impl Default for Theme {
add!("pager.highlight_search", light = { fg: Color::White, bg: Color::Byte(6) /* Teal */, attrs: Attr::BOLD }, dark = { fg: Color::White, bg: Color::Byte(6) /* Teal */, attrs: Attr::BOLD }); add!("pager.highlight_search", light = { fg: Color::White, bg: Color::Byte(6) /* Teal */, attrs: Attr::BOLD }, dark = { fg: Color::White, bg: Color::Byte(6) /* Teal */, attrs: Attr::BOLD });
add!("pager.highlight_search_current", light = { fg: Color::White, bg: Color::Byte(17) /* NavyBlue */, attrs: Attr::BOLD }, dark = { fg: Color::White, bg: Color::Byte(17) /* NavyBlue */, attrs: Attr::BOLD }); add!("pager.highlight_search_current", light = { fg: Color::White, bg: Color::Byte(17) /* NavyBlue */, attrs: Attr::BOLD }, dark = { fg: Color::White, bg: Color::Byte(17) /* NavyBlue */, attrs: Attr::BOLD });
Theme { Themes {
light, light,
dark, dark,
other_themes, other_themes,
@ -914,7 +914,7 @@ impl Default for Theme {
} }
} }
impl Serialize for Theme { impl Serialize for Themes {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where where
S: Serializer, S: Serializer,