-
Notifications
You must be signed in to change notification settings - Fork 4
/
themes.go
56 lines (45 loc) · 1.25 KB
/
themes.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
package prompt
import (
"strings"
"github.com/cqroot/prompt/constants"
)
type State int
const (
StateNormal State = iota
StateFinish
StateError
)
type Theme func(string, State, string) string
func ThemeDefault(msg string, state State, model string) string {
s := strings.Builder{}
switch state {
case StateNormal:
s.WriteString(constants.DefaultFinishPromptPrefixStyle.Render("?"))
case StateFinish:
s.WriteString(constants.DefaultFinishPromptPrefixStyle.Render("✔"))
case StateError:
s.WriteString(constants.DefaultErrorPromptPrefixStyle.Render("✖"))
}
s.WriteString(" ")
s.WriteString(msg)
s.WriteString(" ")
if state == 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()
}
// ThemeDefaultClear is basically the same as ThemeDefault, but it will
// clear the screen after the selection is completed or after exiting.
func ThemeDefaultClear(msg string, state State, model string) string {
if state == StateFinish || state == StateError {
return ""
}
return ThemeDefault(msg, state, model)
}