Added configparser for rewrite
This commit is contained in:
parent
0d5c0d668e
commit
6cd99b50a9
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -11,6 +11,12 @@ dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "configparser"
|
||||
version = "3.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ec6d3da8e550377a85339063af6e3735f4b1d9392108da4e083a1b3b9820288"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.1"
|
||||
@ -21,6 +27,7 @@ checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
|
||||
name = "mycelium"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"configparser",
|
||||
"untildify",
|
||||
]
|
||||
|
||||
|
||||
@ -4,4 +4,5 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
configparser = "3.0.4"
|
||||
untildify = "0.1.1"
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
use configparser::ini::Ini;
|
||||
use core::fmt;
|
||||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
|
||||
use untildify;
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -8,6 +10,18 @@ pub enum WallpaperHandler {
|
||||
Feh,
|
||||
Plasma,
|
||||
Gnome,
|
||||
Error,
|
||||
}
|
||||
|
||||
impl WallpaperHandler {
|
||||
pub fn new(handler: String) -> WallpaperHandler {
|
||||
match handler.as_str() {
|
||||
"feh" => WallpaperHandler::Feh,
|
||||
"plasma" => WallpaperHandler::Plasma,
|
||||
"gnome" => WallpaperHandler::Gnome,
|
||||
_ => WallpaperHandler::Error,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for WallpaperHandler {
|
||||
@ -108,10 +122,32 @@ impl fmt::Display for Config {
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn load_from_file(self, file_path: String) -> String {
|
||||
let mut file = File::open(file_path).unwrap();
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents).unwrap();
|
||||
contents
|
||||
pub fn parse_config(self, file_path: String) -> Config {
|
||||
let mut config = Ini::new();
|
||||
let map = config.load(file_path).unwrap();
|
||||
// let file_contents = Config::load_from_file(file_path);
|
||||
|
||||
// Get the wallpaper engine and parse it
|
||||
let wallpaper_engine =
|
||||
WallpaperHandler::new(config.get("general", "wallpaper_engine").unwrap());
|
||||
//
|
||||
|
||||
// Get the wallpaper dirs and parse them
|
||||
|
||||
//
|
||||
|
||||
// Get the Monitors and parse them
|
||||
for mon in map.get("monitors") {
|
||||
println!("{:?}", mon);
|
||||
}
|
||||
println!("{:?}", map.get("monitors"));
|
||||
//
|
||||
|
||||
Config {
|
||||
x_server: config.get("general", "x_server").unwrap(),
|
||||
wallpaper_engine: wallpaper_engine,
|
||||
wallpaper_dir: WallpaperDir::new(),
|
||||
monitors: Monitors::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,9 +2,9 @@ mod config;
|
||||
|
||||
fn main() {
|
||||
let config = config::Config::new();
|
||||
|
||||
// config.parse_config("/home/ben/.config/wallpaperctl/wallpaperctl.ini".to_owned())
|
||||
println!(
|
||||
"{}",
|
||||
config.load_from_file("/home/ben/.config/wallpaperctl/wallpaperctl.ini".to_owned())
|
||||
config.parse_config("/home/ben/.config/wallpaperctl/wallpaperctl.ini".to_owned())
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user