Skip to content

Commit 79e5573

Browse files
committed
refactor(server): integrate Engine abstraction and use SubprocessEngine
1 parent b7e7726 commit 79e5573

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/libtmux/server.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import warnings
1717

1818
from libtmux import exc, formats
19+
from libtmux._internal.engines.subprocess_engine import SubprocessEngine
1920
from libtmux._internal.query_list import QueryList
2021
from libtmux.common import tmux_cmd
2122
from libtmux.neo import fetch_objs
@@ -38,6 +39,7 @@
3839

3940
from typing_extensions import Self
4041

42+
from libtmux._internal.engines.base import Engine
4143
from libtmux._internal.types import StrPath
4244

4345
DashLiteral: TypeAlias = t.Literal["-"]
@@ -126,12 +128,17 @@ def __init__(
126128
colors: int | None = None,
127129
on_init: t.Callable[[Server], None] | None = None,
128130
socket_name_factory: t.Callable[[], str] | None = None,
131+
engine: Engine | None = None,
129132
**kwargs: t.Any,
130133
) -> None:
131134
EnvironmentMixin.__init__(self, "-g")
132135
self._windows: list[WindowDict] = []
133136
self._panes: list[PaneDict] = []
134137

138+
if engine is None:
139+
engine = SubprocessEngine()
140+
self.engine = engine
141+
135142
if socket_path is not None:
136143
self.socket_path = socket_path
137144
elif socket_name is not None:
@@ -222,7 +229,12 @@ def raise_if_dead(self) -> None:
222229
if self.config_file:
223230
cmd_args.insert(0, f"-f{self.config_file}")
224231

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+
)
226238

227239
#
228240
# Command
@@ -298,7 +310,7 @@ def cmd(
298310

299311
cmd_args = ["-t", str(target), *args] if target is not None else [*args]
300312

301-
return tmux_cmd(*svr_args, *cmd_args)
313+
return self.engine.run(*svr_args, *cmd_args)
302314

303315
@property
304316
def attached_sessions(self) -> list[Session]:

0 commit comments

Comments
 (0)