66 lines
1.9 KiB
Rust
66 lines
1.9 KiB
Rust
use std::fmt::format;
|
|
use std::os::fd::AsFd;
|
|
use std::{default, env, mem};
|
|
use std::os::unix::net::UnixStream;
|
|
use std::io::{prelude::*, stdout, BufReader};
|
|
|
|
use libc::{signal, SIGPIPE, SIG_DFL, SIG_IGN};
|
|
|
|
fn main() {
|
|
let args : Vec<String> = env::args().collect();
|
|
unsafe {signal(SIGPIPE, SIG_IGN);}
|
|
|
|
let mut filter_mode = false;
|
|
let mut split_mode = false;
|
|
if args.len() > 1 {
|
|
filter_mode = true;
|
|
}
|
|
for arg in &args[1..] {
|
|
if arg == "split" {
|
|
split_mode = true;
|
|
}
|
|
}
|
|
|
|
let mut stream = UnixStream::connect(get_hypr_socket_path()).unwrap();
|
|
|
|
//let mut buf = [0u8; 1024];
|
|
let reader = BufReader::new(stream);
|
|
if !filter_mode {
|
|
for line in reader.lines() {
|
|
write!(stdout(), "{}\n", line.unwrap()).unwrap();
|
|
stdout().flush().unwrap();
|
|
}
|
|
} else {
|
|
for line in reader.lines() {
|
|
let mut line = line.unwrap();
|
|
let contains: bool = {
|
|
let mut contains = false;
|
|
for filter in &args[1..] {
|
|
// if line.contains(filter) {
|
|
if line.starts_with(filter) {
|
|
contains = true;
|
|
break;
|
|
}
|
|
};
|
|
contains
|
|
};
|
|
if contains {
|
|
//write!(stdout(), "{}\n", line).unwrap();
|
|
//stdout().write(line.as_bytes()).unwrap();
|
|
//stdout().write_fmt(format_args!("{}\n", line)).unwrap();
|
|
//stdout().flush().unwrap();
|
|
let mut idx = 0;
|
|
if split_mode {
|
|
idx = line.find(">>").unwrap();
|
|
}
|
|
println!("{}", line.split_off(idx+2));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
fn get_hypr_socket_path() -> String {
|
|
let instance = env::var("HYPRLAND_INSTANCE_SIGNATURE").unwrap();
|
|
format!("/tmp/hypr/{instance}/.socket2.sock")
|
|
}
|