-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
types.go
131 lines (99 loc) · 2.81 KB
/
types.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
package view
import (
"context"
"github.com/derailed/k9s/internal/client"
"github.com/derailed/k9s/internal/model"
"github.com/derailed/k9s/internal/ui"
)
const (
ageCol = "AGE"
nameCol = "NAME"
statusCol = "STATUS"
cpuCol = "CPU"
memCol = "MEM"
uptodateCol = "UP-TO-DATE"
readyCol = "READY"
availCol = "AVAILABLE"
)
type (
// EnvFunc represent the current view exposed environment.
EnvFunc func() Env
// BoostActionsFunc extends viewer keyboard actions.
BoostActionsFunc func(ui.KeyActions)
// EnterFunc represents an enter key action.
EnterFunc func(app *App, model ui.Tabular, gvr, path string)
// ContainerFunc returns the active container name.
ContainerFunc func() string
// ContextFunc enhances a given context.
ContextFunc func(context.Context) context.Context
// BindKeysFunc adds new menu actions.
BindKeysFunc func(ui.KeyActions)
)
// ActionExtender enhances a given viewer by adding new menu actions.
type ActionExtender interface {
// BindKeys injects new menu actions.
BindKeys(ResourceViewer)
}
// Hinter represents a view that can produce menu hints.
type Hinter interface {
// Hints returns a collection of hints.
Hints() model.MenuHints
}
// Viewer represents a component viewer.
type Viewer interface {
model.Component
// Actions returns active menu bindings.
Actions() ui.KeyActions
// App returns an app handle.
App() *App
// Refresh updates the viewer
Refresh()
}
// TableViewer represents a tabular viewer.
type TableViewer interface {
Viewer
// Table returns a table component.
GetTable() *Table
}
// ResourceViewer represents a generic resource viewer.
type ResourceViewer interface {
TableViewer
// SetEnvFn sets a function to pull viewer env vars for plugins.
SetEnvFn(EnvFunc)
// GVR returns a resource descriptor.
GVR() client.GVR
// SetContextFn provision a custom context.
SetContextFn(ContextFunc)
// SetBindKeys provision additional key bindings.
SetBindKeysFn(BindKeysFunc)
// SetInstance sets a parent FQN
SetInstance(string)
}
// LogViewer represents a log viewer.
type LogViewer interface {
ResourceViewer
ShowLogs(prev bool)
}
// RestartableViewer represents a viewer with restartable resources.
type RestartableViewer interface {
LogViewer
}
// ScalableViewer represents a viewer with scalable resources.
type ScalableViewer interface {
LogViewer
}
// SubjectViewer represents a policy viewer.
type SubjectViewer interface {
ResourceViewer
// SetSubject sets the active subject.
SetSubject(s string)
}
// ViewerFunc returns a viewer matching a given gvr.
type ViewerFunc func(client.GVR) ResourceViewer
// MetaViewer represents a registered meta viewer.
type MetaViewer struct {
viewerFn ViewerFunc
enterFn EnterFunc
}
// MetaViewers represents a collection of meta viewers.
type MetaViewers map[client.GVR]MetaViewer