Internal Constants

The libtmux._internal.constants module documents private constants used inside libtmux.

Warning

Be careful with these! These constants are private, internal as they’re not covered by version policies. They can break or be removed between minor versions!

If you need a data structure here made public or stabilized please file an issue.

Internal constants.

class libtmux._internal.constants.ServerOptions
class libtmux._internal.constants.ServerOptions

Bases: SkipDefaultFieldsReprMixin

Container for tmux server options.

Each field carries the value of the tmux server option named the same with hyphens in place of underscores. A field keeps its default — None, or an empty container for the array options — when tmux reports no value for it.

class libtmux._internal.constants.SessionOptions
class libtmux._internal.constants.SessionOptions

Bases: SkipDefaultFieldsReprMixin

Container for tmux session options.

Each field carries the value of the tmux session option named the same with hyphens in place of underscores. A field keeps its default — None, or an empty container for the array options — when tmux reports no value for it.

class libtmux._internal.constants.WindowOptions
class libtmux._internal.constants.WindowOptions

Bases: SkipDefaultFieldsReprMixin

Container for tmux window options.

Each field carries the value of the tmux window option named the same with hyphens in place of underscores, and is None when tmux reports no value for it.

class libtmux._internal.constants.PaneOptions
class libtmux._internal.constants.PaneOptions

Bases: SkipDefaultFieldsReprMixin

Container for tmux pane options.

Each field carries the value of the tmux pane option named the same with hyphens in place of underscores, and is None when tmux reports no value for it.

class libtmux._internal.constants.Options
class libtmux._internal.constants.Options

Bases: ServerOptions, SessionOptions, WindowOptions, PaneOptions, SkipDefaultFieldsReprMixin

Container for all tmux options (server, session, window, and pane).

class libtmux._internal.constants.Hooks
class libtmux._internal.constants.Hooks

Bases: SkipDefaultFieldsReprMixin

tmux hooks data structure.

Parses tmux hook output into typed SparseArray fields, preserving array indices for hooks that can have multiple commands at different indices. A field holds an empty SparseArray when tmux reports no commands for that hook.

Examples

Parse raw tmux hook output:

>>> from libtmux._internal.constants import Hooks
>>> raw = [
...     "session-renamed[0] set-option -g status-left-style bg=red",
...     "session-renamed[1] display-message 'session renamed'",
... ]
>>> hooks = Hooks.from_stdout(raw)

Access individual hook commands by index:

>>> hooks.session_renamed[0]
'set-option -g status-left-style bg=red'
>>> hooks.session_renamed[1]
"display-message 'session renamed'"

Get all commands as a list (sorted by index):

>>> hooks.session_renamed.as_list()
['set-option -g status-left-style bg=red', "display-message 'session renamed'"]

Sparse indices are preserved (gaps in index numbers):

>>> raw_sparse = [
...     "pane-focus-in[0] refresh-client",
...     "pane-focus-in[5] display-message 'focus'",
... ]
>>> hooks_sparse = Hooks.from_stdout(raw_sparse)
>>> 0 in hooks_sparse.pane_focus_in
True
>>> 5 in hooks_sparse.pane_focus_in
True
>>> 3 in hooks_sparse.pane_focus_in
False
>>> sorted(hooks_sparse.pane_focus_in.keys())
[0, 5]

Iterate over values in index order:

>>> for cmd in hooks_sparse.pane_focus_in.iter_values():
...     print(cmd)
refresh-client
display-message 'focus'

Multiple hook types in one parse:

>>> raw_multi = [
...     "after-new-window[0] select-pane -t 0",
...     "after-new-window[1] send-keys 'clear' Enter",
...     "window-renamed[0] refresh-client -S",
... ]
>>> hooks_multi = Hooks.from_stdout(raw_multi)
>>> len(hooks_multi.after_new_window)
2
>>> len(hooks_multi.window_renamed)
1