Skip to content

Fix layout related issues #737, #667, #704 #793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 35 additions & 1 deletion tests/test_workspacebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1183,3 +1183,37 @@ def f():

# handle case with OS X adding /private/ to /tmp/ paths
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")

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])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I learned something new:

main-horizontal doesn't necessarily guarantee the top pane will be bigger.

A large (main) pane is shown at the top of the window and the remaining panes are spread from left to right in the leftover space at the bottom. Use the main-pane-height window option to specify the height of the top pane. manpage

I will try to remedy this in #809

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]))
12 changes: 7 additions & 5 deletions tmuxp/workspacebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.9"):
# Use tmux default session size, overwrite Server::new_session
session.set_option("default-size", "80x24")

self.session = session
self.server = session.server

Expand Down Expand Up @@ -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"])

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nvasilas Do you recall the rationale behind the removing / adding of the .select_layout's here, here, and here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tony If I recall correctly without this change the layout wasn't updated properly. It seems like I broke some things with this PR. I will investigate and I'll try to provide a fix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nvasilas Thank you! Let's see how it goes!

if "focus" in pconf and pconf["focus"]:
focus_pane = p

Expand All @@ -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()

Expand Down Expand Up @@ -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"]
Expand Down