mirror of
https://github.com/Direct-Dev-Ru/go-lcg.git
synced 2025-11-16 01:29:55 +00:00
feat: add regenerate options
This commit is contained in:
75
main.go
75
main.go
@@ -58,6 +58,37 @@ func handleCommand(cmd string) int {
|
|||||||
return CMD_COMPLETION
|
return CMD_COMPLETION
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getCommand(gpt3 gpt.Gpt3, cmd string) (string, float64) {
|
||||||
|
gpt3.InitKey()
|
||||||
|
s := time.Now()
|
||||||
|
done := make(chan bool)
|
||||||
|
go func() {
|
||||||
|
loadingChars := []rune{'-', '\\', '|', '/'}
|
||||||
|
i := 0
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
fmt.Printf("\r")
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
fmt.Printf("\rLoading %c", loadingChars[i])
|
||||||
|
i = (i + 1) % len(loadingChars)
|
||||||
|
time.Sleep(30 * time.Millisecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
r := gpt3.Completions(cmd)
|
||||||
|
done <- true
|
||||||
|
elapsed := time.Since(s).Seconds()
|
||||||
|
elapsed = math.Round(elapsed*100) / 100
|
||||||
|
|
||||||
|
if r == "" {
|
||||||
|
return "", elapsed
|
||||||
|
}
|
||||||
|
return r, elapsed
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
currentUser, err := user.Current()
|
currentUser, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -99,42 +130,24 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
gpt3.InitKey()
|
c := "R"
|
||||||
s := time.Now()
|
r := ""
|
||||||
done := make(chan bool)
|
elapsed := 0.0
|
||||||
go func() {
|
for c == "R" || c == "r" {
|
||||||
loadingChars := []rune{'-', '\\', '|', '/'}
|
r, elapsed = getCommand(gpt3, cmd)
|
||||||
i := 0
|
c = "N"
|
||||||
for {
|
fmt.Printf("Completed in %v seconds\n\n", elapsed)
|
||||||
select {
|
fmt.Println(r)
|
||||||
case <-done:
|
fmt.Print("\nDo you want to (e)xecute, (r)egenerate, or take (N)o action on the command? (e/r/N): ")
|
||||||
fmt.Printf("\r")
|
fmt.Scanln(&c)
|
||||||
return
|
if c == "N" || c == "n" {
|
||||||
default:
|
return
|
||||||
fmt.Printf("\rLoading %c", loadingChars[i])
|
|
||||||
i = (i + 1) % len(loadingChars)
|
|
||||||
time.Sleep(30 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}()
|
}
|
||||||
|
|
||||||
r := gpt3.Completions(cmd)
|
|
||||||
done <- true
|
|
||||||
if r == "" {
|
if r == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c := "N"
|
|
||||||
elapsed := time.Since(s).Seconds()
|
|
||||||
elapsed = math.Round(elapsed*100) / 100
|
|
||||||
fmt.Printf("Completed in %v seconds\n\n", elapsed)
|
|
||||||
fmt.Println(r)
|
|
||||||
fmt.Print("\nAre you sure you want to execute the command? (y/N): ")
|
|
||||||
fmt.Scanln(&c)
|
|
||||||
if c == "N" || c == "n" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
cmsplit := strings.Split(r, " ")
|
cmsplit := strings.Split(r, " ")
|
||||||
cm := exec.Command(cmsplit[0], cmsplit[1:]...)
|
cm := exec.Command(cmsplit[0], cmsplit[1:]...)
|
||||||
out, err := cm.Output()
|
out, err := cm.Output()
|
||||||
|
|||||||
Reference in New Issue
Block a user