~animations~

This commit is contained in:
Zacharias-Brohn
2025-12-15 23:31:42 +01:00
parent 567c403912
commit f304fd18a8
6 changed files with 612 additions and 35 deletions
+25
View File
@@ -188,6 +188,31 @@ impl Pty {
// If it returns -1, there was an error (child might have already been reaped)
result != 0
}
/// Get the foreground process group ID of this PTY.
/// Returns None if the query fails.
pub fn foreground_pgid(&self) -> Option<i32> {
let fd = self.master.as_raw_fd();
let pgid = unsafe { libc::tcgetpgrp(fd) };
if pgid > 0 {
Some(pgid)
} else {
None
}
}
/// Get the name of the foreground process running in this PTY.
/// Returns the process name (e.g., "nvim", "zsh") or None if unavailable.
pub fn foreground_process_name(&self) -> Option<String> {
let pgid = self.foreground_pgid()?;
// Read the command line from /proc/<pid>/comm
// (comm gives just the process name, cmdline gives full command)
let comm_path = format!("/proc/{}/comm", pgid);
std::fs::read_to_string(&comm_path)
.ok()
.map(|s| s.trim().to_string())
}
}
impl AsRawFd for Pty {