Fix Ctrl+C/D handling and add Unix socket control API for testing
Key changes: - Fix keyboard input handling for control characters in GhosttyTerminalView - Set consumed_mods correctly (exclude Ctrl/Cmd from consumed mods) - Send unmodified character text for Ctrl+key combinations - Add unshifted_codepoint support for proper key encoding - Add TerminalController with Unix socket API (/tmp/ghosttytabs.sock) - Commands: send, send_key, list_tabs, new_tab, close_tab, select_tab - Supports ctrl-c, ctrl-d, ctrl-z, enter, tab, escape, etc. - Add Python test client and automated test suite - tests/ghosttytabs.py - Python client library - tests/test_ctrl_socket.py - Main Ctrl+C/D test suite (4 tests) - tests/test_signals_auto.py - Standalone PTY signal tests - Update CLAUDE.md with socket API documentation and testing guide - Update .gitignore for Python cache files This fixes Ctrl+C/D not working in apps like claude-code, btop, opencode while continuing to work in simpler apps like htop.
This commit is contained in:
parent
f969298c6e
commit
cd0f6200c0
12 changed files with 1519 additions and 21 deletions
121
tests/test_ctrl_interactive.py
Executable file
121
tests/test_ctrl_interactive.py
Executable file
|
|
@ -0,0 +1,121 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Interactive test for Ctrl+C and Ctrl+D in GhosttyTabs terminal.
|
||||
|
||||
This script tests that control signals are properly handled.
|
||||
Run this script inside the GhosttyTabs terminal.
|
||||
|
||||
Tests:
|
||||
1. Ctrl+C (SIGINT) - Should interrupt a running process
|
||||
2. Ctrl+D (EOF) - Should signal end-of-file on stdin
|
||||
|
||||
Usage:
|
||||
python3 test_ctrl_interactive.py
|
||||
"""
|
||||
|
||||
import signal
|
||||
import sys
|
||||
import os
|
||||
|
||||
def test_ctrl_c():
|
||||
"""Test Ctrl+C signal handling"""
|
||||
print("\n=== Test 1: Ctrl+C (SIGINT) ===")
|
||||
print("This test will wait for you to press Ctrl+C.")
|
||||
print("Press Ctrl+C now...")
|
||||
|
||||
received = [False]
|
||||
|
||||
def handler(signum, frame):
|
||||
received[0] = True
|
||||
print("\n✅ SUCCESS: SIGINT (Ctrl+C) received!")
|
||||
|
||||
old_handler = signal.signal(signal.SIGINT, handler)
|
||||
|
||||
try:
|
||||
# Wait for up to 10 seconds for Ctrl+C
|
||||
import time
|
||||
for i in range(10):
|
||||
if received[0]:
|
||||
break
|
||||
time.sleep(1)
|
||||
if not received[0]:
|
||||
print(f" Waiting... ({10-i-1}s remaining)")
|
||||
|
||||
if not received[0]:
|
||||
print("\n❌ FAILED: No SIGINT received within 10 seconds")
|
||||
print(" Ctrl+C may not be working correctly.")
|
||||
return False
|
||||
return True
|
||||
finally:
|
||||
signal.signal(signal.SIGINT, old_handler)
|
||||
|
||||
def test_ctrl_d():
|
||||
"""Test Ctrl+D (EOF) handling"""
|
||||
print("\n=== Test 2: Ctrl+D (EOF) ===")
|
||||
print("This test will read from stdin.")
|
||||
print("Press Ctrl+D (on empty line) to send EOF...")
|
||||
print("Type something and press Enter, then Ctrl+D on empty line:")
|
||||
|
||||
try:
|
||||
lines = []
|
||||
while True:
|
||||
try:
|
||||
line = input("> ")
|
||||
lines.append(line)
|
||||
except EOFError:
|
||||
print("\n✅ SUCCESS: EOF (Ctrl+D) received!")
|
||||
print(f" Lines entered before EOF: {len(lines)}")
|
||||
return True
|
||||
except KeyboardInterrupt:
|
||||
print("\n⚠️ Got Ctrl+C instead of Ctrl+D")
|
||||
return False
|
||||
|
||||
def main():
|
||||
print("=" * 50)
|
||||
print("GhosttyTabs Control Signal Test")
|
||||
print("=" * 50)
|
||||
print("\nThis script tests if Ctrl+C and Ctrl+D work correctly.")
|
||||
print("Run this inside the GhosttyTabs terminal to verify the fix.\n")
|
||||
|
||||
# Check if running in a terminal
|
||||
if not os.isatty(sys.stdin.fileno()):
|
||||
print("Warning: Not running in a terminal")
|
||||
|
||||
results = []
|
||||
|
||||
# Test Ctrl+C
|
||||
try:
|
||||
results.append(("Ctrl+C (SIGINT)", test_ctrl_c()))
|
||||
except Exception as e:
|
||||
print(f"Error in Ctrl+C test: {e}")
|
||||
results.append(("Ctrl+C (SIGINT)", False))
|
||||
|
||||
# Test Ctrl+D
|
||||
try:
|
||||
results.append(("Ctrl+D (EOF)", test_ctrl_d()))
|
||||
except Exception as e:
|
||||
print(f"Error in Ctrl+D test: {e}")
|
||||
results.append(("Ctrl+D (EOF)", False))
|
||||
|
||||
# Summary
|
||||
print("\n" + "=" * 50)
|
||||
print("Test Results Summary")
|
||||
print("=" * 50)
|
||||
|
||||
all_passed = True
|
||||
for name, passed in results:
|
||||
status = "✅ PASS" if passed else "❌ FAIL"
|
||||
print(f" {name}: {status}")
|
||||
if not passed:
|
||||
all_passed = False
|
||||
|
||||
print()
|
||||
if all_passed:
|
||||
print("All tests passed! Control signals are working correctly.")
|
||||
else:
|
||||
print("Some tests failed. Check the key input handling code.")
|
||||
|
||||
return 0 if all_passed else 1
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Loading…
Add table
Add a link
Reference in a new issue