Skip to content

Commit cd9aa53

Browse files
committed
Fix layout related issues #737, #667, #704
Use tmux default session size 80x24 when creating a new session
1 parent 64926c6 commit cd9aa53

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

tests/test_workspacebuilder.py

+31
Original file line numberDiff line numberDiff line change
@@ -1183,3 +1183,34 @@ def f():
11831183

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