Browse Source

themes: Rename Theme struct to Themes

memfd
Manos Pitsidianakis 3 years ago
parent
commit
9c0ee76ff4
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 2
      src/bin.rs
  2. 6
      src/conf.rs
  3. 6
      src/conf/terminal.rs
  4. 22
      src/conf/themes.rs

2
src/bin.rs

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

6
src/conf.rs

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

6
src/conf/terminal.rs

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

22
src/conf/themes.rs

@ -325,13 +325,13 @@ impl<'de> Deserialize<'de> for ThemeValue<Color> {
}
#[derive(Debug, Clone)]
pub struct Theme {
pub struct Themes {
pub light: HashMap<Cow<'static, str>, ThemeAttributeInner>,
pub dark: 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>
where
D: Deserializer<'de>,
@ -355,7 +355,7 @@ impl<'de> Deserialize<'de> for Theme {
attrs: Option<ThemeValue<Attr>>,
}
let mut ret = Theme::default();
let mut ret = Themes::default();
let mut s = <ThemeOptions>::deserialize(deserializer)?;
for tk in s.other_themes.keys() {
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(
name: &str,
theme: &HashMap<Cow<'static, str>, ThemeAttributeInner>,
@ -484,10 +484,10 @@ impl Theme {
}
pub fn validate(&self) -> Result<()> {
let hash_set: HashSet<&'static str> = DEFAULT_KEYS.into_iter().map(|k| *k).collect();
Theme::validate_keys("light", &self.light, &hash_set)?;
Theme::validate_keys("dark", &self.dark, &hash_set)?;
Themes::validate_keys("light", &self.light, &hash_set)?;
Themes::validate_keys("dark", &self.dark, &hash_set)?;
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) {
return Err(MeliError::new(format!(
@ -563,8 +563,8 @@ impl Theme {
}
}
impl Default for Theme {
fn default() -> Theme {
impl Default for Themes {
fn default() -> Themes {
let mut light = HashMap::default();
let mut dark = 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_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,
dark,
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>
where
S: Serializer,

Loading…
Cancel
Save