Skip to content

Commit

Permalink
Merge pull request derailed#896 from emeric-martineau/master
Browse files Browse the repository at this point in the history
Fix derailed#374 allow remove crumbs
  • Loading branch information
derailed authored Oct 27, 2020
2 parents 19383a2 + 0b67586 commit e78ad92
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ K9s uses aliases to navigate most K8s resources.
enableMouse: false
# Set to true to hide K9s header. Default false
headless: false
# Set to true to hide K9s footer. Default false
crumbsless: false
# Indicates whether modification commands like delete/kill/edit are disabled. Default is false
readOnly: false
# Toggles icons display as not all terminal support these chars.
Expand Down
6 changes: 6 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ func initK9sFlags() {
false,
"Disable all commands that modify the cluster",
)
rootCmd.Flags().BoolVar(
k9sFlags.Crumbsless,
"crumbsless",
false,
"Turn K9s crumbs off",
)
}

func initK8sFlags() {
Expand Down
2 changes: 2 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ var expectedConfig = `k9s:
refreshRate: 100
enableMouse: false
headless: false
crumbsless: false
readOnly: true
noIcons: false
logger:
Expand Down Expand Up @@ -344,6 +345,7 @@ var resetConfig = `k9s:
refreshRate: 2
enableMouse: false
headless: false
crumbsless: false
readOnly: false
noIcons: false
logger:
Expand Down
2 changes: 2 additions & 0 deletions internal/config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Flags struct {
Command *string
AllNamespaces *bool
ReadOnly *bool
Crumbsless *bool
}

// NewFlags returns new configuration flags.
Expand All @@ -30,6 +31,7 @@ func NewFlags() *Flags {
Command: strPtr(DefaultCommand),
AllNamespaces: boolPtr(false),
ReadOnly: boolPtr(false),
Crumbsless: boolPtr(false),
}
}

Expand Down
17 changes: 17 additions & 0 deletions internal/config/k9s.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type K9s struct {
RefreshRate int `yaml:"refreshRate"`
EnableMouse bool `yaml:"enableMouse"`
Headless bool `yaml:"headless"`
Crumbsless bool `yaml:"crumbsless"`
ReadOnly bool `yaml:"readOnly"`
NoIcons bool `yaml:"noIcons"`
Logger *Logger `yaml:"logger"`
Expand All @@ -18,6 +19,7 @@ type K9s struct {
Thresholds Threshold `yaml:"thresholds"`
manualRefreshRate int
manualHeadless *bool
manualCrumbsless *bool
manualReadOnly *bool
manualCommand *string
}
Expand All @@ -42,6 +44,11 @@ func (k *K9s) OverrideHeadless(b bool) {
k.manualHeadless = &b
}

// OverrideCrumbsless set the headlessness manually.
func (k *K9s) OverrideCrumbsless(b bool) {
k.manualCrumbsless = &b
}

// OverrideReadOnly set the readonly mode manually.
func (k *K9s) OverrideReadOnly(b bool) {
k.manualReadOnly = &b
Expand All @@ -62,6 +69,16 @@ func (k *K9s) GetHeadless() bool {
return h
}

// GetCrumbsless returns crumbsless setting.
func (k *K9s) GetCrumbsless() bool {
h := k.Crumbsless
if k.manualCrumbsless != nil && *k.manualCrumbsless {
h = *k.manualCrumbsless
}

return h
}

// GetRefreshRate returns the current refresh rate.
func (k *K9s) GetRefreshRate() int {
rate := k.RefreshRate
Expand Down
30 changes: 29 additions & 1 deletion internal/view/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type App struct {
filterHistory *model.History
conRetry int32
showHeader bool
showCrumbs bool
}

// NewApp returns a K9s app instance.
Expand Down Expand Up @@ -129,12 +130,12 @@ func (a *App) layout(ctx context.Context, version string) {
main := tview.NewFlex().SetDirection(tview.FlexRow)
main.AddItem(a.statusIndicator(), 1, 1, false)
main.AddItem(a.Content, 0, 10, true)
main.AddItem(a.Crumbs(), 1, 1, false)
main.AddItem(flash, 1, 1, false)

a.Main.AddPage("main", main, true, false)
a.Main.AddPage("splash", ui.NewSplash(a.Styles, version), true, true)
a.toggleHeader(!a.Config.K9s.GetHeadless())
a.toggleCrumbs(!a.Config.K9s.GetCrumbsless())
}

func (a *App) initSignals() {
Expand Down Expand Up @@ -186,6 +187,7 @@ func (a *App) keyboard(evt *tcell.EventKey) *tcell.EventKey {
func (a *App) bindKeys() {
a.AddActions(ui.KeyActions{
tcell.KeyCtrlE: ui.NewSharedKeyAction("ToggleHeader", a.toggleHeaderCmd, false),
tcell.KeyCtrlT: ui.NewSharedKeyAction("toggleCrumbs", a.toggleCrumbsCmd, false),
ui.KeyHelp: ui.NewSharedKeyAction("Help", a.helpCmd, false),
tcell.KeyCtrlA: ui.NewSharedKeyAction("Aliases", a.aliasCmd, false),
tcell.KeyEnter: ui.NewKeyAction("Goto", a.gotoCmd, false),
Expand All @@ -212,6 +214,19 @@ func (a *App) toggleHeader(flag bool) {
}
}

func (a *App) toggleCrumbs(flag bool) {
a.showCrumbs = flag
flex, ok := a.Main.GetPrimitive("main").(*tview.Flex)
if !ok {
log.Fatal().Msg("Expecting valid flex view")
}
if a.showCrumbs {
flex.AddItemAtIndex(2, a.Crumbs(), 1, 1, false)
} else {
flex.RemoveItemAtIndex(2)
}
}

func (a *App) buildHeader() tview.Primitive {
header := tview.NewFlex()
header.SetBackgroundColor(a.Styles.BgColor())
Expand Down Expand Up @@ -498,6 +513,19 @@ func (a *App) toggleHeaderCmd(evt *tcell.EventKey) *tcell.EventKey {
return nil
}

func (a *App) toggleCrumbsCmd(evt *tcell.EventKey) *tcell.EventKey {
if a.Prompt().InCmdMode() {
return evt
}

a.QueueUpdateDraw(func() {
a.showCrumbs = !a.showCrumbs
a.toggleCrumbs(a.showCrumbs)
})

return nil
}

func (a *App) gotoCmd(evt *tcell.EventKey) *tcell.EventKey {
if a.CmdBuff().IsActive() && !a.CmdBuff().Empty() {
if err := a.gotoResource(a.GetCmd(), "", true); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/view/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ func TestAppNew(t *testing.T) {
a := view.NewApp(config.NewConfig(ks{}))
a.Init("blee", 10)

assert.Equal(t, 9, len(a.GetActions()))
assert.Equal(t, 10, len(a.GetActions()))
}

0 comments on commit e78ad92

Please sign in to comment.