@@ -5,7 +5,7 @@ import (
5 "image/color"
5 "image/color"
8− "github.com/lucasb-eyer/go-colorful"
8+ "charm.land/lipgloss/v2"
9 "github.com/rivo/uniseg"
9 "github.com/rivo/uniseg"
@@ -13,12 +13,12 @@ import (
13// rendered with a horizontal gradient foreground from color1 to color2. Each
13// rendered with a horizontal gradient foreground from color1 to color2. Each
14// string in the returned slice corresponds to a grapheme cluster in the input
14// string in the returned slice corresponds to a grapheme cluster in the input
15// string. If bold is true, the rendered strings will be bolded.
15// string. If bold is true, the rendered strings will be bolded.
16−func ForegroundGrad(t *Styles, input string, bold bool, color1, color2 color.Color) []string {
16+func ForegroundGrad(base lipgloss.Style, input string, bold bool, color1, color2 color.Color) []string {
17 if input == "" {
17 if input == "" {
18 return []string{""}
18 return []string{""}
20 if len(input) == 1 {
20 if len(input) == 1 {
21− style := t.Base.Foreground(color1)
21+ style := base.Foreground(color1)
23 style.Bold(true)
23 style.Bold(true)
@@ -30,9 +30,9 @@ func ForegroundGrad(t *Styles, input string, bold bool, color1, color2 color.Col
30 clusters = append(clusters, string(gr.Runes()))
30 clusters = append(clusters, string(gr.Runes()))
33− ramp := blendColors(len(clusters), color1, color2)
33+ ramp := lipgloss.Blend1D(len(clusters), color1, color2)
34 for i, c := range ramp {
34 for i, c := range ramp {
35− style := t.Base.Foreground(c)
35+ style := base.Foreground(c)
37 style.Bold(true)
37 style.Bold(true)
@@ -43,12 +43,12 @@ func ForegroundGrad(t *Styles, input string, bold bool, color1, color2 color.Col
44// ApplyForegroundGrad renders a given string with a horizontal gradient
44// ApplyForegroundGrad renders a given string with a horizontal gradient
45// foreground.
45// foreground.
46−func ApplyForegroundGrad(t *Styles, input string, color1, color2 color.Color) string {
46+func ApplyForegroundGrad(base lipgloss.Style, input string, color1, color2 color.Color) string {
47 if input == "" {
47 if input == "" {
50 var o strings.Builder
50 var o strings.Builder
51− clusters := ForegroundGrad(t, input, false, color1, color2)
51+ clusters := ForegroundGrad(base, input, false, color1, color2)
52 for _, c := range clusters {
52 for _, c := range clusters {
53 fmt.Fprint(&o, c)
53 fmt.Fprint(&o, c)
@@ -57,61 +57,14 @@ func ApplyForegroundGrad(t *Styles, input string, color1, color2 color.Color) st
58// ApplyBoldForegroundGrad renders a given string with a horizontal gradient
58// ApplyBoldForegroundGrad renders a given string with a horizontal gradient
59// foreground.
59// foreground.
60−func ApplyBoldForegroundGrad(t *Styles, input string, color1, color2 color.Color) string {
60+func ApplyBoldForegroundGrad(base lipgloss.Style, input string, color1, color2 color.Color) string {
61 if input == "" {
61 if input == "" {
64 var o strings.Builder
64 var o strings.Builder
65− clusters := ForegroundGrad(t, input, true, color1, color2)
65+ clusters := ForegroundGrad(base, input, true, color1, color2)
66 for _, c := range clusters {
66 for _, c := range clusters {
67 fmt.Fprint(&o, c)
67 fmt.Fprint(&o, c)
69 return o.String()
69 return o.String()
72−// blendColors returns a slice of colors blended between the given keys.
73−// Blending is done in Hcl to stay in gamut.
74−func blendColors(size int, stops ...color.Color) []color.Color {
79− stopsPrime := make([]colorful.Color, len(stops))
80− for i, k := range stops {
81− stopsPrime[i], _ = colorful.MakeColor(k)
84− numSegments := len(stopsPrime) - 1
85− blended := make([]color.Color, 0, size)
87− // Calculate how many colors each segment should have.
88− segmentSizes := make([]int, numSegments)
89− baseSize := size / numSegments
90− remainder := size % numSegments
92− // Distribute the remainder across segments.
93− for i := range numSegments {
94− segmentSizes[i] = baseSize
100− // Generate colors for each segment.
101− for i := range numSegments {
103− c2 := stopsPrime[i+1]
104− segmentSize := segmentSizes[i]
106− for j := range segmentSize {
108− if segmentSize > 1 {
109− t = float64(j) / float64(segmentSize-1)
111− c := c1.BlendHcl(c2, t)
112− blended = append(blended, c)