Skip to content

Commit 50d2ab4

Browse files
committed
ControlModeEngine(feat): Add set_client_flags() for runtime flag control
Add method to set tmux client flags at runtime via `refresh-client -f`: - no_output: Filter %output notifications (reduce noise) - pause_after: Pause output after N seconds (flow control) This follows tmux's design where CLIENT_CONTROL_* flags are runtime modifiable, not connection-time parameters. Also fix ServerContext.to_args() to produce concatenated form (e.g., "-Lsocket_name") matching Server._build_server_args().
1 parent 15f556d commit 50d2ab4

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

src/libtmux/_internal/engines/base.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@ class ServerContext:
2626
config_file: str | None = None
2727

2828
def to_args(self) -> tuple[str, ...]:
29-
"""Convert context to tmux server argument tuple."""
29+
"""Convert context to tmux server argument tuple.
30+
31+
Returns args in concatenated form (e.g., ``-Lsocket_name``) to match
32+
the format used by ``Server._build_server_args()``.
33+
"""
3034
args: list[str] = []
3135
if self.socket_name:
32-
args.extend(["-L", self.socket_name])
36+
args.append(f"-L{self.socket_name}")
3337
if self.socket_path:
34-
args.extend(["-S", str(self.socket_path)])
38+
args.append(f"-S{self.socket_path}")
3539
if self.config_file:
36-
args.extend(["-f", str(self.config_file)])
40+
args.append(f"-f{self.config_file}")
3741
return tuple(args)
3842

3943

src/libtmux/_internal/engines/control_mode.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,53 @@ def drain_notifications(
311311
msg = f"Notification queue did not become idle within {timeout}s"
312312
raise TimeoutError(msg)
313313

314+
def set_client_flags(
315+
self,
316+
*,
317+
no_output: bool | None = None,
318+
pause_after: int | None = None,
319+
) -> None:
320+
"""Set control client flags via refresh-client.
321+
322+
These correspond to tmux's runtime client flags (set via
323+
``refresh-client -f``), not connection-time parameters. This follows
324+
tmux's design where CLIENT_CONTROL_* flags are modified at runtime.
325+
326+
Parameters
327+
----------
328+
no_output : bool, optional
329+
Filter %output notifications (reduces noise when attached to active panes).
330+
Set to True to enable, False to disable, None to leave unchanged.
331+
pause_after : int, optional
332+
Pause output after N seconds of buffering (flow control).
333+
Set to 0 to disable, positive int to enable, None to leave unchanged.
334+
335+
Examples
336+
--------
337+
>>> engine.set_client_flags(no_output=True) # doctest: +SKIP
338+
>>> engine.set_client_flags(pause_after=5) # doctest: +SKIP
339+
>>> engine.set_client_flags(no_output=False) # doctest: +SKIP
340+
"""
341+
flags: list[str] = []
342+
if no_output is True:
343+
flags.append("no-output")
344+
elif no_output is False:
345+
flags.append("no-output=off")
346+
347+
if pause_after is not None:
348+
if pause_after == 0:
349+
flags.append("pause-after=none")
350+
else:
351+
flags.append(f"pause-after={pause_after}")
352+
353+
if flags:
354+
server_args = self._server_context.to_args() if self._server_context else ()
355+
self.run(
356+
"refresh-client",
357+
cmd_args=("-f", ",".join(flags)),
358+
server_args=server_args,
359+
)
360+
314361
def get_stats(self) -> EngineStats:
315362
"""Return diagnostic statistics for the engine."""
316363
return self._protocol.get_stats(restarts=self._restarts)

0 commit comments

Comments
 (0)