Implment rough TUI version of new workflow

Merge in Python stuff and then we will probably get
rid of it and continue in Rust only.
This commit is contained in:
2024-07-05 10:44:28 -04:00
parent d97a4885cb
commit 3b7d88f279
5 changed files with 949 additions and 145 deletions

66
src/window.rs Normal file
View File

@@ -0,0 +1,66 @@
use regex::Regex;
use std::{process::Command, process::Output, str};
pub fn get_title_clean() -> String {
let title = get_window_info().title;
let re = Regex::new(r"-?\d+([:.]\d+)+%?").unwrap();
re.replace_all(&title, "").to_string()
}
pub fn minimize_other(class: &str) {
let window_info = get_window_info();
if &window_info.class != class {
run(&format!("xdotool windowminimize {}", window_info.wid));
}
}
struct WindowInfo {
title: String,
class: String,
wid: String,
}
fn run(cmd: &str) -> Option<String> {
let output = Command::new("sh").arg("-c").arg(cmd).output();
let Ok(Output {
status,
stdout,
stderr: _,
}) = output
else {
return None;
};
if status.code() != Some(0) {
return None;
}
let Ok(output_str) = str::from_utf8(&stdout) else {
return None;
};
Some(output_str.trim().to_string())
}
fn get_window_info() -> WindowInfo {
let none = WindowInfo {
title: "none".to_string(),
class: "none".to_string(),
wid: "".to_string(),
};
let Some(wid) = run("xdotool getactivewindow") else {
return none;
};
let Some(class) = run(&format!("xdotool getwindowclassname {wid}")) else {
return none;
};
let Some(title) = run(&format!("xdotool getwindowname {wid}")) else {
return none;
};
WindowInfo { title, class, wid }
}