Debian Codegraph @

debian/patches/0001-Add-patch-to-revert-commit-6aa93cd20570c3f73ab32881f.patch

raw
1 From: "Dr. Tobias Quathamer" <[email protected]>
2 Date: Fri, 24 Oct 2025 21:06:22 +0200
3 Subject: Add patch to revert commit 6aa93cd20570c3f73ab32881f77e1b29ca59c22e
4
5 In that commit, the package exp/color has been removed. However, it is
6 still needed by other packages in this library, so we add it again for now.
7
8 Forwarded: not-needed
9 ---
10 exp/color/blend.go | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
11 exp/color/go.mod | 5 ++++
12 exp/color/go.sum | 2 ++
13 3 files changed, 76 insertions(+)
14 create mode 100644 exp/color/blend.go
15 create mode 100644 exp/color/go.mod
16 create mode 100644 exp/color/go.sum
17
18 diff --git a/exp/color/blend.go b/exp/color/blend.go
19 new file mode 100644
20 index 0000000..cee2c7f
21 --- /dev/null
22 +++ b/exp/color/blend.go
23 @@ -0,0 +1,69 @@
24 +// Package color contains utilities for working with colors.
25 +package color
26 +
27 +import (
28 + "image/color"
29 +
30 + "github.com/lucasb-eyer/go-colorful"
31 +)
32 +
33 +// Blend returns a slice of colors blended between the given
34 +// colors. Blending is done as Hcl to stay in gamut.
35 +//
36 +// Example:
37 +//
38 +// red := color.RGBA{R: 0xff, G: 0x00, B: 0x00, A: 0xff}
39 +// blue := color.RGBA{R: 0x00, G: 0x00, B: 0xff, A: 0xff}
40 +//
41 +// blend := Blend(10, red, blue)
42 +// var b strings.Builder
43 +//
44 +// for _, c := range blend {
45 +// b.WriteString(lipgloss.NewStyle().Background(c).Render(" "))
46 +// }
47 +//
48 +// lipgloss.Println(b.String())
49 +func Blend(size int, points ...color.Color) []color.Color {
50 + if size <= 0 || len(points) < 2 {
51 + return nil
52 + }
53 + if size == 1 {
54 + return []color.Color{points[0]}
55 + }
56 +
57 + stops := make([]colorful.Color, len(points))
58 + for i, c := range points {
59 + stops[i], _ = colorful.MakeColor(c)
60 + }
61 +
62 + numSegments := len(stops) - 1
63 + blended := make([]color.Color, 0, size)
64 +
65 + // Calculate how many colors each segment should have.
66 + segmentSizes := make([]int, numSegments)
67 + baseSize := size / numSegments
68 + remainder := size % numSegments
69 +
70 + // Distribute the remainder across segments.
71 + for i := range numSegments {
72 + segmentSizes[i] = baseSize
73 + if i < remainder {
74 + segmentSizes[i]++
75 + }
76 + }
77 +
78 + // Generate colors for each segment.
79 + for i := range numSegments {
80 + c1 := stops[i]
81 + c2 := stops[i+1]
82 + segmentSize := segmentSizes[i]
83 +
84 + for j := range segmentSize {
85 + t := float64(j) / float64(segmentSize)
86 + c := c1.BlendHcl(c2, t)
87 + blended = append(blended, c)
88 + }
89 + }
90 +
91 + return blended
92 +}
93 diff --git a/exp/color/go.mod b/exp/color/go.mod
94 new file mode 100644
95 index 0000000..414e6c4
96 --- /dev/null
97 +++ b/exp/color/go.mod
98 @@ -0,0 +1,5 @@
99 +module github.com/charmbracelet/x/exp/color
100 +
101 +go 1.24.0
102 +
103 +require github.com/lucasb-eyer/go-colorful v1.3.0
104 diff --git a/exp/color/go.sum b/exp/color/go.sum
105 new file mode 100644
106 index 0000000..7e7b637
107 --- /dev/null
108 +++ b/exp/color/go.sum
109 @@ -0,0 +1,2 @@
110 +github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
111 +github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=