Add cf tutorial and graceful Ctrl+C handling
- Add Interactive Tool Picker tutorial to web docs - Handle SIGINT signal for clean exit on Ctrl+C - Add KeyboardInterrupt handling in main() - Add tutorial to Getting Started section in TOC Co-Authored-By: Claude Opus 4.5 <[email protected]>
This commit is contained in:
@@ -329,11 +329,24 @@ def main():
|
||||
"""Entry point for cf command."""
|
||||
global _ui_out
|
||||
import subprocess
|
||||
import signal
|
||||
|
||||
# Handle Ctrl+C gracefully
|
||||
def handle_sigint(sig, frame):
|
||||
# Restore cursor and exit cleanly
|
||||
sys.stderr.write(SHOW_CURSOR)
|
||||
sys.stderr.flush()
|
||||
sys.exit(0)
|
||||
|
||||
signal.signal(signal.SIGINT, handle_sigint)
|
||||
|
||||
# Read piped input if stdin is not a tty
|
||||
piped_input = None
|
||||
if not sys.stdin.isatty():
|
||||
piped_input = sys.stdin.read()
|
||||
try:
|
||||
piped_input = sys.stdin.read()
|
||||
except KeyboardInterrupt:
|
||||
sys.exit(0)
|
||||
|
||||
# Check if we have a terminal available
|
||||
if not os.path.exists('/dev/tty'):
|
||||
@@ -346,6 +359,9 @@ def main():
|
||||
try:
|
||||
with TTYInput() as tty_input:
|
||||
result = run_picker(tty_input)
|
||||
except KeyboardInterrupt:
|
||||
_write(SHOW_CURSOR)
|
||||
sys.exit(0)
|
||||
except OSError as e:
|
||||
print(f"cf requires a terminal: {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
Reference in New Issue
Block a user