Skip to content

Commit 129300d

Browse files
authored
fix(WorkspaceBuilder): Fix layout issue due to missing default-size for terminal (#793)
Fixes #737, #667, #704 Credit: @nvasilas
2 parents b70cd70 + 28c4366 commit 129300d

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

CHANGES

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ $ pipx install --suffix=@next 'tmuxp' --pip-args '\--pre' --force
1919

2020
- _Insert changes/features/fixes for next release here_
2121

22+
## tmuxp 1.13.1 (unreleased)
23+
24+
### Bug fixes
25+
26+
- Fix layout related issues from {issue}`667`, {issue}`704`, {issue}`737`, via
27+
{issue}`793`. Thank you @nvasilas.
28+
2229
## tmuxp 1.13.0 (2022-08-14)
2330

2431
### Internal

tests/test_workspacebuilder.py

+35-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import libtmux
1212
from libtmux import Window
13-
from libtmux.common import has_gte_version
13+
from libtmux.common import has_gte_version, has_lt_version
1414
from libtmux.test import retry_until, temp_session
1515
from tmuxp import config, exc
1616
from tmuxp.cli.load import load_plugins
@@ -1183,3 +1183,37 @@ def f():
11831183

11841184
# handle case with OS X adding /private/ to /tmp/ paths
11851185
assert retry_until(f)
1186+
1187+
1188+
@pytest.mark.skipif(
1189+
has_lt_version("2.9"), reason="needs option introduced in tmux >= 2.9"
1190+
)
1191+
def test_layout_main_horizontal(session):
1192+
yaml_config = test_utils.read_config_file("workspacebuilder/three_pane.yaml")
1193+
1194+
sconfig = kaptan.Kaptan(handler="yaml")
1195+
sconfig = sconfig.import_config(yaml_config).get()
1196+
1197+
builder = WorkspaceBuilder(sconf=sconfig)
1198+
builder.build(session=session)
1199+
1200+
assert session.windows
1201+
window = session.windows[0]
1202+
1203+
assert len(window.panes) == 3
1204+
main_horizontal_pane, *panes = window.panes
1205+
1206+
def height(p):
1207+
return int(p._info["pane_height"])
1208+
1209+
def width(p):
1210+
return int(p._info["pane_width"])
1211+
1212+
assert height(main_horizontal_pane) > height(panes[0])
1213+
assert width(main_horizontal_pane) > width(panes[0])
1214+
1215+
def is_almost_equal(x, y):
1216+
return abs(x - y) <= 1
1217+
1218+
assert is_almost_equal(height(panes[0]), height(panes[1]))
1219+
assert is_almost_equal(width(panes[0]), width(panes[1]))

tmuxp/workspacebuilder.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from libtmux.server import Server
1313
from libtmux.session import Session
1414
from libtmux.window import Window
15+
from libtmux.common import has_gte_version
1516

1617
from . import exc
1718
from .util import get_current_pane, run_before_script
@@ -217,6 +218,10 @@ def build(self, session=None, append=False):
217218
assert self.sconf["session_name"] == session.name
218219
assert len(self.sconf["session_name"]) > 0
219220

221+
if has_gte_version("2.9"):
222+
# Use tmux default session size, overwrite Server::new_session
223+
session.set_option("default-size", "80x24")
224+
220225
self.session = session
221226
self.server = session.server
222227

@@ -264,9 +269,6 @@ def build(self, session=None, append=False):
264269
assert isinstance(p, Pane)
265270
p = p
266271

267-
if "layout" in wconf:
268-
w.select_layout(wconf["layout"])
269-
270272
if "focus" in pconf and pconf["focus"]:
271273
focus_pane = p
272274

@@ -281,6 +283,8 @@ def build(self, session=None, append=False):
281283
if focus_pane:
282284
focus_pane.select_pane()
283285

286+
w.select_layout(wconf.get("layout", "even-vertical"))
287+
284288
if focus:
285289
focus.select_window()
286290

@@ -421,8 +425,6 @@ def get_pane_shell():
421425
)
422426

423427
assert isinstance(p, Pane)
424-
if "layout" in wconf:
425-
w.select_layout(wconf["layout"])
426428

427429
if "suppress_history" in pconf:
428430
suppress = pconf["suppress_history"]

0 commit comments

Comments
 (0)