mirror of
https://github.com/Maks1mS/bubbles.git
synced 2024-12-25 07:04:37 +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"
|
"github.com/muesli/termenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// Helper for returning colors
|
||||||
|
color func(s string) termenv.Color = termenv.ColorProfile().Color
|
||||||
|
)
|
||||||
|
|
||||||
type Model struct {
|
type Model struct {
|
||||||
Prompt string
|
Prompt string
|
||||||
Value string
|
Value string
|
||||||
@ -22,9 +27,8 @@ type Model struct {
|
|||||||
// component. When false, don't blink and ignore keyboard input.
|
// component. When false, don't blink and ignore keyboard input.
|
||||||
focus bool
|
focus bool
|
||||||
|
|
||||||
blink bool
|
blink bool
|
||||||
pos int
|
pos int
|
||||||
colorProfile termenv.Profile
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Focused returns the focus state on the model
|
// Focused returns the focus state on the model
|
||||||
@ -52,7 +56,16 @@ func (m *Model) Blur() {
|
|||||||
func (m *Model) colorText(s string) string {
|
func (m *Model) colorText(s string) string {
|
||||||
return termenv.
|
return termenv.
|
||||||
String(s).
|
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()
|
String()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,10 +81,9 @@ func DefaultModel() Model {
|
|||||||
PlaceholderColor: "240",
|
PlaceholderColor: "240",
|
||||||
CursorColor: "",
|
CursorColor: "",
|
||||||
|
|
||||||
focus: false,
|
focus: false,
|
||||||
blink: true,
|
blink: true,
|
||||||
pos: 0,
|
pos: 0,
|
||||||
colorProfile: termenv.ColorProfile(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,18 +176,14 @@ func View(model tea.Model) string {
|
|||||||
|
|
||||||
func placeholderView(m Model) string {
|
func placeholderView(m Model) string {
|
||||||
var (
|
var (
|
||||||
v string
|
v string
|
||||||
p = m.Placeholder
|
p = m.Placeholder
|
||||||
c = m.PlaceholderColor
|
|
||||||
color = m.colorProfile.Color
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Cursor
|
// Cursor
|
||||||
if m.blink && m.PlaceholderColor != "" {
|
if m.blink && m.PlaceholderColor != "" {
|
||||||
v += cursorView(
|
v += cursorView(
|
||||||
termenv.String(p[:1]).
|
m.colorPlaceholder(p[:1]),
|
||||||
Foreground(color(c)).
|
|
||||||
String(),
|
|
||||||
m,
|
m,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
@ -183,9 +191,7 @@ func placeholderView(m Model) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The rest of the palceholder text
|
// The rest of the palceholder text
|
||||||
v += termenv.String(p[1:]).
|
v += m.colorPlaceholder(p[1:])
|
||||||
Foreground(color(c)).
|
|
||||||
String()
|
|
||||||
|
|
||||||
return m.Prompt + v
|
return m.Prompt + v
|
||||||
}
|
}
|
||||||
@ -196,7 +202,7 @@ func cursorView(s string, m Model) string {
|
|||||||
return s
|
return s
|
||||||
} else {
|
} else {
|
||||||
return termenv.String(s).
|
return termenv.String(s).
|
||||||
Foreground(m.colorProfile.Color(m.CursorColor)).
|
Foreground(color(m.CursorColor)).
|
||||||
Reverse().
|
Reverse().
|
||||||
String()
|
String()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user