forked from derailed/k9s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
screen_dump.go
53 lines (45 loc) · 1.51 KB
/
screen_dump.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
package view
import (
"context"
"errors"
"path/filepath"
"github.com/derailed/k9s/internal"
"github.com/derailed/k9s/internal/client"
"github.com/derailed/k9s/internal/config"
"github.com/derailed/k9s/internal/render"
"github.com/derailed/k9s/internal/ui"
"github.com/gdamore/tcell/v2"
"github.com/rs/zerolog/log"
)
// ScreenDump presents a directory listing viewer.
type ScreenDump struct {
ResourceViewer
}
// NewScreenDump returns a new viewer.
func NewScreenDump(gvr client.GVR) ResourceViewer {
s := ScreenDump{
ResourceViewer: NewBrowser(gvr),
}
s.GetTable().SetBorderFocusColor(tcell.ColorSteelBlue)
s.GetTable().SetSelectedStyle(tcell.StyleDefault.Foreground(tcell.ColorWhite).Background(tcell.ColorRoyalBlue).Attributes(tcell.AttrNone))
s.GetTable().SetColorerFn(render.ScreenDump{}.ColorerFunc())
s.GetTable().SetSortCol(ageCol, true)
s.GetTable().SelectRow(1, true)
s.GetTable().SetEnterFn(s.edit)
s.SetContextFn(s.dirContext)
return &s
}
func (s *ScreenDump) dirContext(ctx context.Context) context.Context {
dir := filepath.Join(config.K9sDumpDir, s.App().Config.K9s.CurrentCluster)
log.Debug().Msgf("SD-DIR %q", dir)
config.EnsureFullPath(dir, config.DefaultDirMod)
return context.WithValue(ctx, internal.KeyDir, dir)
}
func (s *ScreenDump) edit(app *App, model ui.Tabular, gvr, path string) {
log.Debug().Msgf("ScreenDump selection is %q", path)
s.Stop()
defer s.Start()
if !edit(app, shellOpts{clear: true, args: []string{path}}) {
app.Flash().Err(errors.New("Failed to launch editor"))
}
}