Add example config

This commit is contained in:
2022-05-04 00:27:18 -07:00
parent 92504d279a
commit 2ae04ff91a
5 changed files with 72 additions and 40 deletions

View File

@ -1,4 +1,4 @@
use std::{ffi::CStr, fs::File, io::{self, Read}};
use std::{ffi::CStr, fs::File, io::{self, Read}, path::PathBuf};
use toml::Value;
use xcb::x;
@ -11,19 +11,21 @@ pub fn init_logging(env_name: &str) {
.init();
}
pub fn load_configuration() -> anyhow::Result<Option<Value>> {
match xdg::BaseDirectories::new()?.find_config_file("bscreensaver.toml") {
None => Ok(None),
Some(config_path) => {
let mut f = File::open(config_path)?;
let mut config = String::new();
f.read_to_string(&mut config)?;
drop(f);
fn parse_config_toml(config_path: &PathBuf) -> anyhow::Result<Value> {
let mut f = File::open(config_path)?;
let mut config = String::new();
f.read_to_string(&mut config)?;
drop(f);
let config_toml = config.parse::<Value>()?;
Ok(Some(config_toml))
},
}
let config_toml = config.parse::<Value>()?;
Ok(config_toml)
}
pub fn load_configuration() -> anyhow::Result<Vec<Value>> {
xdg::BaseDirectories::new()?
.find_config_files("bscreensaver/bscreensaver.toml")
.map(|config_path| parse_config_toml(&config_path))
.collect()
}
pub fn create_atom(conn: &xcb::Connection, name: &[u8]) -> xcb::Result<x::Atom> {