-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
55 lines (43 loc) · 1 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
package main
import (
"encoding/json"
"fmt"
"strings"
_ "embed"
"github.com/charmbracelet/huh"
"github.com/charmbracelet/lipgloss"
"github.com/muesli/termenv"
"github.com/rivo/uniseg"
)
//go:embed glyphs.json
var glyphsJSON []byte
type Glyph struct {
Icon string `json:"icon"`
Name string `json:"name"`
}
const iconWidth = 3
func main() {
var glyphs []Glyph
var selected Glyph
_ = json.Unmarshal(glyphsJSON, &glyphs)
glyphOptions := make([]huh.Option[Glyph], len(glyphs))
for i, g := range glyphs {
title := " " + g.Icon + strings.Repeat(" ", iconWidth-uniseg.StringWidth(g.Icon)) + g.Name
glyphOptions[i] = huh.NewOption(title, g)
}
theme := huh.ThemeCharm()
theme.Focused.Base.Border(lipgloss.HiddenBorder())
_ = huh.NewForm(
huh.NewGroup(
huh.NewSelect[Glyph]().
Title("Glyphs").
Description(" ").
Options(glyphOptions...).
Value(&selected).
Height(20),
huh.NewNote(),
),
).WithTheme(theme).Run()
termenv.Copy(selected.Icon)
fmt.Println(selected.Icon)
}