Skip to content
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
2 changes: 1 addition & 1 deletion docs/tools/tuios.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ prefixは`Ctrl+Space`。表はprefixの後に押すキー。
| `1`〜`8` | workspaceを選択 |
| `9` | Gitルートのproject sessionへ |
| `T` / `t` | workspace名 / pane名を変更 |
| `X` / `x` | workspace / paneを閉じる。tmuxの`confirm-before`と同じく`y`で確定し、それ以外は閉じない |
| `X` / `x` | workspace / paneを閉じる。tmuxの`confirm-before`と同じく`y`の1キーで確定し、それ以外は閉じない。remote sessionではpopupがそのホストの`~/dotfiles`で動くため、ホスト側も`git pull`(`dotsync`)で揃える |
| `\|` / `-` | 左右 / 上下に分割 |
| `H` / `J` / `K` / `L` | paneを5セル単位でリサイズ |
| `z`、prefix不要の`Ctrl+z` | sidebarを残してzoom。zoom中はfocus枠線が紫 |
Expand Down
2 changes: 1 addition & 1 deletion scripts/test-tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def test_confirm_closes_only_after_yes(self):
listing = subprocess.CompletedProcess([], 0, json.dumps({"windows": windows}))
env = {"TUIOS_ACTIVE_PANE_ID": "a", "TUIOS_SESSION": "work"}
for target, answer, closed in (("pane", "y", ("tuios", "close-window", "a", "-s", "work")), ("workspace", "Y", ("tuios", "close-workspace", "3", "-s", "work")), ("pane", "n", None), ("workspace", "", None)):
with self.subTest(target=target, answer=answer), patch.dict(os.environ, env), patch.object(tui, "run", return_value=listing) as run, patch("builtins.input", return_value=answer) as ask:
with self.subTest(target=target, answer=answer), patch.dict(os.environ, env), patch.object(tui, "run", return_value=listing) as run, patch.object(tui, "read_key", return_value=answer) as ask:
tui.confirm(target)
ask.assert_called_once_with("kill-pane editor? (y/n) " if target == "pane" else "kill-workspace 3? (y/n) ")
if closed:
Expand Down
19 changes: 17 additions & 2 deletions scripts/tui
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,22 @@ def swap():
run("tuios", "focus-window", "-s", os.environ["TUIOS_SESSION"], active, capture_output=True)


def read_key(prompt):
# tmux confirm-before と同じく Enter を待たず 1 キーで答える。
print(prompt, end="", flush=True)
if not sys.stdin.isatty():
return sys.stdin.readline().strip()
import termios
import tty
fd = sys.stdin.fileno()
saved = termios.tcgetattr(fd)
try:
tty.setraw(fd)
return sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, saved)


def confirm(target):
# tmux confirm-before for the close keys TUIOS runs without asking.
session, active = os.environ["TUIOS_SESSION"], os.environ["TUIOS_ACTIVE_PANE_ID"]
Expand All @@ -209,8 +225,7 @@ def confirm(target):
question, command = f"kill-pane {pane.get('display_name') or pane['title']}?", ("close-window", active)
else:
question, command = f"kill-workspace {pane['workspace']}?", ("close-workspace", str(pane["workspace"]))
answer = input(f"{question} (y/n) ").strip().lower()
if answer == "y":
if read_key(f"{question} (y/n) ").lower() == "y":
run("tuios", *command, "-s", session, capture_output=True)


Expand Down
Loading