generated from n3wscott/cli-base
/
key.go
62 lines (51 loc) · 1.15 KB
/
key.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
package key
import (
"context"
"fmt"
"github.com/fatih/color"
"github.com/gosuri/uitable"
"sort"
"tableflip.dev/bujo/pkg/glyph"
)
type Key struct{}
func (k *Key) Do(ctx context.Context) error {
_, _ = fmt.Fprintln(color.Output, "")
bullets := glyph.DefaultBullets()
bl := make([]glyph.Glyph, 0, len(bullets))
for _, v := range bullets {
if v.Printed {
bl = append(bl, v)
}
}
sort.Sort(glyph.ByOrder(bl))
k.Key(ctx, bl, false)
_, _ = fmt.Fprintln(color.Output, "")
sigs := glyph.DefaultSignifiers()
sl := make([]glyph.Glyph, 0, len(sigs))
for _, v := range sigs {
if v.Printed {
sl = append(sl, v)
}
}
sort.Sort(glyph.ByOrder(sl))
k.Key(ctx, sl, true)
fmt.Println("")
return nil
}
func (k *Key) Key(ctx context.Context, glyfs []glyph.Glyph, sig bool) {
bold := color.New(color.Bold)
tbl := uitable.New()
tbl.Separator = " "
if sig {
tbl.AddRow(bold.Sprint("Signifiers"), bold.Sprint("Meaning"))
} else {
tbl.AddRow(bold.Sprint(" Bullets"), bold.Sprint("Meaning"))
}
for _, v := range glyfs {
if sig == v.Signifier {
tbl.AddRow(v.Symbol, v.Meaning)
}
}
tbl.RightAlign(0)
_, _ = fmt.Fprintln(color.Output, tbl)
}