mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-16 01:43:21 +00:00
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:
+4
-13
@@ -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
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func TestFullHelp(t *testing.T) {
|
||||
m := New()
|
||||
m := New(true)
|
||||
m.FullSeparator = " | "
|
||||
k := key.WithKeys("x")
|
||||
kb := [][]key.Binding{
|
||||
|
||||
Reference in New Issue
Block a user