-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutil.go
50 lines (45 loc) · 1.04 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"os"
"os/exec"
"time"
progressbar "github.com/schollz/progressbar/v3"
)
func showSpinner(bar *progressbar.ProgressBar, done chan bool) {
tick := time.Tick(100 * time.Millisecond)
for {
select {
case <-tick:
bar.Add(1)
case <-done:
return
}
}
}
func getProgressBar() *progressbar.ProgressBar {
return progressbar.NewOptions64(
-1,
progressbar.OptionSetDescription("Waiting for ChatGPT to respond..."),
progressbar.OptionEnableColorCodes(true),
progressbar.OptionClearOnFinish(),
progressbar.OptionSetWriter(os.Stderr),
progressbar.OptionSetWidth(10),
progressbar.OptionThrottle(65*time.Millisecond),
progressbar.OptionOnCompletion(func() {
fmt.Fprint(os.Stderr, "\n")
}),
progressbar.OptionSpinnerType(14),
progressbar.OptionFullWidth(),
progressbar.OptionSetRenderBlankState(true),
)
}
func executeScript(script string) error {
cmd := exec.Command("bash", "-c", script)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return err
}
return nil
}