From 10a70ff352361b8550d451ceef3bf61cd4056507 Mon Sep 17 00:00:00 2001 From: terminallesbian Date: Thu, 2 Apr 2026 19:23:34 -0500 Subject: [PATCH] Add barebones config for haptic length --- src/main.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index db53c71..b3badb5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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!"), _ => () };