Import upstream version 0.9.0
Debian Janitor
2 years ago
4 | 4 |
<a href="https://godoc.org/github.com/muesli/termenv"><img src="https://godoc.org/github.com/golang/gddo?status.svg" alt="GoDoc"></a>
|
5 | 5 |
<a href="https://github.com/muesli/termenv/actions"><img src="https://github.com/muesli/termenv/workflows/build/badge.svg" alt="Build Status"></a>
|
6 | 6 |
<a href="https://coveralls.io/github/muesli/termenv?branch=master"><img src="https://coveralls.io/repos/github/muesli/termenv/badge.svg?branch=master" alt="Coverage Status"></a>
|
7 | |
<a href="http://goreportcard.com/report/muesli/termenv"><img src="http://goreportcard.com/badge/muesli/termenv" alt="Go ReportCard"></a>
|
|
7 |
<a href="https://goreportcard.com/report/muesli/termenv"><img src="https://goreportcard.com/badge/muesli/termenv" alt="Go ReportCard"></a>
|
8 | 8 |
</p>
|
9 | 9 |
|
10 | 10 |
`termenv` lets you safely use advanced styling options on the terminal. It
|
187 | 187 |
h, _ := colorful.Hex(ansiHex[c])
|
188 | 188 |
for i := 0; i <= 15; i++ {
|
189 | 189 |
hb, _ := colorful.Hex(ansiHex[i])
|
190 | |
d := h.DistanceLab(hb)
|
|
190 |
d := h.DistanceHSLuv(hb)
|
191 | 191 |
|
192 | 192 |
if d < md {
|
193 | 193 |
md = d
|
|
234 | 234 |
// Return the one which is nearer to the original input rgb value
|
235 | 235 |
c2 := colorful.Color{R: float64(cr) / 255.0, G: float64(cg) / 255.0, B: float64(cb) / 255.0}
|
236 | 236 |
g2 := colorful.Color{R: float64(gv) / 255.0, G: float64(gv) / 255.0, B: float64(gv) / 255.0}
|
237 | |
colorDist := c.DistanceLab(c2)
|
238 | |
grayDist := c.DistanceLab(g2)
|
|
237 |
colorDist := c.DistanceHSLuv(c2)
|
|
238 |
grayDist := c.DistanceHSLuv(g2)
|
239 | 239 |
|
240 | 240 |
if colorDist <= grayDist {
|
241 | 241 |
return ANSI256Color(16 + ci)
|
3 | 3 |
|
4 | 4 |
require (
|
5 | 5 |
github.com/lucasb-eyer/go-colorful v1.2.0
|
6 | |
github.com/mattn/go-isatty v0.0.12
|
7 | |
github.com/mattn/go-runewidth v0.0.10
|
|
6 |
github.com/mattn/go-isatty v0.0.13
|
|
7 |
github.com/mattn/go-runewidth v0.0.13
|
8 | 8 |
golang.org/x/sys v0.0.0-20200116001909-b77594299b42
|
9 | 9 |
)
|
0 | 0 |
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
1 | 1 |
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
2 | |
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
3 | |
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
4 | |
github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=
|
5 | |
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
6 | |
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
|
7 | |
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
|
2 |
github.com/mattn/go-isatty v0.0.13 h1:qdl+GuBjcsKKDco5BsxPJlId98mSWNKqYA+Co0SC1yA=
|
|
3 |
github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
|
4 |
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
|
|
5 |
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
|
6 |
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
|
7 |
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
8 | 8 |
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
|
9 | 9 |
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
23 | 23 |
InsertLineSeq = "%dL"
|
24 | 24 |
DeleteLineSeq = "%dM"
|
25 | 25 |
|
|
26 |
// Explicit values for EraseLineSeq.
|
|
27 |
EraseLineRightSeq = "0K"
|
|
28 |
EraseLineLeftSeq = "1K"
|
|
29 |
EraseEntireLineSeq = "2K"
|
|
30 |
|
26 | 31 |
ShowCursorSeq = "?25h"
|
27 | 32 |
HideCursorSeq = "?25l"
|
28 | 33 |
EnableMousePressSeq = "?9h" // press only (X10)
|
|
121 | 126 |
|
122 | 127 |
// ClearLine clears the current line.
|
123 | 128 |
func ClearLine() {
|
124 | |
fmt.Printf(CSI+EraseLineSeq, 2)
|
|
129 |
fmt.Print(CSI + EraseEntireLineSeq)
|
|
130 |
}
|
|
131 |
|
|
132 |
// ClearLineLeft clears the line to the left of the cursor.
|
|
133 |
func ClearLineLeft() {
|
|
134 |
fmt.Print(CSI + EraseLineLeftSeq)
|
|
135 |
}
|
|
136 |
|
|
137 |
// ClearLineRight clears the line to the right of the cursor.
|
|
138 |
func ClearLineRight() {
|
|
139 |
fmt.Print(CSI + EraseLineRightSeq)
|
125 | 140 |
}
|
126 | 141 |
|
127 | 142 |
// ClearLines clears a given number of lines.
|
107 | 107 |
func TestANSIProfile(t *testing.T) {
|
108 | 108 |
p := ANSI
|
109 | 109 |
|
110 | |
c := p.Color("#abcdef")
|
111 | |
exp := "37"
|
112 | |
if c.Sequence(false) != exp {
|
113 | |
t.Errorf("Expected %s, got %s", exp, c.Sequence(false))
|
114 | |
}
|
115 | |
if _, ok := c.(ANSIColor); !ok {
|
116 | |
t.Errorf("Expected type termenv.ANSIColor, got %T", c)
|
117 | |
}
|
118 | |
|
119 | |
c = p.Color("139")
|
120 | |
exp = "90"
|
|
110 |
c := p.Color("#e88388")
|
|
111 |
exp := "91"
|
|
112 |
if c.Sequence(false) != exp {
|
|
113 |
t.Errorf("Expected %s, got %s", exp, c.Sequence(false))
|
|
114 |
}
|
|
115 |
if _, ok := c.(ANSIColor); !ok {
|
|
116 |
t.Errorf("Expected type termenv.ANSIColor, got %T", c)
|
|
117 |
}
|
|
118 |
|
|
119 |
c = p.Color("82")
|
|
120 |
exp = "92"
|
121 | 121 |
if c.Sequence(false) != exp {
|
122 | 122 |
t.Errorf("Expected %s, got %s", exp, c.Sequence(false))
|
123 | 123 |
}
|