deerwm/src/bin/deerwm.rs

37 lines
1.0 KiB
Rust

use commands::Command;
use nanoserde::DeBin;
use std::io::Read;
use deerwm::commands;
fn main() {
if let Err(e) = unix_named_pipe::create(commands::DEFAULT_PIPE, None) {
match e.kind() {
std::io::ErrorKind::AlreadyExists => {}
_ => panic!("{}", e),
}
}
let mut cmd_fifo =
unix_named_pipe::open_read(commands::DEFAULT_PIPE).expect("failed to open fifo");
let mut cmd_buffer = [0; 256];
'run: loop {
if let Ok(n) = cmd_fifo.read(&mut cmd_buffer) {
if n > 0 {
println!("{:?}", &cmd_buffer[..n]);
if let Ok(cmd) = Command::de_bin(&mut 0, &cmd_buffer[..n]) {
match cmd {
Command::Quit => {
println!("Recieved quit command!");
break 'run;
},
}
}
}
}
}
std::fs::remove_file(commands::DEFAULT_PIPE).expect("failed to create fifo");
}