Skip to content

Commit

Permalink
Allow configuration through a TOML file (#156).
Browse files Browse the repository at this point in the history
  • Loading branch information
apognu committed Sep 29, 2024
1 parent 359410f commit 9f916a9
Show file tree
Hide file tree
Showing 10 changed files with 476 additions and 247 deletions.
10 changes: 6 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ tracing-appender = "0.2.3"
tracing-subscriber = "0.3.18"
tracing = "0.1.40"
utmp-rs = "0.3.0"
serde = { version = "1.0.210", features = ["serde_derive"] }
toml = "0.8.19"

[profile.release]
lto = true
Expand Down
78 changes: 78 additions & 0 deletions src/config/file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
use std::{error::Error, path::PathBuf};

use serde::Deserialize;

use crate::Greeter;

#[derive(Debug, Default, Deserialize)]
pub struct FileConfig {
#[serde(default)]
pub defaults: Defaults,
#[serde(default)]
pub sessions: Sessions,
#[serde(default)]
pub remember: Remember,
#[serde(default)]
pub ui: Ui,
}

#[derive(Debug, Default, Deserialize)]
pub struct Defaults {
pub debug: Option<String>,
pub command: Option<String>,
pub env: Option<Vec<String>>,
pub user_min_uid: Option<u16>,
pub user_max_uid: Option<u16>,
#[serde(default)]
pub power_no_setsid: bool,
pub shutdown_command: Option<String>,
pub reboot_command: Option<String>,
}

#[derive(Debug, Default, Deserialize)]
pub struct Sessions {
pub wayland_paths: Option<Vec<PathBuf>>,
pub wayland_wrapper: Option<String>,
pub x11_paths: Option<Vec<PathBuf>>,
pub x11_wrapper: Option<String>,
#[serde(default)]
pub x11_wrapper_disabled: bool,
}

#[derive(Debug, Default, Deserialize)]
pub struct Remember {
#[serde(default)]
pub last_user: bool,
#[serde(default)]
pub last_session: bool,
#[serde(default)]
pub last_user_session: bool,
}

#[derive(Debug, Default, Deserialize)]
pub struct Ui {
pub greeting: Option<String>,
#[serde(default)]
pub use_issue: bool,
#[serde(default)]
pub show_time: bool,
pub time_format: Option<String>,
#[serde(default)]
pub show_user_menu: bool,
#[serde(default)]
pub show_asterisks: bool,
pub asterisks_char: Option<char>,
pub width: Option<u64>,
pub window_padding: Option<u64>,
pub container_padding: Option<u64>,
pub prompt_padding: Option<u64>,
pub command_f_key: Option<u8>,
pub sessions_f_key: Option<u8>,
pub power_f_key: Option<u8>,
}

impl Greeter {
pub fn parse_config_file(&mut self, file: &str) -> Result<FileConfig, Box<dyn Error>> {
Ok(toml::from_str::<FileConfig>(file)?)
}
}
2 changes: 2 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod file;
pub mod parser;
Loading

0 comments on commit 9f916a9

Please sign in to comment.