From 92414fb7ce184b59ef3cc25877aa1fbe1851fd52 Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Thu, 16 Nov 2023 18:13:32 -0800 Subject: [PATCH] fixed required positional arguement --- ewwtilities/src/main.rs | 5 +++- ewwtilities/src/workspace_switcher.rs | 35 ++++----------------------- 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/ewwtilities/src/main.rs b/ewwtilities/src/main.rs index 71943b4..4ec4d65 100644 --- a/ewwtilities/src/main.rs +++ b/ewwtilities/src/main.rs @@ -18,6 +18,9 @@ pub struct CliArgs { #[arg(index = 1, value_enum)] action: Option, + #[arg(index=2, required_if_eq("action", "workspace-selector"))] + source_workspace: Option, + #[arg(short, long)] debug: bool, } @@ -42,7 +45,7 @@ fn main() -> Result<(), Box> { run_calendar(); } ProcessType::WorkspaceSelector => { - run_workspace_selector(); + run_workspace_selector(&args); } } Ok(()) diff --git a/ewwtilities/src/workspace_switcher.rs b/ewwtilities/src/workspace_switcher.rs index da7938d..4cd6a35 100644 --- a/ewwtilities/src/workspace_switcher.rs +++ b/ewwtilities/src/workspace_switcher.rs @@ -1,38 +1,12 @@ use log::{debug, error}; -use std::io::stdin; -use std::io::IsTerminal; use std::process::Command; use serde::{Deserialize, Serialize}; use serde_json; -pub fn run_workspace_selector() { - let in_pipe = stdin(); - if in_pipe.is_terminal() { - error!("Workspace Selector process requires being run as a terminal process"); - panic!("Expected to be run in a terminal process, but was not"); - } - - let mut buffer = String::new(); - let bytes = in_pipe.read_line(&mut buffer).unwrap(); - - debug!("Received from pipe: {buffer}"); - - if bytes == 0 { - error!("The input pipe was empty! Unrecoverable error"); - panic!("The input pipe was empty! Unrecoverable error"); - } - - debug!("Attempting to parse buffer"); - - let src_workspace = match buffer.trim().parse::() { - Ok(val) => val, - Err(e) => { - error!("Error parsing stdin buffer: {e}"); - panic!("Could not parse stdin to i32"); - } - }; +use crate::CliArgs; +pub fn run_workspace_selector(cli: &CliArgs) { let output = { let std_out = match Command::new("hyprctl").arg("monitors").arg("-j").output() { Ok(val) => val, @@ -91,11 +65,12 @@ pub fn run_workspace_selector() { debug!("Monitor number adjusted: {}", monitor_num); // Because there is a monitor 0, make sure it is always at least monitor 1 - let target_workspace = src_workspace * (monitor_num + 1) as i32; + let target_workspace = cli.source_workspace.unwrap() * (monitor_num + 1) as i32; debug!("Target workspace: {}", target_workspace); - print!("{}", target_workspace); + debug!("Calling hyprctl and closing"); + Command::new("hyprctl").arg("dispatch").arg("workspace").arg(target_workspace.to_string()).output().unwrap(); }