Skip to content

Commit 2c6f4c3

Browse files
authored
feat(panes): Allow skipping command send with enter: false (#747)
Fixes #53 #293 #735
2 parents 7517181 + 38526e5 commit 2c6f4c3

File tree

2 files changed

+102
-1
lines changed

2 files changed

+102
-1
lines changed

tests/test_workspacebuilder.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
"""Test for tmuxp workspacebuilder."""
22
import os
33
import pathlib
4+
import textwrap
5+
import time
46

57
import pytest
68

79
import kaptan
810

11+
import libtmux
912
from libtmux import Window
1013
from libtmux.common import has_gte_version
1114
from libtmux.test import retry, temp_session
@@ -869,3 +872,99 @@ def test_find_current_active_pane(server, monkeypatch):
869872
builder = WorkspaceBuilder(sconf=sconfig, server=server)
870873

871874
assert builder.find_current_attached_session() == second_session
875+
876+
877+
@pytest.mark.parametrize(
878+
"yaml,output,should_see",
879+
[
880+
[
881+
textwrap.dedent(
882+
"""
883+
session_name: Should not execute
884+
windows:
885+
- panes:
886+
- shell_command: echo "___$((1 + 3))___"
887+
enter: false
888+
"""
889+
),
890+
"___4___",
891+
False,
892+
],
893+
[
894+
textwrap.dedent(
895+
"""
896+
session_name: Should not execute
897+
windows:
898+
- panes:
899+
- shell_command:
900+
- echo "___$((1 + 3))___"
901+
enter: false
902+
"""
903+
),
904+
"___4___",
905+
False,
906+
],
907+
[
908+
textwrap.dedent(
909+
"""
910+
session_name: Should execute
911+
windows:
912+
- panes:
913+
- shell_command: echo "___$((1 + 3))___"
914+
"""
915+
),
916+
"___4___",
917+
True,
918+
],
919+
[
920+
textwrap.dedent(
921+
"""
922+
session_name: Should execute
923+
windows:
924+
- panes:
925+
- shell_command:
926+
- echo "___$((1 + 3))___"
927+
"""
928+
),
929+
"___4___",
930+
True,
931+
],
932+
],
933+
ids=[
934+
"pane_enter_false_shortform",
935+
"pane_enter_false_longform",
936+
"pane_enter_default_shortform",
937+
"pane_enter_default_longform",
938+
],
939+
)
940+
def test_load_workspace_enter(
941+
tmp_path: pathlib.Path,
942+
server: libtmux.Server,
943+
monkeypatch: pytest.MonkeyPatch,
944+
yaml,
945+
output,
946+
should_see,
947+
):
948+
yaml_config = tmp_path / "simple.yaml"
949+
yaml_config.write_text(
950+
yaml,
951+
encoding="utf-8",
952+
)
953+
sconfig = kaptan.Kaptan(handler="yaml")
954+
sconfig = sconfig.import_config(str(yaml_config)).get()
955+
sconfig = config.expand(sconfig)
956+
sconfig = config.trickle(sconfig)
957+
builder = WorkspaceBuilder(sconf=sconfig, server=server)
958+
builder.build()
959+
960+
time.sleep(1)
961+
962+
session = builder.session
963+
pane = session.attached_pane
964+
965+
captured_pane = "\n".join(pane.capture_pane())
966+
967+
if should_see:
968+
assert output in captured_pane
969+
else:
970+
assert output not in captured_pane

tmuxp/workspacebuilder.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,10 @@ def get_pane_shell():
362362
else:
363363
suppress = True
364364

365+
enter = pconf.get("enter", True)
366+
365367
for cmd in pconf["shell_command"]:
366-
p.send_keys(cmd, suppress_history=suppress)
368+
p.send_keys(cmd, suppress_history=suppress, enter=enter)
367369

368370
if "focus" in pconf and pconf["focus"]:
369371
w.select_pane(p["pane_id"])

0 commit comments

Comments
 (0)