mirror of
https://github.com/k0kubun/xremap
synced 2024-11-02 03:40:25 +00:00
Shorten main function
This commit is contained in:
parent
ae7d2deff4
commit
d76ab68d7c
@ -62,7 +62,10 @@ impl<'de> Deserialize<'de> for Action {
|
|||||||
None => return serde_error::<Self::Value, M>("missing action"),
|
None => return serde_error::<Self::Value, M>("missing action"),
|
||||||
};
|
};
|
||||||
if let Some(key) = map.next_key::<String>()? {
|
if let Some(key) = map.next_key::<String>()? {
|
||||||
return serde_error::<Self::Value, M>(&format!("only one action key is expected but also got: {}", key));
|
return serde_error::<Self::Value, M>(&format!(
|
||||||
|
"only one action key is expected but also got: {}",
|
||||||
|
key
|
||||||
|
));
|
||||||
}
|
}
|
||||||
Ok(action)
|
Ok(action)
|
||||||
}
|
}
|
||||||
|
27
src/main.rs
27
src/main.rs
@ -2,13 +2,14 @@ use evdev::EventType;
|
|||||||
use std::env;
|
use std::env;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
use crate::config::Config;
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
mod input;
|
mod input;
|
||||||
mod output;
|
mod output;
|
||||||
mod transform;
|
mod transform;
|
||||||
|
|
||||||
fn event_loop() -> Result<(), Box<dyn Error>> {
|
fn event_loop(_config: &Config) -> Result<(), Box<dyn Error>> {
|
||||||
let mut input_device =
|
let mut input_device =
|
||||||
input::select_device().map_err(|e| format!("Failed to open an input device: {}", e))?;
|
input::select_device().map_err(|e| format!("Failed to open an input device: {}", e))?;
|
||||||
let mut output_device = output::build_device(&input_device)
|
let mut output_device = output::build_device(&input_device)
|
||||||
@ -32,28 +33,22 @@ fn event_loop() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn abort(message: &str) -> ! {
|
||||||
|
println!("{}", message);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let filename = match env::args().nth(1) {
|
let filename = match env::args().nth(1) {
|
||||||
Some(filename) => filename,
|
Some(filename) => filename,
|
||||||
None => {
|
None => abort("Usage: xremap <file>"),
|
||||||
println!("Usage: xremap <file>");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
let config = match config::load_config(&filename) {
|
let config = match config::load_config(&filename) {
|
||||||
Ok(config) => config,
|
Ok(config) => config,
|
||||||
Err(e) => {
|
Err(e) => abort(&format!("Failed to load config '{}': {}", filename, e)),
|
||||||
println!("Failed to load config '{}': {}", filename, e);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
println!("{:#?}", config);
|
|
||||||
|
|
||||||
match event_loop() {
|
if let Err(e) = event_loop(&config) {
|
||||||
Ok(()) => {}
|
abort(&format!("Error: {}", e));
|
||||||
Err(e) => {
|
|
||||||
println!("Error: {}", e);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user