-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
meow.go
133 lines (110 loc) · 2.85 KB
/
meow.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
package view
import (
"context"
"fmt"
"strings"
"github.com/derailed/k9s/internal/config"
"github.com/derailed/k9s/internal/model"
"github.com/derailed/k9s/internal/ui"
"github.com/derailed/tview"
"github.com/gdamore/tcell"
)
// Meow represents a bomb viewer
type Meow struct {
*tview.TextView
actions ui.KeyActions
app *App
says string
}
// NewMeow returns a details viewer.
func NewMeow(app *App, says string) *Meow {
return &Meow{
TextView: tview.NewTextView(),
app: app,
actions: make(ui.KeyActions),
says: says,
}
}
// Init initializes the viewer.
func (m *Meow) Init(_ context.Context) error {
m.SetBorder(true)
m.SetScrollable(true).SetWrap(true).SetRegions(true)
m.SetDynamicColors(true)
m.SetHighlightColor(tcell.ColorOrange)
m.SetTitleColor(tcell.ColorAqua)
m.SetInputCapture(m.keyboard)
m.SetBorderPadding(0, 0, 1, 1)
m.updateTitle()
m.SetTextAlign(tview.AlignCenter)
m.app.Styles.AddListener(m)
m.StylesChanged(m.app.Styles)
m.bindKeys()
m.SetInputCapture(m.keyboard)
m.talk()
return nil
}
func (m *Meow) talk() {
says := m.says
if len(says) == 0 {
says = "Nothing to report here. Please move along..."
}
buff := make([]string, 0, len(cow)+3)
buff = append(buff, " "+strings.Repeat("─", len(says)+8))
buff = append(buff, fmt.Sprintf("< [red::b]MEOW! %s [-::-] >", says))
buff = append(buff, " "+strings.Repeat("─", len(says)+8))
spacer := strings.Repeat(" ", len(says)/2-8)
for _, s := range cow {
buff = append(buff, spacer+s)
}
m.SetText(strings.Join(buff, "\n"))
}
func (m *Meow) bindKeys() {
m.actions.Set(ui.KeyActions{
tcell.KeyEscape: ui.NewKeyAction("Back", m.resetCmd, false),
})
}
func (m *Meow) keyboard(evt *tcell.EventKey) *tcell.EventKey {
if a, ok := m.actions[ui.AsKey(evt)]; ok {
return a.Action(evt)
}
return evt
}
// StylesChanged notifies the skin changes.
func (m *Meow) StylesChanged(s *config.Styles) {
m.SetBackgroundColor(m.app.Styles.BgColor())
m.SetTextColor(m.app.Styles.FgColor())
m.SetBorderFocusColor(m.app.Styles.Frame().Border.FocusColor.Color())
}
func (m *Meow) resetCmd(evt *tcell.EventKey) *tcell.EventKey {
return m.app.PrevCmd(evt)
}
// Actions returns menu actions
func (m *Meow) Actions() ui.KeyActions {
return m.actions
}
// Name returns the component name.
func (m *Meow) Name() string { return "cow" }
// Start starts the view updater.
func (m *Meow) Start() {}
// Stop terminates the updater.
func (m *Meow) Stop() {
m.app.Styles.RemoveListener(m)
}
// Hints returns menu hints.
func (m *Meow) Hints() model.MenuHints {
return m.actions.Hints()
}
// ExtraHints returns additional hints.
func (m *Meow) ExtraHints() map[string]string {
return nil
}
func (m *Meow) updateTitle() {
m.SetTitle(" Error ")
}
var cow = []string{
`\ ^__^ `,
` \ (oo)\_______ `,
` (__)\ )\/\`,
` ||----w | `,
` || || `,
}