Skip to content

Commit a80e7eb

Browse files
committed
feat(Window): Add Window.new_window()
1 parent 59ac585 commit a80e7eb

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

src/libtmux/window.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from libtmux.constants import (
1717
RESIZE_ADJUSTMENT_DIRECTION_FLAG_MAP,
1818
ResizeAdjustmentDirection,
19+
WindowDirection,
1920
)
2021
from libtmux.neo import Obj, fetch_obj, fetch_objs
2122
from libtmux.pane import Pane
@@ -627,6 +628,65 @@ def move_window(
627628

628629
return self
629630

631+
def new_window(
632+
self,
633+
window_name: t.Optional[str] = None,
634+
start_directory: None = None,
635+
attach: bool = False,
636+
window_index: str = "",
637+
window_shell: t.Optional[str] = None,
638+
environment: t.Optional[t.Dict[str, str]] = None,
639+
direction: t.Optional[WindowDirection] = None,
640+
) -> "Window":
641+
"""Create new window respective of current window's position.
642+
643+
See Also
644+
--------
645+
:meth:`Session.new_window()`
646+
647+
Examples
648+
--------
649+
.. ::
650+
>>> import pytest
651+
>>> from libtmux.common import has_lt_version
652+
>>> if has_lt_version('3.2'):
653+
... pytest.skip('This doctest requires tmux 3.2 or newer')
654+
>>> window_initial = session.new_window(window_name='Example')
655+
>>> window_initial
656+
Window(@... 2:Example, Session($1 libtmux_...))
657+
>>> window_initial.window_index
658+
'2'
659+
660+
>>> window_before = window_initial.new_window(
661+
... window_name='Window before', direction=WindowDirection.Before)
662+
>>> window_initial.refresh()
663+
>>> window_before
664+
Window(@... 2:Window before, Session($1 libtmux_...))
665+
>>> window_initial
666+
Window(@... 3:Example, Session($1 libtmux_...))
667+
668+
>>> window_after = window_initial.new_window(
669+
... window_name='Window after', direction=WindowDirection.After)
670+
>>> window_initial.refresh()
671+
>>> window_after.refresh()
672+
>>> window_after
673+
Window(@... 4:Window after, Session($1 libtmux_...))
674+
>>> window_initial
675+
Window(@... 3:Example, Session($1 libtmux_...))
676+
>>> window_before
677+
Window(@... 2:Window before, Session($1 libtmux_...))
678+
"""
679+
return self.session.new_window(
680+
window_name=window_name,
681+
start_directory=start_directory,
682+
attach=attach,
683+
window_index=window_index,
684+
window_shell=window_shell,
685+
environment=environment,
686+
direction=direction,
687+
target_window=self.window_id,
688+
)
689+
630690
#
631691
# Climbers
632692
#

0 commit comments

Comments
 (0)