use core::fmt; use std::fmt::{Display, Result}; use clap::Subcommand; use super::Direction; #[derive(Subcommand)] #[command(about = "", long_about = None)] //Volume command usage pub enum Command { /// Adjust volume Up/Down by 5% Step { /// The direction to adjust the volume #[arg(value_enum)] directon: Direction, }, /// Adjust the volume to 0% or last volume ToggleMute { /// The value to set the volume to #[arg()] volume: u8, }, /// Get the name of the current icon CurrentIcon, /// Get the current volume percent CurrentValue, } pub fn parse_command(command: Command) { match command { Command::CurrentValue => println!("{}", get_current_value()), Command::CurrentIcon => println!("{}", get_current_icon()), Command::Step { directon } => step(directon), Command::ToggleMute { volume } => toggle_mute(volume), } } fn step(directon: Direction) { //onscroll set(5, directon); } fn toggle_mute(saved_volume: u8) { //onclick use super::update_eww_var; let volume = get_current_value(); set(saved_volume, Direction::Absolute); update_eww_var("mute_save", &volume.to_string()); std::process::exit(0); } fn get_current_icon() -> Level { //for path var in image (add to defpoll) match get_current_value() { value if value <= 0 => Level::Mute, value if value <= 25 => Level::Low, value if value <= 75 => Level::Mid, _ => Level::High, } } fn get_current_value() -> u8 { //for value in circular-progrss (add to defpoll) use std::process::Command; let value = Command::new("amixer") .arg("sget").arg("Master") .output().unwrap().stdout; let value = String::from_utf8(value).unwrap(); let value: Vec<&str> = value.split("[").collect(); let value = value[3].trim(); let value = value.get(0..value.len() -2).unwrap().replace("%", ""); value.parse().unwrap() } fn set(value: u8, directon: Direction) { use std::process::Command; let mut value = value.to_string(); value.push('%'); match directon { Direction::Up => value.push('+'), Direction::Down => value.push('-'), Direction::Absolute => (), } let _ = Command::new("amixer") .arg("sset").arg("Master").arg(value).arg("> /dev/null") .spawn(); } enum Level { High, Mid, Low, Mute, } impl Display for Level { fn fmt(&self, formatter: &mut fmt::Formatter) -> Result { match self { Level::Mute => write!(formatter, "mute"), Level::Low => write!(formatter, "low"), Level::Mid => write!(formatter, "mid"), Level::High => write!(formatter, "high"), } } }