Skip to content

Improved splitting #532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2e1ac45
feat(Pane): Add Pane.split, deprecate Pane.split_window
tony Mar 3, 2024
cad0801
tests(Pane): Pane.split()
tony Mar 3, 2024
cd7519d
refactor!(Window): Add .split(), deprecate split_window()
tony Mar 3, 2024
c8c30bc
chore(Window): Window.split_window() -> Window.split()
tony Mar 3, 2024
8290cf3
tests: Move split_window(percent=*) to legacy tests
tony Mar 3, 2024
ee7aac4
feat(Window): Window.split() to use Pane.split_window()
tony Mar 3, 2024
1829385
constants(WindowDirection): Add enum and map for new-window directions
tony Mar 4, 2024
b46e7fa
chore(Session.new_window): Avoid redundant use of -t
tony Mar 10, 2024
59ac585
feat(Session.new_window): Add direction, target_window
tony Mar 9, 2024
a80e7eb
feat(Window): Add `Window.new_window()`
tony Mar 9, 2024
e7886a2
tests(Session): new_window warning for tmux 3.0 and below
tony Mar 10, 2024
5a9487f
tests(Window): new_window warning for tmux 3.0 and below
tony Mar 10, 2024
fd0d066
test(Window.new_window): Test with `direction`
tony Mar 10, 2024
3c086cf
test(Session.new_window): Test with `direction`
tony Mar 10, 2024
76cec6f
constants(PaneDirection): Add enum and map for split-window `direction`
tony Mar 10, 2024
a93871f
feat(Pane.split_window): Add `direction`, deprecate `vertical`.
tony Mar 10, 2024
2297232
feat(Pane.split_window): Add `full_window_split`
tony Mar 10, 2024
ffd9b74
Pane(split): Clean up signature, use `direction`
tony Mar 10, 2024
dbeb554
Window(split): Clean up signature, use `direction`
tony Mar 10, 2024
95bc838
tests(Pane,Window): Use `direction` in .split()
tony Mar 10, 2024
51bbd3e
tests(doctests): split_window() -> split()
tony Mar 16, 2024
5918d93
Obj: Add pane_at_{left,top,bottom,right}
tony Mar 16, 2024
24fcb33
Obj: Remove newline
tony Mar 16, 2024
f94523b
feat(Pane): Add at_{top,bottom,left,right}
tony Mar 16, 2024
cb80530
tests(doctests): For Pane.split
tony Mar 16, 2024
eeb396f
tests(test_pane): Check at_{left,right,bottom,top}
tony Mar 16, 2024
111716e
feat({Window,Pane}.split): Add zoom
tony Mar 16, 2024
4725452
tests({Pane,Window}.split_window): Add tests for zoom
tony Mar 16, 2024
0503da8
docs(CHANGES,MIGRATION): Note split window updates
tony Mar 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,39 @@ $ pip install --user --upgrade --pre libtmux

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

### Breaking changes

#### Improved new sessions (#532)

- `Session.new_window()` to {meth}`Session.new_window()`

- Learned `direction`, via {class}`~libtmux.constants.WindowDirection`).

#### Improved window splitting (#532)

- `Window.split_window()` to {meth}`Window.split()`

- Deprecate `Window.split_window()`

- `Pane.split_window()` to {meth}`Pane.split()`

- Deprecate `Pane.split_window()`
- Learned `direction`, via {class}`~libtmux.constants.PaneDirection`).

- Deprecate `vertical` and `horizontal` in favor of `direction`.

- Learned `zoom`

#### Tweak: Pane position (#532)

It's now possible to retrieve the position of a pane in a window via a
`bool` helper::

- {attr}`Pane.at_left`
- {attr}`Pane.at_right`
- {attr}`Pane.at_bottom`
- {attr}`Pane.at_right`

### Development

- poetry: 1.7.1 -> 1.8.1
Expand Down
7 changes: 7 additions & 0 deletions MIGRATION
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ _Detailed migration steps for the next version will be posted here._

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

## 0.33.0: Deprecations for splitting (2024-03-03)

### Deprecations (#532)

- `Window.split_window()` to {meth}`Window.split()`
- `Pane.split_window()` to {meth}`Pane.split()`

## 0.31.0: Renaming and command cleanup (2024-02-17)

### Cleanups (#527)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Grab remaining tmux window:

```python
>>> window = session.active_window
>>> window.split_window(attach=False)
>>> window.split(attach=False)
Pane(%2 Window(@1 1:... Session($1 ...)))
```

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

```python
>>> pane = window.split_window()
>>> pane = window.split_window(attach=False)
>>> pane = window.split()
>>> pane = window.split(attach=False)
>>> pane.select()
Pane(%3 Window(@1 1:..., Session($1 ...)))
>>> window = session.new_window(attach=False, window_name="test")
>>> window
Window(@2 2:test, Session($1 ...))
>>> pane = window.split_window(attach=False)
>>> pane = window.split(attach=False)
>>> pane
Pane(%5 Window(@2 2:test, Session($1 ...)))
```
Expand Down
12 changes: 6 additions & 6 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ Create a pane from a window:
'%2'
```

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

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

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

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

```python
>>> window.split_window(attach=False)
>>> window.split(attach=False)
Pane(%2 Window(@1 ...:..., Session($1 ...)))
```

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

```python
>>> pane = window.split_window()
>>> pane = window.split()
```

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

```python
>>> pane = window.split_window(attach=False)
>>> pane = window.split(attach=False)
```

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

```python
>>> window = session.new_window(attach=False, window_name="test")
>>> pane = window.split_window(attach=False)
>>> pane = window.split(attach=False)
>>> pane.send_keys('echo hey', enter=False)
```

Expand Down
31 changes: 31 additions & 0 deletions src/libtmux/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,34 @@ class ResizeAdjustmentDirection(enum.Enum):
ResizeAdjustmentDirection.Left: "-L",
ResizeAdjustmentDirection.Right: "-R",
}


class WindowDirection(enum.Enum):
"""Used for *adjustment* in :meth:`Session.new_window()`."""

Before = "BEFORE"
After = "AFTER"


WINDOW_DIRECTION_FLAG_MAP: t.Dict[WindowDirection, str] = {
WindowDirection.Before: "-b",
WindowDirection.After: "-a",
}


class PaneDirection(enum.Enum):
"""Used for *adjustment* in :meth:`Pane.split()`."""

Above = "ABOVE"
Below = "BELOW" # default with no args
Right = "RIGHT"
Left = "LEFT"


PANE_DIRECTION_FLAG_MAP: t.Dict[PaneDirection, t.List[str]] = {
# -v is assumed, but for explicitness it is passed
PaneDirection.Above: ["-v", "-b"],
PaneDirection.Below: ["-v"],
PaneDirection.Right: ["-h"],
PaneDirection.Left: ["-h", "-b"],
}
5 changes: 4 additions & 1 deletion src/libtmux/neo.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ class Obj:
next_session_id: t.Union[str, None] = None
origin_flag: t.Union[str, None] = None
pane_active: t.Union[str, None] = None # Not detected by script
pane_at_bottom: t.Union[str, None] = None
pane_at_left: t.Union[str, None] = None
pane_at_right: t.Union[str, None] = None
pane_at_top: t.Union[str, None] = None
pane_bg: t.Union[str, None] = None
pane_bottom: t.Union[str, None] = None
pane_current_command: t.Union[str, None] = None
Expand All @@ -110,7 +114,6 @@ class Obj:
pane_top: t.Union[str, None] = None
pane_tty: t.Union[str, None] = None
pane_width: t.Union[str, None] = None

pid: t.Union[str, None] = None
scroll_position: t.Union[str, None] = None
scroll_region_lower: t.Union[str, None] = None
Expand Down
Loading