Skip to content

Commit 866f11a

Browse files
committed
docs: explain engine selection and control mode
1 parent 9dd8a01 commit 866f11a

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

docs/api/servers.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
tmux initializes a server automatically on first running (e.g. executing `tmux`)
1111

12+
:::{tip}
13+
Inject a different command engine when constructing :class:`~libtmux.Server`
14+
to change how tmux commands are executed. See {ref}`engines-topic` for details.
15+
:::
16+
1217
```{eval-rst}
1318
.. autoclass:: libtmux.Server
1419
:members:

docs/quickstart.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ First, we can grab a {class}`Server`.
9898
>>> server = libtmux.Server()
9999
>>> server
100100
Server(socket_path=/tmp/tmux-.../default)
101+
102+
If you want to persist a control-mode connection instead of launching a
103+
short-lived ``tmux`` process for every command, inject a different engine at
104+
construction time:
105+
106+
```python
107+
>>> from libtmux.engines import ControlModeEngine
108+
>>> server = libtmux.Server(engine=ControlModeEngine())
109+
```
110+
111+
The rest of the API remains identical regardless of the engine you choose.
101112
```
102113

103114
:::{tip}

docs/topics/engines.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
(engines-topic)=
2+
3+
# Command Engines
4+
5+
libtmux can execute tmux commands through different "engines"—pluggable
6+
backends that share the same high-level API but vary in transport mechanics.
7+
This abstraction keeps the Python surface area stable while allowing you to
8+
choose the best option for your environment.
9+
10+
## Available engines
11+
12+
``SubprocessEngine`` (default)
13+
: Launches a short-lived ``tmux`` process for each command, matching the
14+
behaviour libtmux shipped with historically. This is the most broadly
15+
compatible approach and requires no extra configuration.
16+
17+
``ControlModeEngine``
18+
: Starts ``tmux`` with the ``-C`` flag and communicates using tmux’s control
19+
mode protocol. Because it keeps a persistent control connection open, it can
20+
be more efficient for workflows that issue many commands in rapid succession
21+
and is a stepping stone toward richer, event-driven integrations.
22+
23+
Both engines expose the same :class:`~libtmux.engines.base.CommandResult`
24+
contract, so all existing consumers (e.g., :class:`~libtmux.Server`,
25+
:class:`~libtmux.Session`, :class:`~libtmux.Window`, :class:`~libtmux.Pane`)
26+
continue to operate identically regardless of which engine you choose.
27+
28+
## Choosing an engine
29+
30+
```python
31+
>>> import libtmux
32+
>>> from libtmux.engines import ControlModeEngine
33+
>>> server = libtmux.Server(engine=ControlModeEngine())
34+
```
35+
36+
If you omit the ``engine`` argument, libtmux defaults to
37+
:class:`~libtmux.engines.subprocess.SubprocessEngine` for full backward
38+
compatibility. You can inject the engine at construction time—fixtures in the
39+
test suite demonstrate this pattern—and all child objects created from the
40+
server inherit the same backend automatically.
41+
42+
## Compatibility notes
43+
44+
- Control mode is available in tmux 2.1 and newer. Ensure your tmux binary
45+
supports ``-C`` before opting in.
46+
- When using control mode, libtmux opens a dedicated tmux process per engine
47+
instance. Create one :class:`~libtmux.Server` per desired control connection
48+
to avoid unnecessary processes.
49+
- Both engines honour ``socket_name``, ``socket_path`` and ``config_file``
50+
options just like the CLI would; the abstraction only swaps out how commands
51+
are forwarded to tmux.
52+
53+
For deeper architectural background, explore the {ref}`traversal` topic to see
54+
how commands flow through libtmux’s object model.

docs/topics/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ Explore libtmux’s core functionalities and underlying principles at a high lev
1010
1111
context_managers
1212
traversal
13+
engines
1314
```

0 commit comments

Comments
 (0)