-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
picker.go
76 lines (62 loc) · 1.52 KB
/
picker.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
package view
import (
"context"
"github.com/derailed/k9s/internal/model"
"github.com/derailed/k9s/internal/ui"
"github.com/derailed/tview"
"github.com/gdamore/tcell"
)
// Picker represents a container picker.
type Picker struct {
*tview.List
actions ui.KeyActions
}
// NewPicker returns a new picker.
func NewPicker() *Picker {
return &Picker{
List: tview.NewList(),
actions: ui.KeyActions{},
}
}
// Init initializes the view.
func (p *Picker) Init(ctx context.Context) error {
app, err := extractApp(ctx)
if err != nil {
return err
}
p.actions[tcell.KeyEscape] = ui.NewKeyAction("Back", app.PrevCmd, true)
p.SetBorder(true)
p.SetMainTextColor(tcell.ColorWhite)
p.ShowSecondaryText(false)
p.SetShortcutColor(tcell.ColorAqua)
p.SetSelectedBackgroundColor(tcell.ColorAqua)
p.SetTitle(" [aqua::b]Containers Picker ")
p.SetInputCapture(func(evt *tcell.EventKey) *tcell.EventKey {
if a, ok := p.actions[evt.Key()]; ok {
a.Action(evt)
evt = nil
}
return evt
})
return nil
}
// Start starts the view.
func (p *Picker) Start() {}
// Stop stops the view.
func (p *Picker) Stop() {}
// Name returns the component name.
func (p *Picker) Name() string { return "picker" }
// Hints returns the view hints.
func (p *Picker) Hints() model.MenuHints {
return p.actions.Hints()
}
// ExtraHints returns additional hints.
func (p *Picker) ExtraHints() map[string]string {
return nil
}
func (p *Picker) populate(ss []string) {
p.Clear()
for i, s := range ss {
p.AddItem(s, "Select a container", rune('a'+i), nil)
}
}