diff --git a/src/config.rs b/src/config.rs index f6413ea..e213a4d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,19 +1,42 @@ +use std::env; use crate::{Error, Result}; use serde::{Deserialize, Serialize}; +fn default_terminal() -> std::string::String{ + match env::var("TERMINAL") { + Ok(val) => val, + Err(_) => "xterm -e".to_owned() + } +} + +fn default_selector() -> std::string::String{ + "rofi -dmenu -p 'Open With: '".to_owned() +} + +fn default_enable_selector() -> bool { + false +} + #[derive(Serialize, Deserialize)] pub struct Config { + #[serde(default="default_enable_selector")] pub enable_selector: bool, + + #[serde(default="default_selector")] pub selector: String, + + #[serde(default="default_terminal")] pub terminal_emulator: String, } + impl Default for Config { fn default() -> Self { + // This seems repetitive but serde does not uses Default Config { - enable_selector: false, - selector: "rofi -dmenu -p 'Open With: '".to_owned(), - terminal_emulator: "xterm -e".to_owned(), + enable_selector: default_enable_selector(), + selector: default_selector(), + terminal_emulator: default_terminal() } } }