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

Prompt window uses border styles #2136

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
19 changes: 2 additions & 17 deletions internal/ui/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ func NewPrompt(app *App, noIcons bool, styles *config.Styles) *Prompt {
p.SetDynamicColors(true)
p.SetBorder(true)
p.SetBorderPadding(0, 0, 1, 1)
p.SetBackgroundColor(styles.K9s.Prompt.BgColor.Color())
p.SetTextColor(styles.K9s.Prompt.FgColor.Color())
p.StylesChanged(p.styles)
styles.AddListener(&p)
p.SetInputCapture(p.keyboard)

Expand Down Expand Up @@ -169,6 +168,7 @@ func (p *Prompt) keyboard(evt *tcell.EventKey) *tcell.EventKey {
// StylesChanged notifies skin changed.
func (p *Prompt) StylesChanged(s *config.Styles) {
p.styles = s
p.SetBorderColor(s.Frame().Border.FgColor.Color().TrueColor())
p.SetBackgroundColor(s.K9s.Prompt.BgColor.Color())
p.SetTextColor(s.K9s.Prompt.FgColor.Color())
}
Expand Down Expand Up @@ -230,8 +230,6 @@ func (p *Prompt) BufferActive(activate bool, kind model.BufferKind) {
if activate {
p.ShowCursor(true)
p.SetBorder(true)
p.SetTextColor(p.styles.FgColor())
p.SetBorderColor(colorFor(kind))
p.icon = p.iconFor(kind)
p.activate()
return
Expand All @@ -256,16 +254,3 @@ func (p *Prompt) iconFor(k model.BufferKind) rune {
return '🐩'
}
}

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

func colorFor(k model.BufferKind) tcell.Color {
// nolint:exhaustive
switch k {
case model.CommandBuffer:
return tcell.ColorAqua
default:
return tcell.ColorSeaGreen
}
}
30 changes: 30 additions & 0 deletions internal/ui/prompt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,33 @@ func TestCmdMode(t *testing.T) {
assert.Equal(t, f, v.InCmdMode())
}
}

func TestPromptStylesChanged(t *testing.T) {
style := config.NewStyles()
prompt := ui.NewPrompt(nil, true, style)

// Check that the style is respected when the prompt is created
assert.Equal(t, prompt.TextView.Box.GetBorderColor(), style.Frame().Border.FgColor.Color().TrueColor())
assert.Equal(t, prompt.TextView.Box.GetBackgroundColor(), style.K9s.Prompt.BgColor.Color())

// Create a new style with a different border and background color
newStyle := config.NewStyles()
newStyle.K9s.Frame.Border = config.Border{
FgColor: "red",
FocusColor: "red",
}
newStyle.K9s.Prompt = config.Prompt {
FgColor: "red",
BgColor: "red",
SuggestColor: "red",
}

// Make sure the new style is different from the first one
assert.NotEqual(t, style.Frame().Border.FgColor.Color().TrueColor(), newStyle.Frame().Border.FgColor.Color().TrueColor())
assert.NotEqual(t, style.K9s.Prompt.BgColor.Color(), newStyle.K9s.Prompt.BgColor.Color())

prompt.StylesChanged(newStyle)

assert.Equal(t, prompt.TextView.Box.GetBorderColor(), newStyle.Frame().Border.FgColor.Color().TrueColor())
assert.Equal(t, prompt.TextView.Box.GetBackgroundColor(), newStyle.K9s.Prompt.BgColor.Color())
}