mirror of
https://github.com/charmbracelet/lipgloss.git
synced 2024-08-17 01:40:36 +03:00
Improve NoColor primative
This commit is contained in:
parent
1498fd3b6b
commit
552799ac29
16
color.go
16
color.go
@ -23,20 +23,20 @@ type ColorType interface {
|
||||
//
|
||||
// Example usage:
|
||||
//
|
||||
// color := NoColor
|
||||
// var style = someStyle.Copy().Background(lipgloss.NoColor{})
|
||||
//
|
||||
var NoColor = noColor{}
|
||||
type NoColor struct{}
|
||||
|
||||
type noColor struct{}
|
||||
|
||||
func (n noColor) value() string {
|
||||
func (n NoColor) value() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
var noColor = NoColor{}
|
||||
|
||||
// Color specifies a color by hex or ANSI value. For example:
|
||||
//
|
||||
// ansiColor := Color("21")
|
||||
// hexColor := Color("#0000ff")
|
||||
// ansiColor := lipgloss.Color("21")
|
||||
// hexColor := lipgloss.Color("#0000ff")
|
||||
//
|
||||
type Color string
|
||||
|
||||
@ -50,7 +50,7 @@ func (c Color) value() string {
|
||||
//
|
||||
// Example usage:
|
||||
//
|
||||
// color := AdaptiveColor{Light: "#0000ff", Dark: "#000099"}
|
||||
// color := lipgloss.AdaptiveColor{Light: "#0000ff", Dark: "#000099"}
|
||||
//
|
||||
type AdaptiveColor struct {
|
||||
Light string
|
||||
|
4
get.go
4
get.go
@ -20,12 +20,12 @@ func (s Style) getAsBool(k propKey, defaultVal bool) bool {
|
||||
func (s Style) getAsColor(k propKey) ColorType {
|
||||
v, ok := s.rules[k]
|
||||
if !ok {
|
||||
return NoColor
|
||||
return NoColor{}
|
||||
}
|
||||
if c, ok := v.(ColorType); ok {
|
||||
return c
|
||||
}
|
||||
return NoColor
|
||||
return NoColor{}
|
||||
}
|
||||
|
||||
func (s Style) getAsInt(k propKey) int {
|
||||
|
4
style.go
4
style.go
@ -179,7 +179,7 @@ func (s Style) Render(str string) string {
|
||||
te = te.Faint()
|
||||
}
|
||||
|
||||
if fg != NoColor {
|
||||
if fg != noColor {
|
||||
fgc := color(fg.value())
|
||||
te = te.Foreground(fgc)
|
||||
te.Foreground(fgc)
|
||||
@ -191,7 +191,7 @@ func (s Style) Render(str string) string {
|
||||
}
|
||||
}
|
||||
|
||||
if bg != NoColor {
|
||||
if bg != noColor {
|
||||
bgc := color(bg.value())
|
||||
te = te.Background(bgc)
|
||||
if colorWhitespace {
|
||||
|
Loading…
Reference in New Issue
Block a user