-
Notifications
You must be signed in to change notification settings - Fork 4
/
styles.go
120 lines (95 loc) · 3.67 KB
/
styles.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package ui
import (
"fmt"
"io"
"strings"
"github.com/charmbracelet/bubbles/list"
"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
var (
header = lipgloss.NewStyle().Bold(true)
hint = lipgloss.NewStyle().Faint(true).SetString("|")
Header = header.Copy().SetString("#").Render
Skip = header.Copy().Faint(true).SetString("# Skipped:").Render
Hint = hint.Copy().Render
Underline = lipgloss.NewStyle().Underline(true).Render
Warning = header.Copy().SetString(bgBanana(fgMidnight("!")) + fgBanana(" Warning:")).Render
// https://github.com/charmbracelet/lipgloss/blob/v0.9.1/style.go#L149
StepAlert = lipgloss.NewStyle().SetString(" " + Announce("!")).Render
StepDone = lipgloss.NewStyle().SetString(" -").Render
StepHint = hint.Copy().SetString(" |").Render
StepInProgress = lipgloss.NewStyle().SetString(" *").Render
StepPrompt = lipgloss.NewStyle().SetString(" " + Prompt.Render("?")).Render
Accentuate = lipgloss.NewStyle().Italic(true).Render
Action = lipgloss.NewStyle().Bold(true).Foreground(colorBrandPrimary).Render
Announce = lipgloss.NewStyle().Background(colorBrandSecondary).Render
Error = lipgloss.NewStyle().Bold(true).Foreground(colorDanger).Render
Emphasize = lipgloss.NewStyle().Bold(true).Render
EmphasizeUnderline = lipgloss.NewStyle().Bold(true).Underline(true).Render
Titlize = lipgloss.NewStyle().Bold(true).Render
URL = lipgloss.NewStyle().Faint(true).Underline(true).Render
Whisper = lipgloss.NewStyle().Faint(true).Render
bgBanana = lipgloss.NewStyle().Background(colorBanana).Render
fgBanana = lipgloss.NewStyle().Foreground(colorBanana).Render
fgMidnight = lipgloss.NewStyle().Foreground(colorMidnight).Render
colorBrandPrimary = colorMandarin
colorBrandSecondary = colorGrape
colorDanger = colorApple
// Brand Palette
colorMidnight = lipgloss.Color("#110C18")
colorGrape = lipgloss.Color("#60539E")
colorMandarin = lipgloss.Color("#FF6000")
colorApple = lipgloss.Color("#CE4433")
colorBanana = lipgloss.Color("#FBF5AC")
// colorLime = lipgloss.Color("#9EC756")
Prompt = lipgloss.NewStyle().Foreground(colorBrandPrimary)
Waiting = spinner.MiniDot
)
func WaitingSpinner() spinner.Model {
return spinner.New(
spinner.WithSpinner(Waiting),
spinner.WithStyle(lipgloss.NewStyle().Foreground(colorBrandSecondary)),
)
}
type ListItem[T any] struct {
Key T
Value string
}
func (li ListItem[T]) FilterValue() string { return li.Value }
type itemDelegate[T any] struct{}
func (d itemDelegate[T]) Height() int { return 1 }
func (d itemDelegate[T]) Spacing() int { return 0 }
func (d itemDelegate[T]) Update(_ tea.Msg, _ *list.Model) tea.Cmd { return nil }
func (d itemDelegate[T]) Render(w io.Writer, m list.Model, index int, listItem list.Item) {
i, ok := listItem.(ListItem[T])
if !ok {
return
}
if index == m.Index() {
fmt.Fprintf(w, Action(fmt.Sprintf(" > %s", i.Value)))
} else {
fmt.Fprintf(w, fmt.Sprintf(" %s", i.Value))
}
}
func List[T any](items []ListItem[T]) list.Model {
var lis []list.Item
for _, item := range items {
lis = append(lis, item)
}
l := list.New(lis, itemDelegate[T]{}, 80, len(items))
l.SetShowFilter(false)
l.SetShowHelp(false)
l.SetShowPagination(false)
l.SetShowStatusBar(false)
l.SetShowTitle(false)
return l
}
func Domains(domains []string) string {
var styledDomains []string
for _, domain := range domains {
styledDomains = append(styledDomains, URL(domain))
}
return strings.Join(styledDomains, ", ")
}