Codebase list golang-github-muesli-termenv / 910c24ea-4ad3-40af-b09f-90ad73b41217/upstream/sid
Import upstream version 0.9.0 Debian Janitor 2 years ago
6 changed file(s) with 39 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
44 <a href="https://godoc.org/github.com/muesli/termenv"><img src="https://godoc.org/github.com/golang/gddo?status.svg" alt="GoDoc"></a>
55 <a href="https://github.com/muesli/termenv/actions"><img src="https://github.com/muesli/termenv/workflows/build/badge.svg" alt="Build Status"></a>
66 <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>
88 </p>
99
1010 `termenv` lets you safely use advanced styling options on the terminal. It
187187 h, _ := colorful.Hex(ansiHex[c])
188188 for i := 0; i <= 15; i++ {
189189 hb, _ := colorful.Hex(ansiHex[i])
190 d := h.DistanceLab(hb)
190 d := h.DistanceHSLuv(hb)
191191
192192 if d < md {
193193 md = d
234234 // Return the one which is nearer to the original input rgb value
235235 c2 := colorful.Color{R: float64(cr) / 255.0, G: float64(cg) / 255.0, B: float64(cb) / 255.0}
236236 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)
239239
240240 if colorDist <= grayDist {
241241 return ANSI256Color(16 + ci)
33
44 require (
55 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
88 golang.org/x/sys v0.0.0-20200116001909-b77594299b42
99 )
00 github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
11 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=
88 golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
99 golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
2323 InsertLineSeq = "%dL"
2424 DeleteLineSeq = "%dM"
2525
26 // Explicit values for EraseLineSeq.
27 EraseLineRightSeq = "0K"
28 EraseLineLeftSeq = "1K"
29 EraseEntireLineSeq = "2K"
30
2631 ShowCursorSeq = "?25h"
2732 HideCursorSeq = "?25l"
2833 EnableMousePressSeq = "?9h" // press only (X10)
121126
122127 // ClearLine clears the current line.
123128 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)
125140 }
126141
127142 // ClearLines clears a given number of lines.
107107 func TestANSIProfile(t *testing.T) {
108108 p := ANSI
109109
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"
121121 if c.Sequence(false) != exp {
122122 t.Errorf("Expected %s, got %s", exp, c.Sequence(false))
123123 }