Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6ce7894

Browse filesBrowse files
authored
feat(new_session): add width/height to new_session (#469)
Server.new_session now accepts `x` and `y` value. `if has_gte_version("2.6") and "TMUX" not in os.environ:` is intended for use in tmuxp
2 parents 2d10fec + 57fa790 commit 6ce7894
Copy full SHA for 6ce7894

File tree

Expand file treeCollapse file tree

3 files changed

+42
-6
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+42
-6
lines changed

‎CHANGES

Copy file name to clipboardExpand all lines: CHANGES
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ $ pip install --user --upgrade --pre libtmux
1414

1515
<!-- Maintainers and contributors: Insert change notes for the next release above -->
1616

17+
### What's new
18+
19+
- Server.new_session: Accept `x` and `y`, thanks
20+
@rockandska (#469)
21+
1722
## libtmux 0.19.1 (2022-01-07)
1823

1924
### Fixes

‎src/libtmux/server.py

Copy file name to clipboardExpand all lines: src/libtmux/server.py
+19-5Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
session_check_name,
3030
)
3131

32+
if t.TYPE_CHECKING:
33+
from typing_extensions import Literal, TypeAlias
34+
35+
DashLiteral: TypeAlias = Literal["-"]
36+
3237
logger = logging.getLogger(__name__)
3338

3439

@@ -351,6 +356,8 @@ def new_session(
351356
start_directory: t.Optional[str] = None,
352357
window_name: t.Optional[str] = None,
353358
window_command: t.Optional[str] = None,
359+
x: t.Optional[t.Union[int, "DashLiteral"]] = None,
360+
y: t.Optional[t.Union[int, "DashLiteral"]] = None,
354361
*args: t.Any,
355362
**kwargs: t.Any,
356363
) -> Session:
@@ -388,11 +395,17 @@ def new_session(
388395
::
389396
390397
$ tmux new-session -n <window_name>
391-
window_command : str
398+
window_command : str, optional
392399
execute a command on starting the session. The window will close
393400
when the command exits. NOTE: When this command exits the window
394401
will close. This feature is useful for long-running processes
395402
where the closing of the window upon completion is desired.
403+
x : [int, str], optional
404+
Force the specified width instead of the tmux default for a
405+
dettached session
406+
y : [int, str], optional
407+
Force the specified height instead of the tmux default for a
408+
dettached session
396409
397410
Returns
398411
-------
@@ -455,10 +468,11 @@ def new_session(
455468
if window_name:
456469
tmux_args += ("-n", window_name)
457470

458-
# tmux 2.6 gives unattached sessions a tiny default area
459-
# no need send in -x/-y if they're in a client already, though
460-
if has_gte_version("2.6") and "TMUX" not in os.environ:
461-
tmux_args += ("-x", 800, "-y", 600)
471+
if x is not None:
472+
tmux_args += ("-x", x)
473+
474+
if y is not None:
475+
tmux_args += ("-y", y)
462476

463477
if window_command:
464478
tmux_args += (window_command,)

‎tests/test_server.py

Copy file name to clipboardExpand all lines: tests/test_server.py
+18-1Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pytest
55

6-
from libtmux.common import has_gte_version
6+
from libtmux.common import has_gte_version, has_version
77
from libtmux.server import Server
88
from libtmux.session import Session
99

@@ -127,6 +127,23 @@ def test_new_session_shell(server: Server) -> None:
127127
assert pane_start_command == cmd
128128

129129

130+
@pytest.mark.skipif(has_version("3.2"), reason="Wrong width returned with 3.2")
131+
def test_new_session_width_height(server: Server) -> None:
132+
"""Server.new_session creates and returns valid session running with
133+
specified width /height"""
134+
cmd = "/usr/bin/env PS1='$ ' sh"
135+
mysession = server.new_session(
136+
"test_new_session_width_height",
137+
window_command=cmd,
138+
x=32,
139+
y=32,
140+
)
141+
window = mysession.windows[0]
142+
pane = window.panes[0]
143+
assert pane.display_message("#{window_width}", get_text=True)[0] == "32"
144+
assert pane.display_message("#{window_height}", get_text=True)[0] == "32"
145+
146+
130147
def test_no_server_sessions() -> None:
131148
server = Server(socket_name="test_attached_session_no_server")
132149
assert server.sessions == []

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.