|
16 | 16 | import warnings |
17 | 17 |
|
18 | 18 | from libtmux import exc, formats |
| 19 | +from libtmux._internal.engines.subprocess_engine import SubprocessEngine |
19 | 20 | from libtmux._internal.query_list import QueryList |
20 | 21 | from libtmux.common import tmux_cmd |
21 | 22 | from libtmux.neo import fetch_objs |
|
38 | 39 |
|
39 | 40 | from typing_extensions import Self |
40 | 41 |
|
| 42 | + from libtmux._internal.engines.base import Engine |
41 | 43 | from libtmux._internal.types import StrPath |
42 | 44 |
|
43 | 45 | DashLiteral: TypeAlias = t.Literal["-"] |
@@ -126,12 +128,17 @@ def __init__( |
126 | 128 | colors: int | None = None, |
127 | 129 | on_init: t.Callable[[Server], None] | None = None, |
128 | 130 | socket_name_factory: t.Callable[[], str] | None = None, |
| 131 | + engine: Engine | None = None, |
129 | 132 | **kwargs: t.Any, |
130 | 133 | ) -> None: |
131 | 134 | EnvironmentMixin.__init__(self, "-g") |
132 | 135 | self._windows: list[WindowDict] = [] |
133 | 136 | self._panes: list[PaneDict] = [] |
134 | 137 |
|
| 138 | + if engine is None: |
| 139 | + engine = SubprocessEngine() |
| 140 | + self.engine = engine |
| 141 | + |
135 | 142 | if socket_path is not None: |
136 | 143 | self.socket_path = socket_path |
137 | 144 | elif socket_name is not None: |
@@ -222,7 +229,12 @@ def raise_if_dead(self) -> None: |
222 | 229 | if self.config_file: |
223 | 230 | cmd_args.insert(0, f"-f{self.config_file}") |
224 | 231 |
|
225 | | - subprocess.check_call([tmux_bin, *cmd_args]) |
| 232 | + proc = self.engine.run(*cmd_args) |
| 233 | + if proc.returncode is not None and proc.returncode != 0: |
| 234 | + raise subprocess.CalledProcessError( |
| 235 | + returncode=proc.returncode, |
| 236 | + cmd=[tmux_bin, *cmd_args], |
| 237 | + ) |
226 | 238 |
|
227 | 239 | # |
228 | 240 | # Command |
@@ -298,7 +310,7 @@ def cmd( |
298 | 310 |
|
299 | 311 | cmd_args = ["-t", str(target), *args] if target is not None else [*args] |
300 | 312 |
|
301 | | - return tmux_cmd(*svr_args, *cmd_args) |
| 313 | + return self.engine.run(*svr_args, *cmd_args) |
302 | 314 |
|
303 | 315 | @property |
304 | 316 | def attached_sessions(self) -> list[Session]: |
|
0 commit comments