-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
51 lines (44 loc) · 972 Bytes
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package spinner
import (
"container/ring"
"fmt"
"strings"
"github.com/alecrabbit/go-cli-spinner/color"
)
// moveBackSequence returns string containing ANSI move cursor back sequence
func moveBackSequence(w int) string {
if w <= 0 {
return ""
}
return fmt.Sprintf("\x1b[%vD", w)
}
// eraseSequence returns string containing ANSI erase sequence
func eraseSequence(w int) string {
if w < 1 {
return ""
}
return fmt.Sprintf("\x1b[%vX", w)
}
// replace all "\x1b" to `\e`
func replaceEscapes(in string) string {
return strings.ReplaceAll(in, "\x1b", `\e`)
}
func createColorSet(p color.StylePrototype, format string) (r *ring.Ring) {
xs := p.Handler(p.ANSIStyles)
u := len(xs)
r = ring.New(u)
for i := 0; i < u; i++ {
r.Value = fmt.Sprintf(xs[i], format)
r = r.Next()
}
return
}
func applyCharSet(charSet []string) (r *ring.Ring) {
u := len(charSet)
r = ring.New(u)
for i := 0; i < u; i++ {
r.Value = charSet[i]
r = r.Next()
}
return
}