Skip to content

Commit eb8f81b

Browse files
authored
Fix(split,new_window): Improvements and fixes (#534)
Follow up for #532
2 parents fe27280 + 271f7b9 commit eb8f81b

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

CHANGES

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ $ pip install --user --upgrade --pre libtmux
1919

2020
#### Improved new sessions (#532)
2121

22-
- `Session.new_window()` to {meth}`Session.new_window()`
22+
- `Session.new_window()`:
2323

2424
- Learned `direction`, via {class}`~libtmux.constants.WindowDirection`).
25+
- [PEP 3102] keyword-only arguments after window name (#534).
26+
27+
- Added {meth}`Window.new_window()` shorthand to create window based on that
28+
window's position.
29+
30+
[PEP 3102]: https://www.python.org/dev/peps/pep-3102/
2531

2632
#### Improved window splitting (#532)
2733

src/libtmux/pane.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def cmd(self, cmd: str, *args: t.Any) -> tmux_cmd:
149149

150150
def resize(
151151
self,
152+
/,
152153
# Adjustments
153154
adjustment_direction: t.Optional[ResizeAdjustmentDirection] = None,
154155
adjustment: t.Optional[int] = None,
@@ -489,6 +490,8 @@ def select_pane(self) -> "Pane":
489490

490491
def split(
491492
self,
493+
/,
494+
target: t.Optional[t.Union[int, str]] = None,
492495
start_directory: t.Optional[str] = None,
493496
attach: bool = False,
494497
direction: t.Optional[PaneDirection] = None,
@@ -502,6 +505,8 @@ def split(
502505
503506
Parameters
504507
----------
508+
target : optional
509+
Optional, custom *target-pane*, used by :meth:`Window.split`.
505510
attach : bool, optional
506511
make new window the current window after creating it, default
507512
True.
@@ -615,6 +620,9 @@ def split(
615620
if not attach:
616621
tmux_args += ("-d",)
617622

623+
if target is not None:
624+
tmux_args += (f"-t{target}",)
625+
618626
if environment:
619627
if has_gte_version("3.0"):
620628
for k, v in environment.items():
@@ -805,6 +813,7 @@ def at_right(self) -> bool:
805813
#
806814
def split_window(
807815
self,
816+
target: t.Optional[t.Union[int, str]] = None,
808817
attach: bool = False,
809818
start_directory: t.Optional[str] = None,
810819
vertical: bool = True,
@@ -842,6 +851,7 @@ def split_window(
842851
if size is None and percent is not None:
843852
size = f'{str(percent).rstrip("%")}%'
844853
return self.split(
854+
target=target,
845855
attach=attach,
846856
start_directory=start_directory,
847857
direction=PaneDirection.Below if vertical else PaneDirection.Right,

src/libtmux/session.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ def rename_session(self, new_name: str) -> "Session":
537537
def new_window(
538538
self,
539539
window_name: t.Optional[str] = None,
540+
*,
540541
start_directory: None = None,
541542
attach: bool = False,
542543
window_index: str = "",
@@ -635,6 +636,10 @@ def new_window(
635636
if window_name is not None and isinstance(window_name, str):
636637
window_args += ("-n", window_name)
637638

639+
if window_index is not None:
640+
# empty string for window_index will use the first one available
641+
window_args += (f"-t{self.session_id}:{window_index}",)
642+
638643
if environment:
639644
if has_gte_version("3.0"):
640645
for k, v in environment.items():

src/libtmux/window.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ def select_pane(self, target_pane: t.Union[str, int]) -> t.Optional["Pane"]:
199199

200200
def split(
201201
self,
202+
/,
202203
target: t.Optional[t.Union[int, str]] = None,
203204
start_directory: t.Optional[str] = None,
204205
attach: bool = False,
@@ -238,6 +239,7 @@ def split(
238239
"""
239240
active_pane = self.active_pane or self.panes[0]
240241
return active_pane.split(
242+
target=target,
241243
start_directory=start_directory,
242244
attach=attach,
243245
direction=direction,
@@ -250,6 +252,7 @@ def split(
250252

251253
def resize(
252254
self,
255+
/,
253256
# Adjustments
254257
adjustment_direction: t.Optional[ResizeAdjustmentDirection] = None,
255258
adjustment: t.Optional[int] = None,
@@ -621,6 +624,7 @@ def move_window(
621624
def new_window(
622625
self,
623626
window_name: t.Optional[str] = None,
627+
*,
624628
start_directory: None = None,
625629
attach: bool = False,
626630
window_index: str = "",

0 commit comments

Comments
 (0)