Skip to content

Split follow ups #534

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 6 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ $ pip install --user --upgrade --pre libtmux

#### Improved new sessions (#532)

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

- Learned `direction`, via {class}`~libtmux.constants.WindowDirection`).
- [PEP 3102] keyword-only arguments after window name (#534).

- Added {meth}`Window.new_window()` shorthand to create window based on that
window's position.

[PEP 3102]: https://www.python.org/dev/peps/pep-3102/

#### Improved window splitting (#532)

Expand Down
10 changes: 10 additions & 0 deletions src/libtmux/pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def cmd(self, cmd: str, *args: t.Any) -> tmux_cmd:

def resize(
self,
/,
# Adjustments
adjustment_direction: t.Optional[ResizeAdjustmentDirection] = None,
adjustment: t.Optional[int] = None,
Expand Down Expand Up @@ -489,6 +490,8 @@ def select_pane(self) -> "Pane":

def split(
self,
/,
target: t.Optional[t.Union[int, str]] = None,
start_directory: t.Optional[str] = None,
attach: bool = False,
direction: t.Optional[PaneDirection] = None,
Expand All @@ -502,6 +505,8 @@ def split(

Parameters
----------
target : optional
Optional, custom *target-pane*, used by :meth:`Window.split`.
attach : bool, optional
make new window the current window after creating it, default
True.
Expand Down Expand Up @@ -615,6 +620,9 @@ def split(
if not attach:
tmux_args += ("-d",)

if target is not None:
tmux_args += (f"-t{target}",)

if environment:
if has_gte_version("3.0"):
for k, v in environment.items():
Expand Down Expand Up @@ -805,6 +813,7 @@ def at_right(self) -> bool:
#
def split_window(
self,
target: t.Optional[t.Union[int, str]] = None,
attach: bool = False,
start_directory: t.Optional[str] = None,
vertical: bool = True,
Expand Down Expand Up @@ -842,6 +851,7 @@ def split_window(
if size is None and percent is not None:
size = f'{str(percent).rstrip("%")}%'
return self.split(
target=target,
attach=attach,
start_directory=start_directory,
direction=PaneDirection.Below if vertical else PaneDirection.Right,
Expand Down
5 changes: 5 additions & 0 deletions src/libtmux/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ def rename_session(self, new_name: str) -> "Session":
def new_window(
self,
window_name: t.Optional[str] = None,
*,
start_directory: None = None,
attach: bool = False,
window_index: str = "",
Expand Down Expand Up @@ -635,6 +636,10 @@ def new_window(
if window_name is not None and isinstance(window_name, str):
window_args += ("-n", window_name)

if window_index is not None:
# empty string for window_index will use the first one available
window_args += (f"-t{self.session_id}:{window_index}",)

if environment:
if has_gte_version("3.0"):
for k, v in environment.items():
Expand Down
4 changes: 4 additions & 0 deletions src/libtmux/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def select_pane(self, target_pane: t.Union[str, int]) -> t.Optional["Pane"]:

def split(
self,
/,
target: t.Optional[t.Union[int, str]] = None,
start_directory: t.Optional[str] = None,
attach: bool = False,
Expand Down Expand Up @@ -238,6 +239,7 @@ def split(
"""
active_pane = self.active_pane or self.panes[0]
return active_pane.split(
target=target,
start_directory=start_directory,
attach=attach,
direction=direction,
Expand All @@ -250,6 +252,7 @@ def split(

def resize(
self,
/,
# Adjustments
adjustment_direction: t.Optional[ResizeAdjustmentDirection] = None,
adjustment: t.Optional[int] = None,
Expand Down Expand Up @@ -621,6 +624,7 @@ def move_window(
def new_window(
self,
window_name: t.Optional[str] = None,
*,
start_directory: None = None,
attach: bool = False,
window_index: str = "",
Expand Down