Fixed the edit option
This commit is contained in:
38
copilot.py
38
copilot.py
@@ -5,6 +5,18 @@ import sys
|
||||
import time
|
||||
from os.path import expanduser
|
||||
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
|
||||
try:
|
||||
import gnureadline as readline
|
||||
except ImportError:
|
||||
import readline
|
||||
|
||||
|
||||
|
||||
# get a new github copilot token
|
||||
@@ -117,4 +129,28 @@ def generate_suggestion(prompt):
|
||||
prompt = " ".join(prompt)
|
||||
prompt = "!/bin/bash\n\n" + prompt + ":\n"
|
||||
token = get_token()
|
||||
print(get_suggestion(prompt, token))
|
||||
|
||||
suggestion = get_suggestion(prompt, token)
|
||||
panel = Panel(Text(suggestion, justify="center"), title_align="center", title="Accept? \[y/n/e]", expand=False)
|
||||
print(panel)
|
||||
# read a character from stdin without displaying it
|
||||
c = click.getchar()
|
||||
if c == "y":
|
||||
# execute the suggestion
|
||||
os.system(suggestion)
|
||||
elif c == "e":
|
||||
# prompt the suggestion by using redisplay
|
||||
def pre_input_hook():
|
||||
readline.insert_text(suggestion)
|
||||
readline.redisplay()
|
||||
|
||||
|
||||
readline.set_pre_input_hook(pre_input_hook)
|
||||
line = input()
|
||||
|
||||
# execute line
|
||||
os.system(line)
|
||||
# remove pre input hook
|
||||
readline.set_pre_input_hook()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user