Skip to content

Commit 05d8d78

Browse files
committed
Pane(feat): fill missing flag gaps on interactive commands
why: Interactive pane commands were wrapped with minimal flags. Fill useful parameters for better programmatic control. what: - copy_mode: add scroll_up (-u), exit_on_copy (-e), mouse_drag (-M), quiet (-q) parameters - display_panes: add duration (-d), no_select (-N) parameters - choose_tree: add windows_only (-w) parameter - find_window: add match_content (-C), case_insensitive (-i), match_name (-N), regex (-r), match_title (-T) parameters
1 parent 6c8de6a commit 05d8d78

1 file changed

Lines changed: 101 additions & 9 deletions

File tree

src/libtmux/pane.py

Lines changed: 101 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,14 +1367,26 @@ def pipe(
13671367
if proc.stderr:
13681368
raise exc.LibTmuxException(proc.stderr)
13691369

1370-
def copy_mode(self, *, bottom: bool | None = None) -> None:
1370+
def copy_mode(
1371+
self,
1372+
*,
1373+
scroll_up: bool | None = None,
1374+
exit_on_copy: bool | None = None,
1375+
mouse_drag: bool | None = None,
1376+
quiet: bool | None = None,
1377+
) -> None:
13711378
"""Enter copy mode via ``$ tmux copy-mode``.
13721379
13731380
Parameters
13741381
----------
1375-
bottom : bool, optional
1376-
Start at the bottom of the history (``-u`` flag inverted — default
1377-
starts at bottom, ``-u`` starts at top/scrollback).
1382+
scroll_up : bool, optional
1383+
Start scrolled up one page (``-u`` flag).
1384+
exit_on_copy : bool, optional
1385+
Exit copy mode after copying (``-e`` flag).
1386+
mouse_drag : bool, optional
1387+
Start mouse drag (``-M`` flag).
1388+
quiet : bool, optional
1389+
Quiet mode (``-q`` flag).
13781390
13791391
Examples
13801392
--------
@@ -1386,6 +1398,18 @@ def copy_mode(self, *, bottom: bool | None = None) -> None:
13861398
"""
13871399
tmux_args: tuple[str, ...] = ()
13881400

1401+
if scroll_up:
1402+
tmux_args += ("-u",)
1403+
1404+
if exit_on_copy:
1405+
tmux_args += ("-e",)
1406+
1407+
if mouse_drag:
1408+
tmux_args += ("-M",)
1409+
1410+
if quiet:
1411+
tmux_args += ("-q",)
1412+
13891413
proc = self.cmd("copy-mode", *tmux_args)
13901414

13911415
if proc.stderr:
@@ -1407,17 +1431,37 @@ def clock_mode(self) -> None:
14071431
if proc.stderr:
14081432
raise exc.LibTmuxException(proc.stderr)
14091433

1410-
def display_panes(self) -> None:
1434+
def display_panes(
1435+
self,
1436+
*,
1437+
duration: int | None = None,
1438+
no_select: bool | None = None,
1439+
) -> None:
14111440
"""Show pane numbers via ``$ tmux display-panes``.
14121441
14131442
Requires an attached client.
14141443
1444+
Parameters
1445+
----------
1446+
duration : int, optional
1447+
Duration in milliseconds to display pane numbers (``-d`` flag).
1448+
no_select : bool, optional
1449+
Do not select a pane on keypress (``-N`` flag).
1450+
14151451
Examples
14161452
--------
14171453
>>> with control_mode() as ctl:
14181454
... window.active_pane.display_panes()
14191455
"""
1420-
proc = self.server.cmd("display-panes")
1456+
tmux_args: tuple[str, ...] = ()
1457+
1458+
if duration is not None:
1459+
tmux_args += ("-d", str(duration))
1460+
1461+
if no_select:
1462+
tmux_args += ("-N",)
1463+
1464+
proc = self.server.cmd("display-panes", *tmux_args)
14211465

14221466
if proc.stderr:
14231467
raise exc.LibTmuxException(proc.stderr)
@@ -1446,13 +1490,20 @@ def choose_client(self) -> None:
14461490
if proc.stderr:
14471491
raise exc.LibTmuxException(proc.stderr)
14481492

1449-
def choose_tree(self, *, sessions_only: bool | None = None) -> None:
1493+
def choose_tree(
1494+
self,
1495+
*,
1496+
sessions_only: bool | None = None,
1497+
windows_only: bool | None = None,
1498+
) -> None:
14501499
"""Enter tree chooser via ``$ tmux choose-tree``.
14511500
14521501
Parameters
14531502
----------
14541503
sessions_only : bool, optional
14551504
Only show sessions, not windows (``-s`` flag).
1505+
windows_only : bool, optional
1506+
Only show windows, not sessions (``-w`` flag).
14561507
14571508
Examples
14581509
--------
@@ -1463,6 +1514,9 @@ def choose_tree(self, *, sessions_only: bool | None = None) -> None:
14631514
if sessions_only:
14641515
tmux_args += ("-s",)
14651516

1517+
if windows_only:
1518+
tmux_args += ("-w",)
1519+
14661520
proc = self.cmd("choose-tree", *tmux_args)
14671521

14681522
if proc.stderr:
@@ -1480,7 +1534,16 @@ def customize_mode(self) -> None:
14801534
if proc.stderr:
14811535
raise exc.LibTmuxException(proc.stderr)
14821536

1483-
def find_window(self, match_string: str) -> None:
1537+
def find_window(
1538+
self,
1539+
match_string: str,
1540+
*,
1541+
match_content: bool | None = None,
1542+
case_insensitive: bool | None = None,
1543+
match_name: bool | None = None,
1544+
regex: bool | None = None,
1545+
match_title: bool | None = None,
1546+
) -> None:
14841547
"""Search for a window matching a string via ``$ tmux find-window``.
14851548
14861549
Opens a choose-tree filtered to matching windows.
@@ -1489,12 +1552,41 @@ def find_window(self, match_string: str) -> None:
14891552
----------
14901553
match_string : str
14911554
String to search for in window names, titles, and content.
1555+
match_content : bool, optional
1556+
Match visible pane content (``-C`` flag).
1557+
case_insensitive : bool, optional
1558+
Case-insensitive matching (``-i`` flag).
1559+
match_name : bool, optional
1560+
Match window name only (``-N`` flag).
1561+
regex : bool, optional
1562+
Treat match string as a regex (``-r`` flag).
1563+
match_title : bool, optional
1564+
Match pane title (``-T`` flag).
14921565
14931566
Examples
14941567
--------
14951568
>>> pane.find_window('sh')
14961569
"""
1497-
proc = self.cmd("find-window", match_string)
1570+
tmux_args: tuple[str, ...] = ()
1571+
1572+
if match_content:
1573+
tmux_args += ("-C",)
1574+
1575+
if case_insensitive:
1576+
tmux_args += ("-i",)
1577+
1578+
if match_name:
1579+
tmux_args += ("-N",)
1580+
1581+
if regex:
1582+
tmux_args += ("-r",)
1583+
1584+
if match_title:
1585+
tmux_args += ("-T",)
1586+
1587+
tmux_args += (match_string,)
1588+
1589+
proc = self.cmd("find-window", *tmux_args)
14981590

14991591
if proc.stderr:
15001592
raise exc.LibTmuxException(proc.stderr)

0 commit comments

Comments
 (0)