mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-27 15:55:00 +00:00
feat: add clipboard watcher to monitor and update IO placeholder
This commit is contained in:
parent
eeed79009a
commit
6f36a97c4a
1 changed files with 63 additions and 0 deletions
|
@ -0,0 +1,63 @@
|
|||
import threading
|
||||
import time
|
||||
import pyperclip
|
||||
|
||||
class ClipboardWatcher:
|
||||
"""Watches clipboard for changes and updates IO placeholder"""
|
||||
|
||||
def __init__(self, io, verbose=False):
|
||||
self.io = io
|
||||
self.verbose = verbose
|
||||
self.stop_event = None
|
||||
self.watcher_thread = None
|
||||
self.last_clipboard = None
|
||||
|
||||
def start(self):
|
||||
"""Start watching clipboard for changes"""
|
||||
self.stop_event = threading.Event()
|
||||
self.last_clipboard = pyperclip.paste()
|
||||
|
||||
def watch_clipboard():
|
||||
while not self.stop_event.is_set():
|
||||
try:
|
||||
current = pyperclip.paste()
|
||||
if current != self.last_clipboard:
|
||||
self.last_clipboard = current
|
||||
self.io.placeholder = current
|
||||
self.io.interrupt_input()
|
||||
time.sleep(0.5)
|
||||
except Exception as e:
|
||||
if self.verbose:
|
||||
from aider.dump import dump
|
||||
dump(f"Clipboard watcher error: {e}")
|
||||
continue
|
||||
|
||||
self.watcher_thread = threading.Thread(target=watch_clipboard, daemon=True)
|
||||
self.watcher_thread.start()
|
||||
|
||||
def stop(self):
|
||||
"""Stop watching clipboard for changes"""
|
||||
if self.stop_event:
|
||||
self.stop_event.set()
|
||||
if self.watcher_thread:
|
||||
self.watcher_thread.join()
|
||||
self.watcher_thread = None
|
||||
self.stop_event = None
|
||||
|
||||
def main():
|
||||
"""Example usage of the clipboard watcher"""
|
||||
from aider.io import InputOutput
|
||||
|
||||
io = InputOutput()
|
||||
watcher = ClipboardWatcher(io, verbose=True)
|
||||
|
||||
try:
|
||||
watcher.start()
|
||||
while True:
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
print("\nStopped watching clipboard")
|
||||
watcher.stop()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue