Windows

class libtmux.Window
class libtmux.Window

Bases: Obj, OptionsMixin, HooksMixin

tmux(1) Window [window_manual].

Holds Pane objects.

Reading it. Every field is a tmux format token read when the window was listed or last refreshed, and is None when tmux gave no value. refresh() rewrites the fields in place and raises TmuxObjectDoesNotExist when the window has gone.

Finding it. from_window_id() asks tmux for one window and raises TmuxObjectDoesNotExist when it is not there. from_env() resolves the window of the pane this process runs inside, and raises NotInsideTmux outside one.

Finding its neighbours. A window can sit in several sessions. session is the session recorded on this instance, and linked_sessions lists every one that holds the window, each once, and is empty when either listing it needs fails. active_pane is None when no pane is active.

Splitting and arranging. split() divides the active pane, beneath it by default, and returns the new Pane. Passing both size and percentage raises ValueError, and flags newer than the running tmux warn and are ignored. A layout name and a layout flag together raise ValueError in select_layout(). Floating panes need tmux 3.7 or later.

Linking and moving. link() shows the window in another session as well, and unlink() removes it from the current one. move_window() with renumber=True only renumbers the windows and moves nothing.

Changing it. rename_window() refreshes the window and returns it. respawn() documents kill=True as required if the window is still active.

Options and hooks. An option or hook call acts on the window scope by default. The setters return the window, so calls chain, and an unknown or invalid name raises OptionError or one of its subclasses.

Parameters:

session (Session)

Examples

>>> window = session.new_window('My project', attach=True)
>>> window
Window(@2 2:My project, Session($... ...))

Windows have panes:

>>> window.panes
[Pane(...)]
>>> window.active_pane
Pane(...)

Relations moving up:

>>> window.session
Session(...)
>>> window.window_id == session.active_window.window_id
True
>>> window == session.active_window
True
>>> window in session.windows
True

The window can be used as a context manager to ensure proper cleanup:

>>> with session.new_window() as window:
...     pane = window.split()
...     # Do work with the pane
...     # Window will be killed automatically when exiting the context

References

[window_manual]
tmux window. openbsd manpage for TMUX(1).

“Each session has one or more windows linked to it. A window occupies the entire screen and may be split into rectangular panes…”

https://man.openbsd.org/tmux.1#DESCRIPTION. Accessed April 1st, 2018.