Skip to content

v0.68.0 - Raise on closed panes, reuse windows by index

Latest

Choose a tag to compare

@tony tony released this 25 Nov 01:18

libtmux 0.68.0 raises TmuxObjectDoesNotExist when a pane, window or session has closed, instead of returning [] from Pane.capture_pane() or None from Pane.send_keys(). Server.run_shell() raises VersionTooLow on tmux 3.3a and 3.4 rather than returning [] when tmux leaves the output in copy mode, Session.new_window() with select_existing=True reuses an existing window by index or target on every tmux, and expand_formats is the one parameter name for tmux's -F.

Highlights

  • Closed panes, windows and sessions raise TmuxObjectDoesNotExist. Pane.capture_pane() and Pane.send_keys() previously returned [] and None when their pane had closed, and methods that already raised for a missing session, window or pane raised the base LibTmuxException. They now raise TmuxObjectDoesNotExist, a LibTmuxException subclass so except LibTmuxException still matches. send_keys() and Pane.enter() also raise LibTmuxException on other tmux errors (#902).
  • run_shell() raises VersionTooLow on tmux 3.3a and 3.4 instead of returning []. On tmux 3.3a and 3.4, a foreground run-shell leaves its output in copy mode and sends nothing back to the caller. Server.run_shell() now raises VersionTooLow there; calls with background=True, as_tmux_command=True or target_pane= run as before (#918).
  • select_existing=True reuses by index or target on every tmux. Session.new_window() looks up the window at window_index or target_window itself instead of sending new-window -S, so reuse returns the existing Window instead of raising IndexError or failing with "index in use" on tmux 3.3a through 3.7. Passing window_name alongside an index or window ID raises LibTmuxException when the window there has another name, and combining select_existing=True with kill_existing=True raises ValueError (#827). Entering with on a reused Window still kills it on exit (#926; see Context managers), and Format("#{command}") never matches an existing window because the lookup expands it with display-message while tmux names the window new-window (#921; see Literal text and tmux formats).
  • expand_formats is the one name for tmux's -F. Session.set_environment(), Server.command_prompt() and Session.set_option() (along with server, window and pane set_option()) take expand_formats, the same name Pane.send_keys() uses. expand_format and _format still work and emit DeprecationWarning (#919).

To handle panes that may close before capture:

from libtmux import exc

try:
    lines = pane.capture_pane()
except exc.TmuxObjectDoesNotExist:
    lines = []

See the migration notes and the changelog for the full list.

What's Changed

  • Session(docs[new_window]): Note the #{command} lookup limit by @tony in #921
  • tests(Session,Window): Wait for the shell before reading env output by @tony in #922
  • libtmux(feat[expand_formats]): One name for -F by @tony in #919
  • Server(fix[run_shell]): Refuse output tmux keeps by @tony in #918
  • Session(fix[new_window]): Reuse by index or target on every tmux by @tony in #827
  • tmux(fix[errors]): Raise TmuxObjectDoesNotExist for a closed target by @tony in #902
  • Session(docs[new_window]): Note Window.__exit__ on select_existing reuse by @tony in #926

Full Changelog: v0.67.1...v0.68.0