Skip to content

Commit 53f92a1

Browse files
committed
Server(feat[list_clients]): add list_clients() wrapping tmux list-clients
why: list-clients is needed for monitoring connected clients and multi-client session management. what: - Add Server.list_clients() returning raw stdout lines - Returns empty list when no clients are attached - Add test verifying return type
1 parent c8e9fb7 commit 53f92a1

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

src/libtmux/server.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,26 @@ def list_buffers(self) -> list[str]:
718718

719719
return proc.stdout
720720

721+
def list_clients(self) -> list[str]:
722+
"""List connected clients via ``$ tmux list-clients``.
723+
724+
Returns
725+
-------
726+
list[str]
727+
Raw output lines from list-clients.
728+
729+
Examples
730+
--------
731+
>>> isinstance(server.list_clients(), list)
732+
True
733+
"""
734+
proc = self.cmd("list-clients")
735+
736+
if proc.stderr:
737+
raise exc.LibTmuxException(proc.stderr)
738+
739+
return proc.stdout
740+
721741
def switch_client(self, target_session: str) -> None:
722742
"""Switch tmux client.
723743

tests/test_server.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,13 @@ def test_list_buffers(server: Server) -> None:
605605
assert len(result) >= 2
606606

607607

608+
def test_list_clients(server: Server) -> None:
609+
"""Test Server.list_clients() returns list without error."""
610+
server.new_session(session_name="list_clients_test")
611+
result = server.list_clients()
612+
assert isinstance(result, list)
613+
614+
608615
def test_new_session_config_file(
609616
server: Server,
610617
tmp_path: pathlib.Path,

0 commit comments

Comments
 (0)