Improve NoColor primative

This commit is contained in:
Christian Rocha 2021-03-18 14:34:39 -04:00
parent 1498fd3b6b
commit 552799ac29
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018
3 changed files with 12 additions and 12 deletions

View File

@ -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
View File

@ -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 {

View File

@ -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 {