Add example config
This commit is contained in:
@ -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> {
|
||||
|
Reference in New Issue
Block a user