Read prompt from clipboard without copying selection
This commit is contained in:
@@ -1,29 +1,13 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import time
|
||||
|
||||
import keyboard
|
||||
import pyperclip
|
||||
|
||||
|
||||
def capture_clipboard() -> str:
|
||||
"""Return the current clipboard text without modifying it."""
|
||||
return pyperclip.paste() or ""
|
||||
|
||||
|
||||
# Backward-compatible alias for older imports/tests.
|
||||
def capture_selection(copy_wait_seconds: float = 1.0, restore_clipboard: bool = True) -> str:
|
||||
previous = pyperclip.paste()
|
||||
keyboard.send("ctrl+c")
|
||||
|
||||
deadline = time.monotonic() + max(copy_wait_seconds, 0.05)
|
||||
captured = previous
|
||||
while time.monotonic() < deadline:
|
||||
current = pyperclip.paste()
|
||||
if current != previous:
|
||||
captured = current
|
||||
break
|
||||
time.sleep(0.03)
|
||||
else:
|
||||
captured = pyperclip.paste()
|
||||
|
||||
if restore_clipboard:
|
||||
try:
|
||||
pyperclip.copy(previous)
|
||||
except pyperclip.PyperclipException:
|
||||
pass
|
||||
return captured or ""
|
||||
return capture_clipboard()
|
||||
|
||||
Reference in New Issue
Block a user