Core Library0.xAPI Reference

Choose documentation 3

latest

Current version

latest
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

struct libtmux-rs latest

Window

One tmux window, as reached through one session that links it.

Source and package
Qualified name
libtmux::window::Window
Module
window
Package
libtmux
Source
crates/libtmux/src/window.rs
Other languages
Perlclass Erlangstruct PowerShellcmdlet Juliastruct Elixirstruct Haskell Common Lispclass PythonRubyLuaTypeScriptGoJavaC#C++SwiftKotlinScalaOCamltypealias F#module Clojurefunction
struct window.Window

Description#

A window is not owned by a single session. link-window makes the same underlying window appear in several sessions at once, so discovery returns one Window per link rather than per window. Two handles for the same window reached through different sessions are not equal: they describe different places in the hierarchy.

Getters that describe the window itself, such as Window::name(), read the window. Getters that describe its place in a session, such as Window::index() and Window::is_active(), read the link.

What is on here

The methods on a Window fall into a few groups:

Finding the window you are in
Resolve the window this process is running in, through the pane TMUX_PANE names or through a value you pass. Both report Ok(None) when tmux no longer has that pane, and fail when the value is absent or not a pane ID.
Reading the snapshot
Getters are synchronous: they read the snapshot this handle owns and send nothing to tmux. last_activity() is when the window last produced output, whatever its options say, while has_activity() is an alert that stays false unless monitor-activity is on, which it is not by default. Refreshing updates this handle in place or returns a new one, keeps following the same link, and fails with Error::ObjectGone when the session no longer links the window; get() reads any snapshot field, including those with no getter, and needs the query feature, which is on by default.
Any field
Panes and sessions
panes() returns the same panes through every link to the window, and a failed listing is an error, not an empty list; search_panes() needs the query feature, which is on by default. pane_at() reports Ok(None) when nothing matches, and active_pane() does so only when the window has gone, because a window always has an active pane; session() re-reads tmux and reports Ok(None) when the session is gone. Focus follows the layout rather than pane order: focus_direction() wraps at the edge and always returns a pane, and last_pane() reports Ok(None) when no other pane has been active.
List
Adding and arranging panes
split() returns the new pane, takes a SplitOptions or a bare SplitDirection, and leaves focus where it was unless asked. with_pane() creates a pane, runs an operation with it, and kills the pane afterwards: a failure to create it, to run the operation or to kill it comes back as a ScopeError, and a cleanup failure carries Error::AfterEffect. If the future is dropped, the pane is still killed while the Tokio runtime is alive. A layout is a Layout by name, or a saved string from Window::layout() that restores pane sizes exactly; the mirrored layouts need tmux 3.5, and a saved string that tmux 3.8 produced is refused by an older tmux. rotate() moves the panes round one position and keeps the layout.
Order
Changing the window
Renaming changes the name for every session that links the window. A name is sent as text, and only a TmuxArg::format() value is expanded: see [the crate documentation][crate#a-name-reaches-tmux-as-text]. Selecting makes the window active in the session this handle came through; respawning restarts the window's command and replaces every pane with the one it runs in, and fails while a pane is still running unless Respawn::Replacing says to kill it. resize() sets the window to an exact size in cells, and resize_by() moves one of its edges. Killing consumes the handle and closes the window in every session that links it.
Linking and moving
Linking puts the same window in another session, so a rename or a split shows in both; unlinking removes only this session's link, and tmux refuses when only one session holds the window. Moving places the window at an index, possibly in another session, and fails when the destination is occupied or absent; swapping trades places with another window. Linking, moving and swapping return Error::ServerMismatch for a window or session on another server.
Options and hooks
Read and set options at this window's scope: listings report what this window has set, not what it inherits, and typed_option() reads Ok(None) for an option that holds nothing here. set_typed_option() checks the value against tmux's option table before anything is sent, set_option() sends text and leaves tmux to refuse it, and OptionValue says how the reads and writes fit together. tmux does not enumerate the hooks set on a window, so there is no listing: read one by name with hook(), which gives Ok(None) when it holds nothing.
Formats and messages
Expand a tmux format in this window's context and get the text back, or show a message to the clients viewing it. Both read their text as a format, so command and recursive formats can run shell commands, and display() succeeds when nobody is watching.

Anything tmux can do to a window that is not here is reachable through cmd(), which runs an arbitrary command against it and hands back its result.

Examples#

use libtmux::SplitDirection;
let guard = libtmux::test::TestServer::new().await?;
let session = guard.server().new_session("work").await?;
let window = session.active_window().await?.expect("a session has a window");
// Splitting is detached by default, so focus stays where it was.
window.split(SplitDirection::Below).await?;
assert_eq!(window.panes().await?.len(), 2);
guard.shutdown().await?;

Members57#

Parent objects1#

  • session method Return the session this window was reached through.

Collections and queries2#

  • panes method List this window's panes, preserving any failure.
  • search_panes method The panes under this window that a matcher accepts, reporting why if the listing fails.

Common operations45#

  • select_layout method Set the window's pane layout.
  • kill method Kill the window, closing it in every session that links it.
  • rename method Rename the window and update this handle.
  • link_to method Link this window into another session, so both hold the same window.
  • unlink method Remove this session's link to the window, leaving other links intact.
  • select method Make this window active in the session it was reached through.
  • id method Return the tmux window identity.
  • name method Return the window name.
  • move_to method Move this window to an index, possibly in another session.
  • split method Split this window and return the new pane.
  • height method Return the window height in cells.
  • width method Return the window width in cells.
  • options method Read every option set at this window, decoded by its declared kind.
  • index method Return the window's index within Window::session_id().
  • resize method Resize the window to an exact size in cells.
  • rotate method Move the window's panes round one position, keeping the layout.
  • set_option method Set one option to text, unchecked.
  • unset_option method Remove one option, restoring whatever it inherits.
  • is_active method Report whether this window is the active one in its session.
  • layout method Return the window's pane layout string.
  • respawn method Restart the window's command in place.
  • swap_with method Swap this window's position with another.
  • active_pane method Return the window's active pane.
  • typed_option method Read one option, decoded according to what tmux declares about it.
  • next_layout method Move to the next named layout, and return the window.
  • set_hook method Set one hook to a tmux command.
  • unset_hook method Remove one hook.
  • refresh method Replace this handle's snapshot with the window's current state.
  • previous_layout method Move to the previous named layout, and return the window.
  • last_pane method Move to the pane that was active before this one, and return it.
  • pane_count method Return how many panes the window contains.
  • linked_sessions method The sessions this window is linked into, reporting why if it cannot.
  • display method Show a message on the clients viewing this window.
  • cmd method Run a raw tmux command against this window.
  • session_id method Return the session this handle reached the window through.
  • last_activity method Return when the window last produced output.
  • is_linked method Report whether the window is linked into more than one session.
  • set_hooks method Write a whole hook at once.
  • from_env method Find the window this process is running in.
  • focus_direction method Move focus one pane in this direction, and report where it landed.
  • format method Expand a tmux format string in this window's context.
  • get method Read one field of this window's snapshot, named by the handle that filters it.
  • hook method Read one hook's commands, or None when it holds nothing.
  • resize_by method Resize the window to an exact size in cells.
  • set_typed_option method Set one option to a typed value, checked before it is sent.

Other members9#

  • append_option method Append to one option rather than replacing it.
  • from_env_value method Find a window from an explicit TMUX_PANE value.
  • has_activity method Report whether the window has unseen activity in this session.
  • has_bell method Report whether the window rang a bell in this session.
  • is_zoomed method Report whether one of the window's panes is zoomed to fill it.
  • option_names method List the option names set at this window's scope.
  • pane_at method Find this window's pane at the given index.
  • refreshed method Return a new handle holding the window's current state.
  • with_pane method Create a pane, run an operation with it, then kill it.

Guides#

Pages that discuss Window.

In other ports#

A tmux window

Equivalents of A tmux window in other languages
Language Equivalent
Python libtmux.Window
Ruby LibTmux::Window
Lua libtmux.Window
PowerShell LibTmux\Get-TmuxWindow This cmdlet reads shared .NET LibTmux.Window placements. Use -Server for all sessions or -Session for one session.
Julia LibTmux.WindowSnapshot WindowSnapshot holds captured physical-window data. WindowLink records a placement in a session; actions use WindowRef.
Erlang #tmux_model:window{} A physical window can have several session memberships. window_link holds the session-relative index and active flag.
Elixir LibTmux.Window Window is a physical window. WindowLink records its session index and active state.
Haskell No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing.
Common Lisp libtmux:window window is a physical captured window. window-link preserves each session placement.
TypeScript window.Window
Go tmux.Window
Java io.github.libtmux.Window
Clojure libtmux.data/windows Traverses captured window-placement maps without I/O; the window value is a map with an explicit Java reference for effects.
Kotlin io.github.libtmux.kotlin.Window
Scala io.github.libtmux.scaladsl.Window
C# LibTmux.Window
F# LibTmux.FSharp.Window This F# module identifies shared .NET LibTmux.Window placements and builds deferred pane queries. Query.list acquires their results from tmux.
C++ libtmux::Window
Swift Window
OCaml Libtmux.Window.t A global window can have several session placements. Window_link holds the session, index and current flag.
Perl LibTmux::Window Physical window identity. WindowLink owns each session/index placement.
Esc

Type to search.

Reference previewOpen reference