Skip to content
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

libtmux: Improved options and hooks #925

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ tmuxp = 'tmuxp:cli.cli'

[tool.poetry.dependencies]
python = "^3.8"
libtmux = "~0.37.0"
libtmux = {git = "https://github.com/tmux-python/libtmux.git", rev = "improved-options"}
colorama = ">=0.3.9"
PyYAML = "^6.0"

Expand Down
8 changes: 4 additions & 4 deletions src/tmuxp/workspace/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def iter_create_windows(
Generator yielding :class:`libtmux.Window` by iterating through
``session_config['windows']``.

Applies ``window_options`` to window.
Applies ``options`` to window.

Parameters
----------
Expand Down Expand Up @@ -433,7 +433,7 @@ def iter_create_windows(
dict,
):
for key, val in window_config["options"].items():
window.set_window_option(key, val)
window.set_option(key, val)

if window_config.get("focus"):
window.select()
Expand Down Expand Up @@ -464,7 +464,7 @@ def iter_create_panes(
"""
assert isinstance(window, Window)

pane_base_index_str = window.show_window_option("pane-base-index", g=True)
pane_base_index_str = window._show_option("pane-base-index", _global=True)
assert pane_base_index_str is not None
pane_base_index = int(pane_base_index_str)

Expand Down Expand Up @@ -585,7 +585,7 @@ def config_after_window(
dict,
):
for key, val in window_config["options_after"].items():
window.set_window_option(key, val)
window.set_option(key, val)

def find_current_attached_session(self) -> Session:
"""Return current attached session."""
Expand Down
2 changes: 1 addition & 1 deletion src/tmuxp/workspace/freezer.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def freeze(session: Session) -> t.Dict[str, t.Any]:

for window in session.windows:
window_config: t.Dict[str, t.Any] = {
"options": window.show_window_options(),
"options": window._show_options(),
"window_name": window.name,
"layout": window.window_layout,
"panes": [],
Expand Down
43 changes: 21 additions & 22 deletions tests/workspace/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ def test_split_windows(session: Session) -> None:
window_count = len(session.windows) # current window count
assert len(session.windows) == window_count
for w, wconf in builder.iter_create_windows(session):
for p in builder.iter_create_panes(w, wconf):
for _ in builder.iter_create_panes(w, wconf):
w.select_layout("tiled") # fix glitch with pane size
p = p
assert len(session.windows) == window_count
assert isinstance(w, Window)

Expand All @@ -68,15 +67,14 @@ def test_split_windows_three_pane(session: Session) -> None:
window_count = len(session.windows) # current window count
assert len(session.windows) == window_count
for w, wconf in builder.iter_create_windows(session):
for p in builder.iter_create_panes(w, wconf):
for _ in builder.iter_create_panes(w, wconf):
w.select_layout("tiled") # fix glitch with pane size
p = p
assert len(session.windows) == window_count
assert isinstance(w, Window)

assert len(session.windows) == window_count
window_count += 1
w.set_window_option("main-pane-height", 50)
w.set_option("main-pane-height", 50)
w.select_layout(wconf["layout"])


Expand All @@ -94,9 +92,9 @@ def test_focus_pane_index(session: Session) -> None:

assert session.active_window.name == "focused window"

_pane_base_index = session.active_window.show_window_option(
_pane_base_index = session.active_window._show_option(
"pane-base-index",
g=True,
_global=True,
)
assert isinstance(_pane_base_index, int)
pane_base_index = int(_pane_base_index)
Expand Down Expand Up @@ -230,11 +228,11 @@ def test_session_options(session: Session) -> None:
builder = WorkspaceBuilder(session_config=workspace, server=session.server)
builder.build(session=session)

_default_shell = session.show_option("default-shell")
_default_shell = session._show_option("default-shell")
assert isinstance(_default_shell, str)
assert "/bin/sh" in _default_shell

_default_command = session.show_option("default-command")
_default_command = session._show_option("default-command")
assert isinstance(_default_command, str)
assert "/bin/sh" in _default_command

Expand All @@ -249,10 +247,10 @@ def test_global_options(session: Session) -> None:
builder = WorkspaceBuilder(session_config=workspace, server=session.server)
builder.build(session=session)

_status_position = session.show_option("status-position", _global=True)
_status_position = session._show_option("status-position", _global=True)
assert isinstance(_status_position, str)
assert "top" in _status_position
assert session.show_option("repeat-time", _global=True) == 493
assert session._show_option("repeat-time", _global=True) == 493


def test_global_session_env_options(
Expand All @@ -275,11 +273,11 @@ def test_global_session_env_options(
builder = WorkspaceBuilder(session_config=workspace, server=session.server)
builder.build(session=session)

_visual_silence = session.show_option("visual-silence", _global=True)
assert isinstance(_visual_silence, str)
assert visual_silence in _visual_silence
assert repeat_time == session.show_option("repeat-time")
assert main_pane_height == session.active_window.show_window_option(
_visual_silence = session._show_option("visual-silence", _global=True)
assert isinstance(_visual_silence, bool)
assert _visual_silence is True
assert repeat_time == session._show_option("repeat-time")
assert main_pane_height == session.active_window._show_option(
"main-pane-height",
)

Expand All @@ -301,14 +299,13 @@ def test_window_options(
window_count = len(session.windows) # current window count
assert len(session.windows) == window_count
for w, wconf in builder.iter_create_windows(session):
for p in builder.iter_create_panes(w, wconf):
for _ in builder.iter_create_panes(w, wconf):
w.select_layout("tiled") # fix glitch with pane size
p = p
assert len(session.windows) == window_count
assert isinstance(w, Window)
assert w.show_window_option("main-pane-height") == 5
assert w._show_option("main-pane-height") == 5
if has_gte_version("2.3"):
assert w.show_window_option("pane-border-format") == " #P "
assert w._show_option("pane-border-format") == " #P "

assert len(session.windows) == window_count
window_count += 1
Expand Down Expand Up @@ -513,7 +510,7 @@ def check_window_name_mismatch() -> bool:
assert retry_until(check_window_name_mismatch, 5, interval=0.25)

def check_window_name_match() -> bool:
assert w.show_window_option("automatic-rename") == "on"
assert w._show_option("automatic-rename")
return w.name in {
pathlib.Path(os.getenv("SHELL", "bash")).name,
portable_command,
Expand Down Expand Up @@ -714,8 +711,10 @@ def test_pane_order(session: Session) -> None:
window_count += 1

for w in session.windows:
pane_base_index = w.show_window_option("pane-base-index", g=True)
pane_base_index = w._show_option("pane-base-index", _global=True)
assert isinstance(pane_base_index, int)
for p_index, p in enumerate(w.panes, start=pane_base_index):
assert p.index is not None
assert int(p_index) == int(p.index)

# pane-base-index start at base-index, pane_paths always start
Expand Down