diff --git a/src/config/file.rs b/src/config/file.rs index f3d0354..58b3554 100644 --- a/src/config/file.rs +++ b/src/config/file.rs @@ -54,6 +54,7 @@ pub struct Remember { #[derive(Debug, Default, Deserialize)] #[serde(deny_unknown_fields)] pub struct Ui { + pub theme: Option, pub greeting: Option, #[serde(default)] pub use_issue: bool, @@ -65,10 +66,11 @@ pub struct Ui { #[serde(default)] pub show_asterisks: bool, pub asterisks_char: Option, - pub width: Option, - pub window_padding: Option, - pub container_padding: Option, - pub prompt_padding: Option, + pub width: Option, + pub window_padding: Option, + pub container_padding: Option, + pub prompt_padding: Option, + pub greet_align: Option, pub command_f_key: Option, pub sessions_f_key: Option, pub power_f_key: Option, diff --git a/src/config/parser.rs b/src/config/parser.rs index 285284b..37b3d68 100644 --- a/src/config/parser.rs +++ b/src/config/parser.rs @@ -6,7 +6,7 @@ use crate::{ info::{get_issue, get_min_max_uids, get_users}, power::PowerOption, ui::{ - common::menu::Menu, + common::{menu::Menu, style::Theme}, power::Power, sessions::{SessionSource, SessionType}, }, @@ -33,6 +33,14 @@ impl Greeter { } } + pub fn parse_theme(&mut self) -> Result<(), Box> { + if let Some(spec) = self.config().opt_str("theme").or_else(|| self.config.ui.theme.clone()) { + self.theme = Theme::parse(spec.as_str()); + } + + Ok(()) + } + pub fn parse_greeting(&mut self) -> Result<(), Box> { let has_greeting = self.config().opt_present("greeting") || self.config.ui.greeting.is_some(); let has_issue = self.config().opt_present("issue") || self.config.ui.use_issue; diff --git a/src/greeter.rs b/src/greeter.rs index 32c5b6e..3b946e1 100644 --- a/src/greeter.rs +++ b/src/greeter.rs @@ -373,10 +373,8 @@ impl Greeter { // Returns the width of the main window where content is displayed from the // provided arguments. pub fn width(&self) -> u16 { - if let Some(value) = self.option("width") { - if let Ok(width) = value.parse::() { - return width; - } + if let Some(width) = self.option("width").and_then(|value| value.parse::().ok()).or(self.config.ui.width) { + return width; } 80 @@ -384,10 +382,8 @@ impl Greeter { // Returns the padding of the screen from the provided arguments. pub fn window_padding(&self) -> u16 { - if let Some(value) = self.option("window-padding") { - if let Ok(padding) = value.parse::() { - return padding; - } + if let Some(padding) = self.option("window-padding").and_then(|value| value.parse::().ok()).or(self.config.ui.window_padding) { + return padding; } 0 @@ -396,10 +392,8 @@ impl Greeter { // Returns the padding of the main window where content is displayed from the // provided arguments. pub fn container_padding(&self) -> u16 { - if let Some(value) = self.option("container-padding") { - if let Ok(padding) = value.parse::() { - return padding + 1; - } + if let Some(padding) = self.option("container-padding").and_then(|value| value.parse::().ok()).or(self.config.ui.container_padding) { + return padding + 1; } 2 @@ -407,17 +401,15 @@ impl Greeter { // Returns the spacing between each prompt from the provided arguments. pub fn prompt_padding(&self) -> u16 { - if let Some(value) = self.option("prompt-padding") { - if let Ok(padding) = value.parse::() { - return padding; - } + if let Some(padding) = self.option("prompt-padding").and_then(|value| value.parse::().ok()).or(self.config.ui.prompt_padding) { + return padding; } 1 } pub fn greet_align(&self) -> GreetAlign { - if let Some(value) = self.option("greet-align") { + if let Some(value) = self.option("greet-align").or_else(|| self.config.ui.greet_align.clone()) { match value.as_str() { "left" => GreetAlign::Left, "right" => GreetAlign::Right, @@ -526,6 +518,7 @@ impl Greeter { self.parse_remembers()?; self.parse_power(); self.parse_keybinds()?; + self.parse_theme()?; Ok(()) }