Expand description
Focal - Terminal focus library.
This crate provides cross-platform functionality for focusing terminal windows and switching multiplexer panes. It supports:
- Terminal detection: Identify which terminal emulator owns a TTY
- Cross-platform activation: Bring terminal windows to front (macOS + Linux)
- Terminal-specific handlers: Precise tab/pane focusing for iTerm2, Terminal.app, WezTerm, Kitty
- Multiplexer support: Switch to the correct tmux/zellij/screen pane
§Focus Modes
The library supports two focus modes:
-
SingleWindow: Uses Accessibility APIs (AXRaise) to bring only the specific window to the front. Requires accessibility permissions on macOS.
-
ActivateApp: Uses traditional app activation which brings ALL windows of the terminal app to the front. No special permissions required.
§Usage
ⓘ
use focal::{focus_session, focus_session_with_mode, FocusResult, FocusMode};
// Focus using default mode (SingleWindow with ActivateApp fallback)
match focus_session(pid, None) {
FocusResult::Success => println!("Focused!"),
FocusResult::MuxSwitched { mux, target } => {
println!("Switched to {mux} {target}");
}
FocusResult::NotFound => println!("Terminal not found"),
_ => {}
}
// Or explicitly choose a mode
focus_session_with_mode(pid, None, FocusMode::ActivateApp);§Architecture
The focus flow works as follows:
- Check if the process is in a terminal multiplexer (tmux, zellij, screen)
- If so, switch to the correct pane and get the client TTY
- Get the TTY device for the process
- Detect which terminal emulator owns the TTY
- Try terminal-specific focusing (for precise tab/pane control)
- Fall back to generic window activation
Re-exports§
pub use detect::Terminal;pub use detect::TerminalKind;pub use mux::Focuser;pub use mux::Multiplexer;pub use mux::MuxFocusResult;
Modules§
- activate
- Cross-platform window activation.
- detect
- Terminal detection from TTY device.
- mux
- Terminal multiplexer handlers.
- terminals
- Terminal-specific focus handlers.
- tty
- TTY device utilities.
- util
- Shared utilities for the focal crate.
Enums§
- Focus
Mode - Focus mode for terminal window activation.
- Focus
Result - Result of attempting to focus a terminal.
Functions§
- focus_
by_ tty - Focus a terminal window by its TTY device.
- focus_
by_ tty_ with_ mode - Focus a terminal window by TTY with explicit mode control.
- focus_
session - Focus the terminal window containing the given process.
- focus_
session_ with_ mode - Focus the terminal window with explicit mode control.
- get_
tty_ device - Get the TTY device for a process.