feat: add a Styler interface for styling bubbles

This change introduces a Styler interface that allows users to define
custom styles for bubbles. The interface is implemented by the StylerFunc
type, which is a function type that takes a boolean argument and returns
a value of any type.

This allows a user to define a custom StylerFunc that returns a custom
style for a bubble based on the background color of the terminal.
This commit is contained in:
Ayman Bagabas
2024-10-29 15:54:40 -04:00
parent db64e3cd78
commit 8fdc81c836
8 changed files with 34 additions and 33 deletions
+4 -13
View File
@@ -41,7 +41,8 @@ type Styles struct {
FullSeparator lipgloss.Style
}
func newStyles(isDark bool) Styles {
// DefaultStyles returns a set of default styles for the help bubble.
func DefaultStyles(isDark bool) Styles {
lightDark := lipgloss.LightDark(isDark)
keyStyle := lipgloss.NewStyle().Foreground(lightDark("#909090", "#626262"))
@@ -59,16 +60,6 @@ func newStyles(isDark bool) Styles {
}
}
// DefaultDarkStyles returns a set of default styles for dark backgrounds.
func DefaultDarkStyles() Styles {
return newStyles(true)
}
// DefaultLightStyles returns a set of default styles for light backgrounds.
func DefaultLightStyles() Styles {
return newStyles(false)
}
// Model contains the state of the help view.
type Model struct {
Width int
@@ -85,12 +76,12 @@ type Model struct {
}
// New creates a new help view with some useful defaults.
func New() Model {
func New(isDark bool) Model {
return Model{
ShortSeparator: " • ",
FullSeparator: " ",
Ellipsis: "…",
Styles: DefaultDarkStyles(),
Styles: DefaultStyles(isDark),
}
}
+1 -1
View File
@@ -10,7 +10,7 @@ import (
)
func TestFullHelp(t *testing.T) {
m := New()
m := New(true)
m.FullSeparator = " | "
k := key.WithKeys("x")
kb := [][]key.Binding{