diff --git a/src/commands/check.rs b/src/commands/check.rs index 6fa93c3..0082874 100644 --- a/src/commands/check.rs +++ b/src/commands/check.rs @@ -1,4 +1,38 @@ +use std::io::BufRead; + +use colored::Colorize; + +use crate::config::get_device_peripherals; pub fn check_tablet(tablet_name: &str) -> i32 { - todo!() -} \ No newline at end of file + // Get the peripheral list for the tablet + let peripherals = get_device_peripherals(tablet_name).unwrap(); + + // Use `xsetwacom` to check if the tablet is connected + let xsetwacom = std::process::Command::new("xsetwacom") + .arg("--list") + .output() + .unwrap(); + let xsetwacom_output = xsetwacom.stdout; + + // Check if the tablet is connected + let mut is_connected = false; + for line in xsetwacom_output.lines() { + let line = line.unwrap(); + for peripheral in &peripherals { + if line.contains(peripheral) { + is_connected = true; + break; + } + } + } + + // Print the message and return the status code + if is_connected { + println!("{} is {}", tablet_name, "connected".green()); + 0 + } else { + println!("{} is {}", tablet_name, "not connected".red()); + 1 + } +} diff --git a/src/commands/list.rs b/src/commands/list.rs index 3a46489..7f31ed3 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -2,6 +2,7 @@ use colored::Colorize; use crate::config::{get_config_dir, get_device_name, get_device_peripherals, get_device_profiles}; + pub fn list_tablets() { // Get the config directory let config_dir = get_config_dir().unwrap();