-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.go
47 lines (35 loc) · 867 Bytes
/
helper.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
package checklist
import (
"fmt"
"regexp"
"strings"
"github.com/juju/ansiterm"
)
func allReady(s []ListItemState, waitAllReady bool) bool {
if len(s) == 0 {
return false
}
for _, state := range s {
if !state.isFinal(waitAllReady) {
return false
}
}
return true
}
func printToTabWriter(w *ansiterm.TabWriter, items []string) error {
format := strings.Repeat("%s\t", len(items)-1)
format += "%s\n"
values := make([]interface{}, len(items))
for i := range items {
values[i] = items[i]
}
if _, err := fmt.Fprintf(w, format, values...); err != nil {
return err
}
return nil
}
const ansi = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
var re = regexp.MustCompile(ansi)
func stripANSI(str string) string {
return re.ReplaceAllString(str, "")
}