fixed required positional arguement
This commit is contained in:
parent
c2bc19611f
commit
92414fb7ce
2 changed files with 9 additions and 31 deletions
|
@ -18,6 +18,9 @@ pub struct CliArgs {
|
|||
#[arg(index = 1, value_enum)]
|
||||
action: Option<ProcessType>,
|
||||
|
||||
#[arg(index=2, required_if_eq("action", "workspace-selector"))]
|
||||
source_workspace: Option<i32>,
|
||||
|
||||
#[arg(short, long)]
|
||||
debug: bool,
|
||||
}
|
||||
|
@ -42,7 +45,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
run_calendar();
|
||||
}
|
||||
ProcessType::WorkspaceSelector => {
|
||||
run_workspace_selector();
|
||||
run_workspace_selector(&args);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -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::<i32>() {
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue