v1.8.6: safe Ctrl+C — double-press for SIGINT
- Single Ctrl+C with selection → copy - Single Ctrl+C without selection → hint "Press again to send SIGINT" - Double Ctrl+C within 1.5s → sends SIGINT - Prevents accidental process termination Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -695,33 +695,34 @@ class TerminalWidget(tk.Frame):
|
||||
|
||||
return "break"
|
||||
|
||||
# ── Ctrl+C: always SIGINT, use Ctrl+Shift+C to copy ──
|
||||
# ── Ctrl+C: copy or SIGINT (double-press within 1.5s) ──
|
||||
def _on_ctrl_c(self, event):
|
||||
if event.state & 0x1: # Shift held → Ctrl+Shift+C → copy
|
||||
return self._on_copy(event)
|
||||
|
||||
now = time.monotonic()
|
||||
double = (now - self._last_ctrl_c) < 0.3
|
||||
self._last_ctrl_c = now
|
||||
|
||||
if double:
|
||||
# Double Ctrl+C → always SIGINT (force kill)
|
||||
self._send(b"\x03")
|
||||
return "break"
|
||||
|
||||
# Single Ctrl+C: copy if there is a selection, otherwise SIGINT
|
||||
# If there is a selection → always copy (no SIGINT risk)
|
||||
try:
|
||||
sel = self._text.get("sel.first", "sel.last")
|
||||
if sel:
|
||||
self.clipboard_clear()
|
||||
self.clipboard_append(sel)
|
||||
self._flash_status("Copied!", "#44cc44")
|
||||
self._last_ctrl_c = 0.0
|
||||
return "break"
|
||||
except tk.TclError:
|
||||
pass
|
||||
|
||||
# No selection → SIGINT
|
||||
self._send(b"\x03")
|
||||
# No selection → double Ctrl+C within 1.5s sends SIGINT
|
||||
now = time.monotonic()
|
||||
if (now - self._last_ctrl_c) < 1.5:
|
||||
self._send(b"\x03")
|
||||
self._last_ctrl_c = 0.0
|
||||
self._flash_status("SIGINT sent", "#ff8800")
|
||||
return "break"
|
||||
|
||||
# First press → hint, wait for second
|
||||
self._last_ctrl_c = now
|
||||
self._flash_status("Press Ctrl+C again to send SIGINT", "#ccaa00")
|
||||
return "break"
|
||||
|
||||
def _on_copy(self, event):
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user