Skip to content

Commit

Permalink
Fix layout related issues #737, #667, #704
Browse files Browse the repository at this point in the history
Use tmux default session size 80x24 when creating a new session
  • Loading branch information
nvasilas authored and tony committed Aug 14, 2022
1 parent 3908ce7 commit cf5daa6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
31 changes: 31 additions & 0 deletions tests/test_workspacebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
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.6"):
# 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"])

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

0 comments on commit cf5daa6

Please sign in to comment.