diff --git a/copilot.py b/copilot.py index 6abf201..9c6a100 100755 --- a/copilot.py +++ b/copilot.py @@ -8,10 +8,7 @@ import click from rich import print from rich.panel import Panel from rich.text import Text -import signal -import subprocess -from threading import Thread -from pynput.keyboard import Key, Controller +import pyperclip try: import gnureadline as readline except ImportError: @@ -131,7 +128,7 @@ def generate_suggestion(prompt): token = get_token() suggestion = get_suggestion(prompt, token) - panel = Panel(Text(suggestion, justify="center"), title_align="center", title="Accept? \[y/n/e]", expand=False) + panel = Panel(Text(suggestion, justify="center"), title_align="center", title="Execute? \[y/n/e/c]", expand=False) print(panel) # read a character from stdin without displaying it c = click.getchar() @@ -153,4 +150,12 @@ def generate_suggestion(prompt): # remove pre input hook readline.set_pre_input_hook() + # set history + readline.clear_history() + readline.add_history(line) + elif c == "c": + # copy the suggestion to clipboard + pyperclip.copy(suggestion) + print("Copied to clipboard") + diff --git a/token.json b/token.json index 66720aa..1554859 100644 --- a/token.json +++ b/token.json @@ -1 +1 @@ -{"expires_at": 1669980922, "public_suggestions": "disabled", "refresh_in": 1500, "sku": "free_educational", "telemetry": "disabled", "token": "tid=d47460691ef58366f713e508d59d807b;exp=1669980922;sku=free_educational:fb44337ee996917b43d51aa8bd1553ecce5ef1d7880333106ee25689648ca133", "tracking_id": "d47460691ef58366f713e508d59d807b"} \ No newline at end of file +{"expires_at": 1669988057, "public_suggestions": "disabled", "refresh_in": 1500, "sku": "free_educational", "telemetry": "disabled", "token": "tid=d47460691ef58366f713e508d59d807b;exp=1669988057;sku=free_educational:8f88da8df463706243fcf52df0f6e9d5ec3ca0126ccdc919c2528ce4f7573101", "tracking_id": "d47460691ef58366f713e508d59d807b"} \ No newline at end of file