This commit is contained in:
Joshua Perry 2024-07-21 23:26:08 +01:00
parent 605f31b6c2
commit 9aec63d7ee
7 changed files with 131 additions and 17 deletions

View File

View File

@ -1 +1,26 @@
use clap::Parser;
use utils::{color::color_picker, Util, volume, workspace};
pub mod utils;
pub fn run() {
let args = Args::parse();
match args.util {
Util::Color => color_picker(),
Util::Volume(command) => volume::parse_command(command),
Util::Workspaces(command) => workspace::parse_command(command),
};
}
#[derive(Parser)]
#[command(
name = "yucky-utils",
author = "r0r-5chach",
version = "1.0",
about = "", //TODO: Command about
long_about = None)]
struct Args {
#[command(subcommand)]
util: Util,
}

View File

@ -1,2 +1,3 @@
fn main() {
}
yucky_utils::run();
} //TODO: Handle unwraps

View File

@ -1,3 +1,5 @@
use clap::{Subcommand, ValueEnum};
pub mod color;
pub mod volume;
pub mod workspace;
@ -11,8 +13,21 @@ pub fn update_eww_var(key: &str, value: &str) {
.spawn();
}
#[derive(Clone, ValueEnum)]
pub enum Direction {
Up,
Down,
Absolute,
}
#[derive(Subcommand)]
pub enum Util {
/// Color Picking Utility
Color,
/// Volume Management Utility
#[command(subcommand)]
Volume(volume::Command),
/// Workspace Management Utility
#[command(subcommand)]
Workspaces(workspace::Command),
}

View File

@ -1,6 +1,5 @@
use std::process::Command;
pub fn color_picker() {
use super::update_eww_var;

View File

@ -1,11 +1,44 @@
use std::process::Command;
use core::fmt;
use std::fmt::{Display, Result};
use clap::Subcommand;
use super::Direction;
pub fn step(directon: Direction) { //onscroll
#[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);
}
pub fn toggle_mute(saved_volume: u8) { //onclick
fn toggle_mute(saved_volume: u8) { //onclick
use super::update_eww_var;
let volume = get_current_value();
@ -15,7 +48,7 @@ pub fn toggle_mute(saved_volume: u8) { //onclick
std::process::exit(0);
}
pub fn get_current_icon() -> Level { //for path var in image (add to defpoll)
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,
@ -24,19 +57,25 @@ pub fn get_current_icon() -> Level { //for path var in image (add to defpoll)
}
}
pub fn get_current_value() -> u8 { //for value in circular-progrss (add to defpoll)
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[3].trim().get(0..value.len()-3).unwrap().parse().unwrap()
value.parse().unwrap()
}
fn set(value: u8, directon: Direction) {
use std::process::Command;
let mut value = value.to_string();
value.push('%');
@ -46,15 +85,24 @@ fn set(value: u8, directon: Direction) {
Direction::Absolute => (),
}
Command::new("amixer")
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"),
}
}
}

View File

@ -1,16 +1,40 @@
use std::process::Command;
use clap::Subcommand;
use super::Direction;
pub fn step(direction: Direction) {
#[derive(Subcommand)]
#[command(about = "", long_about = "")]
pub enum Command {
/// Move Up/Down 1 workspace
Step {
/// The direction to move
#[arg(value_enum)]
direction: Direction,
},
/// Move to empty workspace
Empty,
/// Get id of the active workspace
GetActive,
}
pub fn parse_command(command: Command) {
match command {
Command::Empty => empty(),
Command::GetActive => println!("{}", get_active()),
Command::Step { direction } => step(direction),
}
}
fn step(direction: Direction) {
set(1, direction);
}
pub fn empty() {
fn empty() {
set(0, Direction::Absolute);
}
pub fn get_active() -> u8 {
fn get_active() -> u8 {
use std::process::Command;
let value = Command::new("hyprctl")
.arg("activeworkspace")
.output().unwrap().stdout;
@ -23,6 +47,8 @@ pub fn get_active() -> u8 {
}
fn set(id: u8, direction: Direction) {
use std::process::Command;
let workspace_arg = match id {
0 => "emptym",
_ => match direction {
@ -32,7 +58,7 @@ fn set(id: u8, direction: Direction) {
}
};
Command::new("hyprctl")
let _ = Command::new("hyprctl")
.arg("dispatch").arg("workspace").arg(workspace_arg)
.spawn();