focal 0.2.8

Terminal focus library - focus terminal windows and multiplexer panes
Documentation
//! TTY device utilities.
//!
//! Provides functions for working with TTY devices.

/// Get the TTY device path for a given PID (e.g., "ttys003").
///
/// # Arguments
/// * `pid` - Process ID to look up
///
/// # Returns
/// The TTY device name (without "/dev/" prefix), or `None` if the process
/// doesn't exist or has no controlling terminal.
#[must_use]
pub fn get_device(pid: i32) -> Option<String> {
    prock::get_tty(pid)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_get_device_current_process() {
        // Current process should have a TTY (when run from terminal)
        let pid = std::process::id() as i32;
        // Note: may return None in CI environments
        let _ = get_device(pid);
    }

    #[test]
    fn test_get_device_nonexistent_pid() {
        // A very high PID that almost certainly doesn't exist
        assert!(get_device(999_999_999).is_none());
    }
}