Panes

class libtmux.Pane
class libtmux.Pane

Bases: Obj, OptionsMixin, HooksMixin

tmux(1) Pane [pane_manual].

Pane instances can send commands directly to a pane, or traverse between linked tmux objects.

Reading it. Every field is a tmux format token read when the pane was listed or last refreshed, and is None when tmux gave no value. refresh() rewrites the fields in place and raises TmuxObjectDoesNotExist when the pane has gone. The edge properties convert tmux’s flags to bools.

Finding it. from_pane_id() asks tmux for one pane and raises TmuxObjectDoesNotExist when it is not there. from_env() returns the pane this process runs inside, read from $TMUX and $TMUX_PANE, and raises NotInsideTmux outside one.

Finding its parents. Each access asks tmux.

Sending input. send_keys() presses Enter after the keys unless enter=False, and sends them literally with literal=True. Called without keys it needs reset, repeat or copy_mode_cmd, and raises ValueError otherwise.

Reading output. capture_pane() returns a list with one string per row. start and end count from the first visible line, with negative numbers reaching into the history, - for the start of the history as start and for the end of the visible pane as end. With to_buffer it stores the capture in a tmux buffer and returns None. A flag newer than the running tmux warns and is ignored.

Splitting and arranging. split() divides this exact pane, beneath it by default, and returns the new pane. Passing both size and percentage raises ValueError. A resize takes an adjustment, a height and width, or zoom, and a height or width given as text must be digits or a percentage.

Modes, pipes and history. pipe() copies the pane’s output to a shell command, and stops piping when given no command. clear_history() forgets the scrollback, and reset() also resets the terminal state.

Changing it. respawn() documents kill=True as required if the pane is still active. kill() takes all_except to kill every other pane in the window instead.

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

Examples

>>> pane
Pane(%1 Window(@1 1:..., Session($1 ...)))
>>> pane in window.panes
True
>>> pane.window
Window(@1 1:..., Session($1 ...))
>>> pane.session
Session($1 ...)

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

>>> with window.split() as pane:
...     pane.send_keys('echo "Hello"')
...     # Do work with the pane
...     # Pane will be killed automatically when exiting the context

Notes

Changed in version 0.8: Renamed from .tmux to .cmd.

References

[pane_manual]
tmux pane. openbsd manpage for TMUX(1).

“Each window displayed by tmux may be split into one or more panes; each pane takes up a certain area of the display and is a separate terminal.”

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