From fb9a8affd5060dc9173104238a460bbc32ccf059 Mon Sep 17 00:00:00 2001 From: Nikos Vasilas Date: Sun, 7 Aug 2022 18:30:30 +0300 Subject: [PATCH 1/4] Fix layout related issues #737, #667, #704 Use tmux default session size 80x24 when creating a new session --- tests/test_workspacebuilder.py | 31 +++++++++++++++++++++++++++++++ tmuxp/workspacebuilder.py | 12 +++++++----- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/tests/test_workspacebuilder.py b/tests/test_workspacebuilder.py index e30a9168bc0..ae8f6a95ba5 100644 --- a/tests/test_workspacebuilder.py +++ b/tests/test_workspacebuilder.py @@ -1183,3 +1183,34 @@ def f(): # handle case with OS X adding /private/ to /tmp/ paths assert retry_until(f) + + +def test_layout_main_horizontal(session): + yaml_config = test_utils.read_config_file("workspacebuilder/three_pane.yaml") + + sconfig = kaptan.Kaptan(handler="yaml") + sconfig = sconfig.import_config(yaml_config).get() + + builder = WorkspaceBuilder(sconf=sconfig) + builder.build(session=session) + + assert session.windows + window = session.windows[0] + + assert len(window.panes) == 3 + main_horizontal_pane, *panes = window.panes + + def height(p): + return int(p._info["pane_height"]) + + def width(p): + return int(p._info["pane_width"]) + + assert height(main_horizontal_pane) > height(panes[0]) + assert width(main_horizontal_pane) > width(panes[0]) + + def is_almost_equal(x, y): + return abs(x - y) <= 1 + + assert is_almost_equal(height(panes[0]), height(panes[1])) + assert is_almost_equal(width(panes[0]), width(panes[1])) diff --git a/tmuxp/workspacebuilder.py b/tmuxp/workspacebuilder.py index 5ea9fc92abf..30eda513a06 100644 --- a/tmuxp/workspacebuilder.py +++ b/tmuxp/workspacebuilder.py @@ -12,6 +12,7 @@ from libtmux.server import Server from libtmux.session import Session from libtmux.window import Window +from libtmux.common import has_gte_version from . import exc from .util import get_current_pane, run_before_script @@ -217,6 +218,10 @@ def build(self, session=None, append=False): assert self.sconf["session_name"] == session.name assert len(self.sconf["session_name"]) > 0 + if has_gte_version("2.6"): + # Use tmux default session size, overwrite Server::new_session + session.set_option("default-size", "80x24") + self.session = session self.server = session.server @@ -264,9 +269,6 @@ def build(self, session=None, append=False): assert isinstance(p, Pane) p = p - if "layout" in wconf: - w.select_layout(wconf["layout"]) - if "focus" in pconf and pconf["focus"]: focus_pane = p @@ -281,6 +283,8 @@ def build(self, session=None, append=False): if focus_pane: focus_pane.select_pane() + w.select_layout(wconf.get("layout", "even-vertical")) + if focus: focus.select_window() @@ -421,8 +425,6 @@ def get_pane_shell(): ) assert isinstance(p, Pane) - if "layout" in wconf: - w.select_layout(wconf["layout"]) if "suppress_history" in pconf: suppress = pconf["suppress_history"] From 2099745f6eb684725d7193f868b70f0566e5774f Mon Sep 17 00:00:00 2001 From: Nikos Vasilas Date: Thu, 18 Aug 2022 19:21:39 +0300 Subject: [PATCH 2/4] Check minimum tmux version --- tmuxp/workspacebuilder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmuxp/workspacebuilder.py b/tmuxp/workspacebuilder.py index 30eda513a06..b21f0dc8a2c 100644 --- a/tmuxp/workspacebuilder.py +++ b/tmuxp/workspacebuilder.py @@ -218,7 +218,7 @@ def build(self, session=None, append=False): assert self.sconf["session_name"] == session.name assert len(self.sconf["session_name"]) > 0 - if has_gte_version("2.6"): + if has_gte_version("2.9"): # Use tmux default session size, overwrite Server::new_session session.set_option("default-size", "80x24") From 927cf1fb323e66c42bf8c5784955e4caab2b0e46 Mon Sep 17 00:00:00 2001 From: Nikos Vasilas Date: Thu, 18 Aug 2022 19:51:09 +0300 Subject: [PATCH 3/4] Skip test that requires higher tmux version --- tests/test_workspacebuilder.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_workspacebuilder.py b/tests/test_workspacebuilder.py index ae8f6a95ba5..048dd7e5c7b 100644 --- a/tests/test_workspacebuilder.py +++ b/tests/test_workspacebuilder.py @@ -10,7 +10,7 @@ import libtmux from libtmux import Window -from libtmux.common import has_gte_version +from libtmux.common import has_gte_version, has_lt_version from libtmux.test import retry_until, temp_session from tmuxp import config, exc from tmuxp.cli.load import load_plugins @@ -1185,6 +1185,9 @@ def f(): assert retry_until(f) +@pytest.mark.skipif( + has_lt_version("2.9"), reason="needs option introduced in tmux >= 2.9" +) def test_layout_main_horizontal(session): yaml_config = test_utils.read_config_file("workspacebuilder/three_pane.yaml") From 28c4366aa701041fc8f509e42486da9dbdb07f6f Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 21 Aug 2022 15:46:00 -0500 Subject: [PATCH 4/4] docs(CHANGES): Note bug fix by @nvasilas --- CHANGES | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGES b/CHANGES index 21bc8198b91..94087c3c202 100644 --- a/CHANGES +++ b/CHANGES @@ -19,6 +19,13 @@ $ pipx install --suffix=@next 'tmuxp' --pip-args '\--pre' --force - _Insert changes/features/fixes for next release here_ +## tmuxp 1.13.1 (unreleased) + +### Bug fixes + +- Fix layout related issues from {issue}`667`, {issue}`704`, {issue}`737`, via + {issue}`793`. Thank you @nvasilas. + ## tmuxp 1.13.0 (2022-08-14) ### Internal