Skip to content

Commit d7d1707

Browse files
committed
Server(fix[confirm_before,command_prompt]): gate -b behind has_gte_version("3.3")
why: Both methods unconditionally emit -b despite their docstrings noting it requires tmux 3.3+. On older tmux this causes a hard command error instead of the project-convention warn-and-skip behaviour. what: - confirm_before: add has_gte_version("3.3") guard; warn and skip -b on older tmux - command_prompt: same - Add lazy imports for warnings and has_gte_version inside each method, matching the pattern already used in pane.py
1 parent 1324372 commit d7d1707

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/libtmux/server.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,19 @@ def confirm_before(
866866
... server.cmd('show-options', '-gv', '@cf_test').stdout[0]
867867
'yes'
868868
"""
869-
tmux_args: tuple[str, ...] = ("-b",)
869+
import warnings
870+
871+
from libtmux.common import has_gte_version
872+
873+
tmux_args: tuple[str, ...] = ()
874+
875+
if has_gte_version("3.3", tmux_bin=self.tmux_bin):
876+
tmux_args += ("-b",)
877+
else:
878+
warnings.warn(
879+
"confirm_before -b requires tmux 3.3+, ignoring",
880+
stacklevel=2,
881+
)
870882

871883
if prompt is not None:
872884
tmux_args += ("-p", prompt)
@@ -941,7 +953,19 @@ def command_prompt(
941953
... server.cmd('show-options', '-gv', '@cp_test').stdout[0]
942954
'hi'
943955
"""
944-
tmux_args: tuple[str, ...] = ("-b",)
956+
import warnings
957+
958+
from libtmux.common import has_gte_version
959+
960+
tmux_args: tuple[str, ...] = ()
961+
962+
if has_gte_version("3.3", tmux_bin=self.tmux_bin):
963+
tmux_args += ("-b",)
964+
else:
965+
warnings.warn(
966+
"command_prompt -b requires tmux 3.3+, ignoring",
967+
stacklevel=2,
968+
)
945969

946970
if one_key:
947971
tmux_args += ("-1",)

0 commit comments

Comments
 (0)