From 86ccf9b18fdecb5f56d07591009071b8e4abc659 Mon Sep 17 00:00:00 2001 From: derailed Date: Mon, 30 Dec 2019 15:28:28 -0700 Subject: [PATCH] cleaning up --- internal/ui/key.go | 5 ++++- internal/ui/table.go | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/internal/ui/key.go b/internal/ui/key.go index 4bbed4f4..d726f739 100644 --- a/internal/ui/key.go +++ b/internal/ui/key.go @@ -14,6 +14,7 @@ func initKeys() { initNumbKeys() initStdKeys() initShiftKeys() + initShiftNumKeys() } // Defines numeric keys for container actions @@ -164,7 +165,7 @@ func initStdKeys() { tcell.KeyNames[tcell.Key(KeyZ)] = "z" } -func initShiftKeys() { +func initShiftNumKeys() { tcell.KeyNames[tcell.Key(KeyShift0)] = "Shift-0" tcell.KeyNames[tcell.Key(KeyShift1)] = "Shift-1" tcell.KeyNames[tcell.Key(KeyShift2)] = "Shift-2" @@ -175,7 +176,9 @@ func initShiftKeys() { tcell.KeyNames[tcell.Key(KeyShift7)] = "Shift-7" tcell.KeyNames[tcell.Key(KeyShift8)] = "Shift-8" tcell.KeyNames[tcell.Key(KeyShift9)] = "Shift-9" +} +func initShiftKeys() { tcell.KeyNames[tcell.Key(KeyShiftA)] = "Shift-A" tcell.KeyNames[tcell.Key(KeyShiftB)] = "Shift-B" tcell.KeyNames[tcell.Key(KeyShiftC)] = "Shift-C" diff --git a/internal/ui/table.go b/internal/ui/table.go index 5ee6e56b..3699874b 100644 --- a/internal/ui/table.go +++ b/internal/ui/table.go @@ -3,6 +3,8 @@ package ui import ( "context" "errors" + "fmt" + "strings" "github.com/derailed/k9s/internal/config" "github.com/derailed/k9s/internal/model" @@ -340,9 +342,46 @@ func (t *Table) ShowDeleted() { // UpdateTitle refreshes the table title. func (t *Table) UpdateTitle() { + t.SetTitle(t.styleTitle()) +} + +// UpdateTitle refreshes the table title. +func (t *Table) styleTitle() string { ns := t.GetModel().GetNamespace() if ns == render.AllNamespaces { ns = render.NamespaceAll } - t.SetTitle(styleTitle(t.GetRowCount(), ns, t.BaseTitle, t.Path, t.cmdBuff.String(), t.styles)) + rc := t.GetRowCount() + if rc > 0 { + rc-- + } + + base, path := strings.Title(t.BaseTitle), t.Path + if ns == render.AllNamespaces { + ns = render.NamespaceAll + } + info := ns + if path != "" { + info = path + cns, n := render.Namespaced(path) + if cns == render.ClusterScope { + info = n + } + } + + buff := t.SearchBuff().String() + var title string + if info == "" || info == render.ClusterScope { + title = SkinTitle(fmt.Sprintf(titleFmt, base, rc), t.styles.Frame()) + } else { + title = SkinTitle(fmt.Sprintf(nsTitleFmt, base, info, rc), t.styles.Frame()) + } + if buff == "" { + return title + } + + if IsLabelSelector(buff) { + buff = TrimLabelSelector(buff) + } + return title + SkinTitle(fmt.Sprintf(SearchFmt, buff), t.styles.Frame()) }