-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
64 lines (53 loc) · 1.34 KB
/
main.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"errors"
"fmt"
"os"
"strings"
"github.com/cqroot/prompt"
"github.com/cqroot/prompt/constants"
)
func CheckErr(err error) {
if err != nil {
if errors.Is(err, prompt.ErrUserQuit) {
fmt.Fprintln(os.Stderr, "Error:", err)
os.Exit(1)
} else {
panic(err)
}
}
}
func EmojiTheme(msg string, state prompt.State, model string) string {
s := strings.Builder{}
switch state {
case prompt.StateNormal:
s.WriteString(constants.DefaultFinishPromptPrefixStyle.Render("🤔 "))
case prompt.StateFinish:
s.WriteString(constants.DefaultFinishPromptPrefixStyle.Render("😃 "))
case prompt.StateError:
s.WriteString(constants.DefaultErrorPromptPrefixStyle.Render("😡 "))
}
s.WriteString(" ")
s.WriteString(msg)
s.WriteString(" ")
if state == prompt.StateNormal {
s.WriteString(constants.DefaultNormalPromptSuffixStyle.Render("›"))
s.WriteString(" ")
s.WriteString(model)
} else {
s.WriteString(constants.DefaultFinishPromptSuffixStyle.Render("…"))
s.WriteString(" ")
s.WriteString(model)
s.WriteString("\n")
}
return s.String()
}
func main() {
val, err := prompt.New(prompt.WithTheme(EmojiTheme)).
Ask("Emoji Theme:").Input("Blah blah")
CheckErr(err)
fmt.Printf("{ %s }\n", val)
_, err = prompt.New(prompt.WithTheme(EmojiTheme)).
Ask("Emoji Theme:").Input("Blah blah")
CheckErr(err)
}