Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add indicator to title if toast is toggled #2119

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ k9s:
highlightColor: skyblue
counterColor: slateblue
filterColor: slategray
toastIndicator: "!",
views:
# TableView attributes.
table:
Expand Down
15 changes: 10 additions & 5 deletions internal/config/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type (
// Color represents a color.
Color string

// Indicator represent a string or emoji.
Indicator string

// Colors tracks multiple colors.
Colors []Color

Expand Down Expand Up @@ -136,11 +139,12 @@ type (

// Title tracks title styles.
Title struct {
FgColor Color `yaml:"fgColor"`
BgColor Color `yaml:"bgColor"`
HighlightColor Color `yaml:"highlightColor"`
CounterColor Color `yaml:"counterColor"`
FilterColor Color `yaml:"filterColor"`
FgColor Color `yaml:"fgColor"`
BgColor Color `yaml:"bgColor"`
HighlightColor Color `yaml:"highlightColor"`
CounterColor Color `yaml:"counterColor"`
FilterColor Color `yaml:"filterColor"`
ToastIndicator Indicator `yaml:"toastIndicator"`
}

// Info tracks info styles.
Expand Down Expand Up @@ -391,6 +395,7 @@ func newTitle() Title {
HighlightColor: "fuchsia",
CounterColor: "papayawhip",
FilterColor: "seagreen",
ToastIndicator: "!",
}
}

Expand Down
6 changes: 6 additions & 0 deletions internal/ui/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,12 @@ func (t *Table) styleTitle() string {
if t.Extras != "" {
ns = t.Extras
}

toastIndicator := t.styles.K9s.Frame.Title.ToastIndicator
if t.toast && toastIndicator != "" {
base = fmt.Sprintf("%s%s", base, toastIndicator)
}

var title string
if ns == client.ClusterScope {
title = SkinTitle(fmt.Sprintf(TitleFmt, base, rc), t.styles.Frame())
Expand Down
19 changes: 19 additions & 0 deletions internal/ui/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ui_test

import (
"context"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -56,6 +57,24 @@ func TestTableSelection(t *testing.T) {
assert.Equal(t, 1, v.GetSelectedRowIndex())
}

func TestToggleToastWithIndicator(t *testing.T) {
v := ui.NewTable(client.NewGVR("fred"))
v.Init(makeContext())
v.SetModel(&mockModel{})

indicator := "Indicator"
v.Styles().K9s.Frame.Title.ToastIndicator = config.Indicator(indicator)
v.Update(makeTableData(), false)

initTitle := v.GetTitle()
expectedTitle := strings.Replace(initTitle, "Fred", "Fred"+indicator, 1)

v.ToggleToast()
assert.Equal(t, expectedTitle, v.GetTitle())
v.ToggleToast()
assert.Equal(t, initTitle, v.GetTitle())
}

// ----------------------------------------------------------------------------
// Helpers...

Expand Down