-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.go
164 lines (131 loc) · 4.74 KB
/
ui.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package main
import (
"fmt"
"strings"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/huh"
"github.com/charmbracelet/lipgloss"
)
// formFilePicker wraps a huh.FilePicker.
//
// We need this to override the KeyBinds method which determines what keys is shown
// in the help view.
type formFilePicker struct {
*huh.FilePicker
km huh.FilePickerKeyMap
}
func newFormFilePicker(fp *huh.FilePicker, km huh.FilePickerKeyMap) formFilePicker {
return formFilePicker{
FilePicker: fp,
km: km,
}
}
func defaultList(title string, km keymap, shortHelps, fullHelps func() []key.Binding) list.Model {
l := list.New([]list.Item{}, listDelegate(), 0, 0)
l.Title = title
l.Styles.Title = titleStyle
// Remove horizontal padding from the title bar for consistency.
l.Styles.TitleBar = lipgloss.NewStyle()
l.DisableQuitKeybindings()
l.AdditionalShortHelpKeys = shortHelps
l.AdditionalFullHelpKeys = fullHelps
l.KeyMap.Quit = km.quit
l.KeyMap.ShowFullHelp = km.openHelp
l.KeyMap.CloseFullHelp = km.closeHelp
return l
}
func listDelegate() list.DefaultDelegate {
delegate := list.NewDefaultDelegate()
delegate.Styles.SelectedTitle = listSelectedTitleStyle
delegate.Styles.SelectedDesc = listDescSelectedStyle
delegate.Styles.NormalTitle = listTitleStyle
delegate.Styles.NormalDesc = listDescStyle
return delegate
}
func logoView() string {
return logoStyle.Render(logo)
}
func logoHeight() int {
return lipgloss.Height(logoView())
}
func errView(width int, err error) string {
return errorStyle.Render(fmt.Sprintf("Error: %s%s",
err, strings.Repeat(" ", width)))
}
func errHeight(width int, err error) int {
return lipgloss.Height(errView(width, err))
}
// logo is generated at https://patorjk.com/software/taag/#p=display&f=Slant&t=DOConvo
const logo = `
____ ____ ______
/ __ \/ __ \/ ____/___ ____ _ ______
/ / / / / / / / / __ \/ __ \ | / / __ \
/ /_/ / /_/ / /___/ /_/ / / / / |/ / /_/ /
/_____/\____/\____/\____/_/ /_/|___/\____/
`
// These styles are based on the official Catppuccin palette:
// https://github.com/catppuccin/catppuccin#-palette
var (
// General styles
logoStyle = lipgloss.NewStyle().
Foreground(lipgloss.AdaptiveColor{Light: "#e64553", Dark: "#f38ba8"}). // Red
Bold(true).
PaddingBottom(1)
titleStyle = lipgloss.NewStyle().
Foreground(lipgloss.AdaptiveColor{Light: "#e64553", Dark: "#f38ba8"}). // Red
Bold(true).
BorderStyle(lipgloss.RoundedBorder()).
BorderForeground(lipgloss.AdaptiveColor{Light: "#dc8a78", Dark: "#f2cdcd"}). // Rosewater
PaddingLeft(2).
PaddingRight(2).
MarginBottom(1)
errorStyle = lipgloss.NewStyle().
Foreground(lipgloss.AdaptiveColor{Light: "#eff1f5", Dark: "#cdd6f4"}). // Text color (Base)
Background(lipgloss.AdaptiveColor{Light: "#e64553", Dark: "#d20f39"}). // Red (darker variant)
Bold(true).
Padding(0, 1)
// List styles
listSelectedTitleStyle = lipgloss.NewStyle().
Border(lipgloss.NormalBorder(), false, false, false, true).
Foreground(lipgloss.AdaptiveColor{Light: "#e64553", Dark: "#f38ba8"}). // Red
BorderForeground(lipgloss.AdaptiveColor{Light: "#dc8a78", Dark: "#f2cdcd"}). // Rosewater
Padding(0, 0, 0, 1)
listDescSelectedStyle = listSelectedTitleStyle.
Foreground(lipgloss.AdaptiveColor{Light: "#9ca0b0", Dark: "#a6adc8"}) // Overlay0
listTitleStyle = lipgloss.NewStyle().
Foreground(lipgloss.AdaptiveColor{Light: "#ea76cb", Dark: "#f5c2e7"}). // Pink
Bold(true)
listDescStyle = lipgloss.NewStyle().
Foreground(lipgloss.AdaptiveColor{Light: "#9ca0b0", Dark: "#a6adc8"}). // Overlay0
Italic(true)
// Chat styles
chatEntityStyle = lipgloss.NewStyle().
Foreground(lipgloss.AdaptiveColor{Light: "#ea76cb", Dark: "#f5c2e7"}). // Pink
Bold(true)
chatContentStyle = lipgloss.NewStyle().
Foreground(lipgloss.AdaptiveColor{Light: "#4c4f69", Dark: "#cdd6f4"}). // Text
Padding(0, 4)
chatTextareaStyle = lipgloss.NewStyle().
Border(lipgloss.RoundedBorder()).
BorderForeground(lipgloss.AdaptiveColor{Light: "#dc8a78", Dark: "#f2cdcd"}). // Rosewater
Padding(1)
spinnerStyle = lipgloss.NewStyle().
Foreground(lipgloss.AdaptiveColor{Light: "#7287fd", Dark: "#b4befe"}). // Lavender
Bold(true).
PaddingLeft(1).
PaddingRight(1)
)
func (f formFilePicker) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
filePicker, cmd := f.FilePicker.Update(msg)
if fp, ok := filePicker.(*huh.FilePicker); ok {
f.FilePicker = fp
}
return f, cmd
}
func (f formFilePicker) KeyBinds() []key.Binding {
f.km.Select.SetEnabled(true)
f.km.Back.SetEnabled(true)
return []key.Binding{f.km.Open, f.km.Back, f.km.Select, f.km.Close, f.km.Prev, f.km.Next}
}