Skip to content

Commit 77047c6

Browse files
authored
Improved splitting (#532)
## New param: `Session.new_window()` - `direction`: `WindowDirection` (`Before`, `After`) ## New method: `Pane.split()` - New param: `direction`, via `PaneDirection` (`Above`, `Below`, `Left`, `Right`) Replaces `vertical`'s old behavior. - New param: `full_window_split` ## Deprecate `Pane.split_window()` ## New method: `Window.split()` - New param: `direction`, via `PaneDirection` (`Above`, `Below`, `Left`, `Right`) Replaces `vertical`'s old behavior. - New param: `full_window_split`, `zoom` ## Deprecate `Window.split_window()`
2 parents 6ea527b + 0503da8 commit 77047c6

16 files changed

+840
-221
lines changed

CHANGES

+33
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,39 @@ $ pip install --user --upgrade --pre libtmux
1515

1616
<!-- To maintainers and contributors: Please add notes for the forthcoming version above -->
1717

18+
### Breaking changes
19+
20+
#### Improved new sessions (#532)
21+
22+
- `Session.new_window()` to {meth}`Session.new_window()`
23+
24+
- Learned `direction`, via {class}`~libtmux.constants.WindowDirection`).
25+
26+
#### Improved window splitting (#532)
27+
28+
- `Window.split_window()` to {meth}`Window.split()`
29+
30+
- Deprecate `Window.split_window()`
31+
32+
- `Pane.split_window()` to {meth}`Pane.split()`
33+
34+
- Deprecate `Pane.split_window()`
35+
- Learned `direction`, via {class}`~libtmux.constants.PaneDirection`).
36+
37+
- Deprecate `vertical` and `horizontal` in favor of `direction`.
38+
39+
- Learned `zoom`
40+
41+
#### Tweak: Pane position (#532)
42+
43+
It's now possible to retrieve the position of a pane in a window via a
44+
`bool` helper::
45+
46+
- {attr}`Pane.at_left`
47+
- {attr}`Pane.at_right`
48+
- {attr}`Pane.at_bottom`
49+
- {attr}`Pane.at_right`
50+
1851
### Development
1952

2053
- poetry: 1.7.1 -> 1.8.1

MIGRATION

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ _Detailed migration steps for the next version will be posted here._
2525

2626
<!-- To the maintainers and contributors: please add migration details for the upcoming release here -->
2727

28+
## 0.33.0: Deprecations for splitting (2024-03-03)
29+
30+
### Deprecations (#532)
31+
32+
- `Window.split_window()` to {meth}`Window.split()`
33+
- `Pane.split_window()` to {meth}`Pane.split()`
34+
2835
## 0.31.0: Renaming and command cleanup (2024-02-17)
2936

3037
### Cleanups (#527)

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ Grab remaining tmux window:
182182

183183
```python
184184
>>> window = session.active_window
185-
>>> window.split_window(attach=False)
185+
>>> window.split(attach=False)
186186
Pane(%2 Window(@1 1:... Session($1 ...)))
187187
```
188188

@@ -196,14 +196,14 @@ Window(@1 1:libtmuxower, Session($1 ...))
196196
Split window (create a new pane):
197197

198198
```python
199-
>>> pane = window.split_window()
200-
>>> pane = window.split_window(attach=False)
199+
>>> pane = window.split()
200+
>>> pane = window.split(attach=False)
201201
>>> pane.select()
202202
Pane(%3 Window(@1 1:..., Session($1 ...)))
203203
>>> window = session.new_window(attach=False, window_name="test")
204204
>>> window
205205
Window(@2 2:test, Session($1 ...))
206-
>>> pane = window.split_window(attach=False)
206+
>>> pane = window.split(attach=False)
207207
>>> pane
208208
Pane(%5 Window(@2 2:test, Session($1 ...)))
209209
```

docs/quickstart.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Create a pane from a window:
149149
'%2'
150150
```
151151

152-
Raw output directly to a {class}`Pane` (in practice, you'd use {meth}`Window.split_window()`):
152+
Raw output directly to a {class}`Pane` (in practice, you'd use {meth}`Window.split()`):
153153

154154
```python
155155
>>> Pane.from_pane_id(pane_id=window.cmd('split-window', '-P', '-F#{pane_id}').stdout[0], server=window.server)
@@ -312,10 +312,10 @@ to grab our current window.
312312

313313
`window` now has access to all of the objects inside of {class}`Window`.
314314

315-
Let's create a pane, {meth}`Window.split_window`:
315+
Let's create a pane, {meth}`Window.split`:
316316

317317
```python
318-
>>> window.split_window(attach=False)
318+
>>> window.split(attach=False)
319319
Pane(%2 Window(@1 ...:..., Session($1 ...)))
320320
```
321321

@@ -341,15 +341,15 @@ You have two ways you can move your cursor to new sessions, windows and panes.
341341
For one, arguments such as `attach=False` can be omittted.
342342

343343
```python
344-
>>> pane = window.split_window()
344+
>>> pane = window.split()
345345
```
346346

347347
This gives you the {class}`Pane` along with moving the cursor to a new window. You
348348
can also use the `.select_*` available on the object, in this case the pane has
349349
{meth}`Pane.select()`.
350350

351351
```python
352-
>>> pane = window.split_window(attach=False)
352+
>>> pane = window.split(attach=False)
353353
```
354354

355355
```python
@@ -371,7 +371,7 @@ As long as you have the object, or are iterating through a list of them, you can
371371

372372
```python
373373
>>> window = session.new_window(attach=False, window_name="test")
374-
>>> pane = window.split_window(attach=False)
374+
>>> pane = window.split(attach=False)
375375
>>> pane.send_keys('echo hey', enter=False)
376376
```
377377

src/libtmux/constants.py

+31
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,34 @@ class ResizeAdjustmentDirection(enum.Enum):
1919
ResizeAdjustmentDirection.Left: "-L",
2020
ResizeAdjustmentDirection.Right: "-R",
2121
}
22+
23+
24+
class WindowDirection(enum.Enum):
25+
"""Used for *adjustment* in :meth:`Session.new_window()`."""
26+
27+
Before = "BEFORE"
28+
After = "AFTER"
29+
30+
31+
WINDOW_DIRECTION_FLAG_MAP: t.Dict[WindowDirection, str] = {
32+
WindowDirection.Before: "-b",
33+
WindowDirection.After: "-a",
34+
}
35+
36+
37+
class PaneDirection(enum.Enum):
38+
"""Used for *adjustment* in :meth:`Pane.split()`."""
39+
40+
Above = "ABOVE"
41+
Below = "BELOW" # default with no args
42+
Right = "RIGHT"
43+
Left = "LEFT"
44+
45+
46+
PANE_DIRECTION_FLAG_MAP: t.Dict[PaneDirection, t.List[str]] = {
47+
# -v is assumed, but for explicitness it is passed
48+
PaneDirection.Above: ["-v", "-b"],
49+
PaneDirection.Below: ["-v"],
50+
PaneDirection.Right: ["-h"],
51+
PaneDirection.Left: ["-h", "-b"],
52+
}

src/libtmux/neo.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ class Obj:
8989
next_session_id: t.Union[str, None] = None
9090
origin_flag: t.Union[str, None] = None
9191
pane_active: t.Union[str, None] = None # Not detected by script
92+
pane_at_bottom: t.Union[str, None] = None
93+
pane_at_left: t.Union[str, None] = None
94+
pane_at_right: t.Union[str, None] = None
95+
pane_at_top: t.Union[str, None] = None
9296
pane_bg: t.Union[str, None] = None
9397
pane_bottom: t.Union[str, None] = None
9498
pane_current_command: t.Union[str, None] = None
@@ -110,7 +114,6 @@ class Obj:
110114
pane_top: t.Union[str, None] = None
111115
pane_tty: t.Union[str, None] = None
112116
pane_width: t.Union[str, None] = None
113-
114117
pid: t.Union[str, None] = None
115118
scroll_position: t.Union[str, None] = None
116119
scroll_region_lower: t.Union[str, None] = None

0 commit comments

Comments
 (0)