xcrab/src/config.rs

43 lines
938 B
Rust
Raw Normal View History

2022-06-26 01:53:38 -05:00
#![allow(dead_code)]
2022-06-26 01:22:09 -05:00
use serde::{Deserialize, Serialize};
2022-06-26 01:53:38 -05:00
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
2022-06-26 01:22:09 -05:00
pub struct XcrabConfig {
2022-06-26 01:53:38 -05:00
border_color: Option<u32>,
border_size: Option<u16>,
gap_width: Option<u16>,
2022-06-26 01:22:09 -05:00
}
impl Default for XcrabConfig {
fn default() -> Self {
Self {
border_color: Some(0xff_00_00), // red
border_size: Some(5),
gap_width: Some(10),
}
}
}
2022-06-26 01:53:38 -05:00
impl XcrabConfig {
pub fn border_color(&self) -> u32 {
self.border_color.unwrap_or(0xff_00_00)
}
pub fn border_size(&self) -> u16 {
self.border_size.unwrap_or(5)
}
pub fn gap_width(&self) -> u16 {
self.gap_width.unwrap_or(10)
}
2022-06-26 01:22:09 -05:00
}
2022-06-26 01:53:38 -05:00
pub fn load_file() -> Result<XcrabConfig, crate::XcrabError> {
2022-06-26 01:22:09 -05:00
let contents = std::fs::read_to_string("~/.config/xcrab/config.toml")?;
let config: XcrabConfig = toml::from_str(&contents)?;
Ok(config)
}