From 6b27c911680e3ae6abbec429f39c774e1c425600 Mon Sep 17 00:00:00 2001 From: Emeric MARTINEAU <11473190+emeric-martineau@users.noreply.github.com> Date: Thu, 1 Oct 2020 14:17:03 +0200 Subject: [PATCH] Fix #374 allow remove crumbs --- README.md | 2 ++ cmd/root.go | 6 ++++++ internal/config/flags.go | 2 ++ internal/config/k9s.go | 17 +++++++++++++++++ internal/view/app.go | 30 +++++++++++++++++++++++++++++- 5 files changed, 56 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a111676b..1f9bb41e 100644 --- a/README.md +++ b/README.md @@ -242,6 +242,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. diff --git a/cmd/root.go b/cmd/root.go index fcfe28a9..9c5d0966 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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() { diff --git a/internal/config/flags.go b/internal/config/flags.go index 1f79b940..82c762b2 100644 --- a/internal/config/flags.go +++ b/internal/config/flags.go @@ -19,6 +19,7 @@ type Flags struct { Command *string AllNamespaces *bool ReadOnly *bool + Crumbsless *bool } // NewFlags returns new configuration flags. @@ -30,6 +31,7 @@ func NewFlags() *Flags { Command: strPtr(DefaultCommand), AllNamespaces: boolPtr(false), ReadOnly: boolPtr(false), + Crumbsless: boolPtr(false), } } diff --git a/internal/config/k9s.go b/internal/config/k9s.go index dc39c2cb..9c663036 100644 --- a/internal/config/k9s.go +++ b/internal/config/k9s.go @@ -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"` @@ -18,6 +19,7 @@ type K9s struct { Thresholds Threshold `yaml:"thresholds"` manualRefreshRate int manualHeadless *bool + manualCrumbsless *bool manualReadOnly *bool manualCommand *string } @@ -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 @@ -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 diff --git a/internal/view/app.go b/internal/view/app.go index e073f423..f56fb6e1 100644 --- a/internal/view/app.go +++ b/internal/view/app.go @@ -48,6 +48,7 @@ type App struct { filterHistory *model.History conRetry int32 showHeader bool + showCrumbs bool } // NewApp returns a K9s app instance. @@ -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() { @@ -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), @@ -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()) @@ -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 {