Rename ColorType to TerminalColor

This commit is contained in:
Christian Rocha 2021-03-30 22:19:38 -04:00
parent 8a4bf146ce
commit 9b77d4607b
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018
5 changed files with 21 additions and 21 deletions

View File

@ -219,7 +219,7 @@ func renderHorizontalEdge(left, middle, right string, width int) string {
} }
// Apply foreground and background styling to a border. // Apply foreground and background styling to a border.
func styleBorder(border string, fg, bg ColorType) string { func styleBorder(border string, fg, bg TerminalColor) string {
if fg == noColor && bg == noColor { if fg == noColor && bg == noColor {
return border return border
} }

View File

@ -10,8 +10,8 @@ var (
hasDarkBackground bool = termenv.HasDarkBackground() hasDarkBackground bool = termenv.HasDarkBackground()
) )
// ColorType is an interface used in color specifications. // TerminalColor is a color intended to be rendered in the terminal.
type ColorType interface { type TerminalColor interface {
value() string value() string
color() termenv.Color color() termenv.Color
} }

4
get.go
View File

@ -23,12 +23,12 @@ func (s Style) getAsBool(k propKey, defaultVal bool) bool {
return defaultVal return defaultVal
} }
func (s Style) getAsColor(k propKey) ColorType { func (s Style) getAsColor(k propKey) TerminalColor {
v, ok := s.rules[k] v, ok := s.rules[k]
if !ok { if !ok {
return NoColor{} return NoColor{}
} }
if c, ok := v.(ColorType); ok { if c, ok := v.(TerminalColor); ok {
return c return c
} }
return NoColor{} return NoColor{}

28
set.go
View File

@ -79,13 +79,13 @@ func (s Style) Faint(v bool) Style {
// // Removes the foreground color // // Removes the foreground color
// s.Foreground(lipgloss.NoColor) // s.Foreground(lipgloss.NoColor)
// //
func (s Style) Foreground(c ColorType) Style { func (s Style) Foreground(c TerminalColor) Style {
s.set(foregroundKey, c) s.set(foregroundKey, c)
return s return s
} }
// Background sets a background color. // Background sets a background color.
func (s Style) Background(c ColorType) Style { func (s Style) Background(c TerminalColor) Style {
s.set(backgroundKey, c) s.set(backgroundKey, c)
return s return s
} }
@ -222,7 +222,7 @@ func (s Style) MarginBottom(i int) Style {
return s return s
} }
func (s Style) marginBackground(c ColorType) Style { func (s Style) marginBackground(c TerminalColor) Style {
s.set(marginBackgroundKey, c) s.set(marginBackgroundKey, c)
return s return s
} }
@ -328,7 +328,7 @@ func (s Style) BorderLeft(v bool) Style {
// top side, followed by the right side, then the bottom, and finally the left. // top side, followed by the right side, then the bottom, and finally the left.
// //
// With more than four arguments nothing will be set. // With more than four arguments nothing will be set.
func (s Style) BorderForegroundColor(c ...ColorType) Style { func (s Style) BorderForegroundColor(c ...TerminalColor) Style {
if len(c) == 0 { if len(c) == 0 {
return s return s
} }
@ -347,25 +347,25 @@ func (s Style) BorderForegroundColor(c ...ColorType) Style {
} }
// BorderTopForegroundColor set the top color of the border. // BorderTopForegroundColor set the top color of the border.
func (s Style) BorderTopForegroundColor(c ColorType) Style { func (s Style) BorderTopForegroundColor(c TerminalColor) Style {
s.set(borderTopFGColorKey, c) s.set(borderTopFGColorKey, c)
return s return s
} }
// BorderRightForegroundColor set the top color of the border. // BorderRightForegroundColor set the top color of the border.
func (s Style) BorderRightForegroundColor(c ColorType) Style { func (s Style) BorderRightForegroundColor(c TerminalColor) Style {
s.set(borderRightFGColorKey, c) s.set(borderRightFGColorKey, c)
return s return s
} }
// BorderBottomForegroundColor set the top color of the border. // BorderBottomForegroundColor set the top color of the border.
func (s Style) BorderBottomForegroundColor(c ColorType) Style { func (s Style) BorderBottomForegroundColor(c TerminalColor) Style {
s.set(borderBottomFGColorKey, c) s.set(borderBottomFGColorKey, c)
return s return s
} }
// BorderLeftForegroundColor set the top color of the border. // BorderLeftForegroundColor set the top color of the border.
func (s Style) BorderLeftForegroundColor(c ColorType) Style { func (s Style) BorderLeftForegroundColor(c TerminalColor) Style {
s.set(borderLeftFGColorKey, c) s.set(borderLeftFGColorKey, c)
return s return s
} }
@ -385,7 +385,7 @@ func (s Style) BorderLeftForegroundColor(c ColorType) Style {
// top side, followed by the right side, then the bottom, and finally the left. // top side, followed by the right side, then the bottom, and finally the left.
// //
// With more than four arguments nothing will be set. // With more than four arguments nothing will be set.
func (s Style) BorderBackgroundColor(c ...ColorType) Style { func (s Style) BorderBackgroundColor(c ...TerminalColor) Style {
if len(c) == 0 { if len(c) == 0 {
return s return s
} }
@ -404,25 +404,25 @@ func (s Style) BorderBackgroundColor(c ...ColorType) Style {
} }
// BorderTopBackgroundColor set the top color of the border. // BorderTopBackgroundColor set the top color of the border.
func (s Style) BorderTopBackgroundColor(c ColorType) Style { func (s Style) BorderTopBackgroundColor(c TerminalColor) Style {
s.set(borderTopBGColorKey, c) s.set(borderTopBGColorKey, c)
return s return s
} }
// BorderRightBackgroundColor set the top color of the border. // BorderRightBackgroundColor set the top color of the border.
func (s Style) BorderRightBackgroundColor(c ColorType) Style { func (s Style) BorderRightBackgroundColor(c TerminalColor) Style {
s.set(borderRightBGColorKey, c) s.set(borderRightBGColorKey, c)
return s return s
} }
// BorderBottomBackgroundColor set the top color of the border. // BorderBottomBackgroundColor set the top color of the border.
func (s Style) BorderBottomBackgroundColor(c ColorType) Style { func (s Style) BorderBottomBackgroundColor(c TerminalColor) Style {
s.set(borderBottomBGColorKey, c) s.set(borderBottomBGColorKey, c)
return s return s
} }
// BorderLeftBackgroundColor set the top color of the border. // BorderLeftBackgroundColor set the top color of the border.
func (s Style) BorderLeftBackgroundColor(c ColorType) Style { func (s Style) BorderLeftBackgroundColor(c TerminalColor) Style {
s.set(borderLeftBGColorKey, c) s.set(borderLeftBGColorKey, c)
return s return s
} }
@ -569,7 +569,7 @@ func whichSidesBool(i ...bool) (top, right, bottom, left bool, ok bool) {
// whichSidesColor is like whichSides, except it operates on a series of // whichSidesColor is like whichSides, except it operates on a series of
// boolean values. See the comment on whichSidesInt for details on how this // boolean values. See the comment on whichSidesInt for details on how this
// works. // works.
func whichSidesColor(i ...ColorType) (top, right, bottom, left ColorType, ok bool) { func whichSidesColor(i ...TerminalColor) (top, right, bottom, left TerminalColor, ok bool) {
switch len(i) { switch len(i) {
case 1: case 1:
top = i[0] top = i[0]

View File

@ -47,14 +47,14 @@ func (w whitespace) render(width int) string {
type WhitespaceOption func(*whitespace) type WhitespaceOption func(*whitespace)
// WithWhitespaceForeground sets the color of the characters in the whitespace. // WithWhitespaceForeground sets the color of the characters in the whitespace.
func WithWhitespaceForeground(c ColorType) WhitespaceOption { func WithWhitespaceForeground(c TerminalColor) WhitespaceOption {
return func(w *whitespace) { return func(w *whitespace) {
w.style = w.style.Foreground(c.color()) w.style = w.style.Foreground(c.color())
} }
} }
// WithWhiteSpaceBackground sets the background color of the whitespace. // WithWhiteSpaceBackground sets the background color of the whitespace.
func WithWhitespaceBackground(c ColorType) WhitespaceOption { func WithWhitespaceBackground(c TerminalColor) WhitespaceOption {
return func(w *whitespace) { return func(w *whitespace) {
w.style = w.style.Background(c.color()) w.style = w.style.Background(c.color())
} }