libtmux Reference MCP Search
On this page

window.navigation.Window.focus_direction

View as Markdown

Module
window.navigation
Declared in
Window
Package
libtmux
Source
crates/libtmux/src/window/navigation.rs
focus_direction ( self , direction : PaneDirection ) Result<Pane, Error>
method [source]
method [source]
focus_direction

Move focus one pane in this direction, and report where it landed.

tmux wraps: asking to go up from the topmost pane lands on the bottom one, and a window holding a single pane stays where it is. Neither is a failure, and tmux reports neither, so this returns the pane rather than absence. A caller that wants to know whether it moved compares the returned ID with the one it started from.

Direction follows the layout, not the pane index: "up" means the pane drawn above this one.

Errors

Returns an error when tmux cannot be reached or refuses the move.

Examples

use libtmux::{PaneDirection, SplitDirection};

let guard = libtmux::test::TestServer::new().await?;
let session = guard.server().new_session("directions").await?;
let window = session.active_window().await?.expect("a session has a window");

// Splitting leaves focus where it was, so the top pane is still active.
let lower = window.split(SplitDirection::Below).await?;

let moved = window.focus_direction(PaneDirection::Below).await?;
assert_eq!(moved.id(), lower.id(), "focus moved down to the new pane");

// Down again from the bottom wraps rather than failing.
let wrapped = window.focus_direction(PaneDirection::Below).await?;
assert_ne!(wrapped.id(), lower.id(), "the edge wraps back to the top");

guard.shutdown().await?;

0 declared, 0 inherited

Esc

Type to search.