Added option to copy command to clipboard
This commit is contained in:
15
copilot.py
15
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")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user