Add barebones config for haptic length

This commit is contained in:
terminallesbian 2026-04-02 19:23:34 -05:00
parent d3ad2cf239
commit 10a70ff352

View file

@ -1,4 +1,4 @@
use std::{path::{Path, PathBuf}, fs::{File, OpenOptions}, process::exit};
use std::{path::{Path}, fs::{File, OpenOptions}};
use std::io::{Read, Write};
use clap::Parser;
use regex::Regex;
@ -11,13 +11,27 @@ const HAPTIC_PATH: &str = "/sys/class/timed_output/vibrator/enable";
#[command(version, about, long_about = None)]
struct Args {
/// vibration duration in milliseconds
#[arg(short, long, default_value_t = 50)]
length: usize,
#[arg(short, long, default_value_t = String::from("/etc/kb-haptic-length"))]
config_path: String,
}
fn main() {
let cli = Args::parse();
let haptic_length: String = {
let mut str = String::new();
match File::open(&Path::new(&cli.config_path)) {
Ok(mut f) => match f.read_to_string(&mut str) {
Ok(_) => (),
Err(_) => { str.push_str("50"); }
}
_ => { str.push_str("50"); }
}
str
};
let mut haptic = OpenOptions::new()
.append(true)
.open(HAPTIC_PATH)
@ -39,7 +53,7 @@ fn main() {
loop {
for event in device.fetch_events().unwrap() {
if let EventSummary::Key(_, _, 1) = event.destructure() {
match write!(haptic, "{}", cli.length) {
match write!(haptic, "{}", haptic_length) {
Err(_) => println!("Unable to write to haptics!"),
_ => ()
};