/
dir.go
69 lines (56 loc) · 1.36 KB
/
dir.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
package render
import (
"fmt"
"os"
"github.com/gdamore/tcell/v2"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
// Dir renders a directory entry to screen.
type Dir struct{}
// IsGeneric identifies a generic handler.
func (Dir) IsGeneric() bool {
return false
}
// ColorerFunc colors a resource row.
func (Dir) ColorerFunc() ColorerFunc {
return func(ns string, _ Header, re RowEvent) tcell.Color {
return tcell.ColorCadetBlue
}
}
// Header returns a header row.
func (Dir) Header(ns string) Header {
return Header{
HeaderColumn{Name: "NAME"},
}
}
// Render renders a K8s resource to screen.
// BOZO!! Pass in a row with pre-alloc fields??
func (Dir) Render(o interface{}, ns string, r *Row) error {
d, ok := o.(DirRes)
if !ok {
return fmt.Errorf("expected DirRes, but got %T", o)
}
name := "🦄 "
if d.Entry.IsDir() {
name = "📁 "
}
name += d.Entry.Name()
r.ID, r.Fields = d.Path, append(r.Fields, name)
return nil
}
// ----------------------------------------------------------------------------
// Helpers...
// DirRes represents an alias resource.
type DirRes struct {
Entry os.DirEntry
Path string
}
// GetObjectKind returns a schema object.
func (DirRes) GetObjectKind() schema.ObjectKind {
return nil
}
// DeepCopyObject returns a container copy.
func (d DirRes) DeepCopyObject() runtime.Object {
return d
}