Skip to content

Commit e95c875

Browse files
authored
Merge pull request #2 from spideyz0r/spinner
Spinner
2 parents 575d4ee + a1989e0 commit e95c875

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

main.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"strconv"
1010
"strings"
11+
"time"
1112

1213
"github.com/mitchellh/go-wordwrap"
1314
"github.com/pborman/getopt"
@@ -83,10 +84,14 @@ func main() {
8384
Content: userInput,
8485
})
8586

87+
stop := make(chan bool)
88+
go spinner(10*time.Millisecond, stop)
89+
8690
output, err := sendMessage(client, messages, float32(t), uint(w))
8791
if err != nil {
8892
log.Fatal(err)
8993
}
94+
stop <- true
9095
fmt.Println(output)
9196
}
9297
}
@@ -96,7 +101,7 @@ func sendMessage(client *openai.OpenAIClient, messages []openai.Message, t float
96101
if err != nil {
97102
return "", err
98103
} else {
99-
return wordwrap.WrapString(fmt.Sprintf("Bot: %v\n", completion.Choices[0].Message.Content), w), nil
104+
return wordwrap.WrapString(fmt.Sprintf("\nBot: %v\n", completion.Choices[0].Message.Content), w), nil
100105
}
101106
}
102107

@@ -118,3 +123,18 @@ func getUserInput(delim string) string {
118123
}
119124
return strings.TrimSuffix(input, delim)
120125
}
126+
127+
func spinner(delay time.Duration, stop chan bool) {
128+
for {
129+
for _, r := range `-\|/` {
130+
select {
131+
case <-stop:
132+
fmt.Print("\r")
133+
return
134+
default:
135+
fmt.Printf("\r%c", r)
136+
time.Sleep(delay)
137+
}
138+
}
139+
}
140+
}

rpm/gpt-cli-chat.spec

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
%global go_release go1.18.10
33

44
Name: gpt-cli-chat
5-
Version: 0.1
5+
Version: 0.2
66
Release: 1%{?dist}
77
Summary: gpt-cli-chat tool
88
License: GPLv3
@@ -35,6 +35,9 @@ install -Dpm 0755 %{name} %{buildroot}%{_bindir}/%{name}
3535
%license LICENSE
3636

3737
%changelog
38+
* Thu Apr 13 2023 spideyz0r <47341410+spideyz0r@users.noreply.github.com> 0.2-1
39+
- Bump version
40+
3841
* Thu Apr 13 2023 spideyz0r <47341410+spideyz0r@users.noreply.github.com> 0.1-1
3942
- Initial build
4043

0 commit comments

Comments
 (0)