mirror of
https://github.com/Maks1mS/bubbles.git
synced 2024-12-24 14:44:38 +03:00
Just set the color profile on the package level
This commit is contained in:
parent
f4a59f7bc3
commit
9225516bf4
@ -8,6 +8,11 @@ import (
|
||||
"github.com/muesli/termenv"
|
||||
)
|
||||
|
||||
var (
|
||||
// Helper for returning colors
|
||||
color func(s string) termenv.Color = termenv.ColorProfile().Color
|
||||
)
|
||||
|
||||
type Model struct {
|
||||
Prompt string
|
||||
Value string
|
||||
@ -24,7 +29,6 @@ type Model struct {
|
||||
|
||||
blink bool
|
||||
pos int
|
||||
colorProfile termenv.Profile
|
||||
}
|
||||
|
||||
// Focused returns the focus state on the model
|
||||
@ -52,7 +56,16 @@ func (m *Model) Blur() {
|
||||
func (m *Model) colorText(s string) string {
|
||||
return termenv.
|
||||
String(s).
|
||||
Foreground(m.colorProfile.Color(m.TextColor)).
|
||||
Foreground(color(m.TextColor)).
|
||||
String()
|
||||
}
|
||||
|
||||
// colorPlaceholder colorizes a given string according to the TextColor value
|
||||
// of the model
|
||||
func (m *Model) colorPlaceholder(s string) string {
|
||||
return termenv.
|
||||
String(s).
|
||||
Foreground(color(m.PlaceholderColor)).
|
||||
String()
|
||||
}
|
||||
|
||||
@ -71,7 +84,6 @@ func DefaultModel() Model {
|
||||
focus: false,
|
||||
blink: true,
|
||||
pos: 0,
|
||||
colorProfile: termenv.ColorProfile(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -166,16 +178,12 @@ func placeholderView(m Model) string {
|
||||
var (
|
||||
v string
|
||||
p = m.Placeholder
|
||||
c = m.PlaceholderColor
|
||||
color = m.colorProfile.Color
|
||||
)
|
||||
|
||||
// Cursor
|
||||
if m.blink && m.PlaceholderColor != "" {
|
||||
v += cursorView(
|
||||
termenv.String(p[:1]).
|
||||
Foreground(color(c)).
|
||||
String(),
|
||||
m.colorPlaceholder(p[:1]),
|
||||
m,
|
||||
)
|
||||
} else {
|
||||
@ -183,9 +191,7 @@ func placeholderView(m Model) string {
|
||||
}
|
||||
|
||||
// The rest of the palceholder text
|
||||
v += termenv.String(p[1:]).
|
||||
Foreground(color(c)).
|
||||
String()
|
||||
v += m.colorPlaceholder(p[1:])
|
||||
|
||||
return m.Prompt + v
|
||||
}
|
||||
@ -196,7 +202,7 @@ func cursorView(s string, m Model) string {
|
||||
return s
|
||||
} else {
|
||||
return termenv.String(s).
|
||||
Foreground(m.colorProfile.Color(m.CursorColor)).
|
||||
Foreground(color(m.CursorColor)).
|
||||
Reverse().
|
||||
String()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user