Start parsing the config

pull/39/head
Takashi Kokubun 2 years ago
parent 2590a84654
commit 2db606bce3
No known key found for this signature in database
GPG Key ID: 6FFC433B12EE23DD

16
Cargo.lock generated

@ -61,6 +61,12 @@ version = "0.2.111"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e167738f1866a7ec625567bae89ca0d44477232a4f7c52b1c7f2adc2c98804f"
[[package]]
name = "linked-hash-map"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
[[package]]
name = "memoffset"
version = "0.6.5"
@ -110,4 +116,14 @@ version = "0.1.0"
dependencies = [
"evdev",
"libc",
"yaml-rust",
]
[[package]]
name = "yaml-rust"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
dependencies = [
"linked-hash-map",
]

@ -8,3 +8,4 @@ edition = "2021"
[dependencies]
evdev = "0.11.3"
libc = "0.2"
yaml-rust = "0.4"

@ -0,0 +1,24 @@
use std::error::Error;
use std::fs;
pub fn load_config(filename: &str) -> Result<Config, Box<dyn Error>> {
let yaml = fs::read_to_string(&filename).unwrap();
println!("{}", yaml.len());
return Ok(Config { modmap: vec![], keymap: vec![] })
}
#[derive(Debug)]
pub struct Config {
pub modmap: Vec<Modmap>,
pub keymap: Vec<Keymap>,
}
#[derive(Debug)]
pub struct Modmap {
// TODO
}
#[derive(Debug)]
pub struct Keymap {
// TODO
}

@ -1,10 +1,13 @@
use evdev::{Device, EventType};
use std::error::Error;
use std::env;
use std::process::exit;
mod input;
mod output;
mod select;
mod transform;
mod config;
fn event_loop(input_device: &mut Device) -> Result<(), Box<dyn Error>> {
let mut output_device = output::build_device(input_device).unwrap();
@ -24,6 +27,22 @@ fn event_loop(input_device: &mut Device) -> Result<(), Box<dyn Error>> {
}
fn main() -> Result<(), Box<dyn Error>> {
let filename = match env::args().nth(1) {
Some(filename) => filename,
None => {
println!("Usage: xremap <file>");
exit(1);
},
};
let config = match config::load_config(&filename) {
Ok(config) => config,
Err(e) => {
println!("Failed to load config '{}': {}", filename, e);
exit(1);
},
};
println!("{:?}", config);
let mut device = input::select_device();
device.grab()?;
event_loop(&mut device)?;

Loading…
Cancel
Save