Fixed the edit option
This commit is contained in:
parent
09f9129e58
commit
3fc206b0c6
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()
|
||||
|
||||
|
||||
|
||||
@ -1 +1 @@
|
||||
{"expires_at": 1669917293, "public_suggestions": "disabled", "refresh_in": 1500, "sku": "free_educational", "telemetry": "disabled", "token": "tid=d47460691ef58366f713e508d59d807b;exp=1669917293;sku=free_educational:f9553e702e2a159aa3459e09a3b0b2c0ca83a11c4042ea928c8af5cf8732063b", "tracking_id": "d47460691ef58366f713e508d59d807b"}
|
||||
{"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"}
|
||||
Loading…
x
Reference in New Issue
Block a user