Skip to content

Commit

Permalink
refactor(compat): accept any and use lipgloss.Color
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Nov 5, 2024
1 parent a89b24a commit 7cdc043
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions compat/color.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package compat

import (
"image/color"
"os"

"github.com/charmbracelet/colorprofile"
Expand All @@ -27,37 +26,37 @@ var (
//
// color := lipgloss.AdaptiveColor{Light: "#0000ff", Dark: "#000099"}
type AdaptiveColor struct {
Light color.Color
Dark color.Color
Light any
Dark any
}

// RGBA returns the RGBA value of this color. This satisfies the Go Color
// interface.
func (c AdaptiveColor) RGBA() (uint32, uint32, uint32, uint32) {
if HasDarkBackground {
return c.Dark.RGBA()
return lipgloss.Color(c.Dark).RGBA()
}
return c.Light.RGBA()
return lipgloss.Color(c.Light).RGBA()
}

// CompleteColor specifies exact values for truecolor, ANSI256, and ANSI color
// profiles. Automatic color degradation will not be performed.
type CompleteColor struct {
TrueColor color.Color
ANSI256 color.Color
ANSI color.Color
TrueColor any
ANSI256 any
ANSI any
}

// RGBA returns the RGBA value of this color. This satisfies the Go Color
// interface.
func (c CompleteColor) RGBA() (uint32, uint32, uint32, uint32) {
switch Profile {

Check failure on line 53 in compat/color.go

View workflow job for this annotation

GitHub Actions / lint / lint-soft (ubuntu-latest)

missing cases in switch of type colorprofile.Profile: colorprofile.Ascii, colorprofile.NoTTY (exhaustive)

Check failure on line 53 in compat/color.go

View workflow job for this annotation

GitHub Actions / lint / lint-soft (macos-latest)

missing cases in switch of type colorprofile.Profile: colorprofile.Ascii, colorprofile.NoTTY (exhaustive)

Check failure on line 53 in compat/color.go

View workflow job for this annotation

GitHub Actions / lint / lint-soft (windows-latest)

missing cases in switch of type colorprofile.Profile: colorprofile.Ascii, colorprofile.NoTTY (exhaustive)

Check failure on line 53 in compat/color.go

View workflow job for this annotation

GitHub Actions / lint / lint-soft (ubuntu-latest)

missing cases in switch of type colorprofile.Profile: colorprofile.Ascii, colorprofile.NoTTY (exhaustive)

Check failure on line 53 in compat/color.go

View workflow job for this annotation

GitHub Actions / lint / lint-soft (macos-latest)

missing cases in switch of type colorprofile.Profile: colorprofile.Ascii, colorprofile.NoTTY (exhaustive)

Check failure on line 53 in compat/color.go

View workflow job for this annotation

GitHub Actions / lint / lint-soft (windows-latest)

missing cases in switch of type colorprofile.Profile: colorprofile.Ascii, colorprofile.NoTTY (exhaustive)
case colorprofile.TrueColor:
return c.TrueColor.RGBA()
return lipgloss.Color(c.TrueColor).RGBA()
case colorprofile.ANSI256:
return c.ANSI256.RGBA()
return lipgloss.Color(c.ANSI256).RGBA()
case colorprofile.ANSI:
return c.ANSI.RGBA()
return lipgloss.Color(c.ANSI).RGBA()
}
return lipgloss.NoColor{}.RGBA()
}
Expand Down

0 comments on commit 7cdc043

Please sign in to comment.