|
@@ -21,6 +21,12 @@ func Writer(handle int) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+var FindANSIColor *regexp.Regexp
|
|
|
+
|
|
|
+func init() {
|
|
|
+ FindANSIColor = regexp.MustCompile("\x1b\\[([0-9;]*)m")
|
|
|
+}
|
|
|
+
|
|
|
/*
|
|
|
reading from a closed channel is easy to detect.
|
|
|
|
|
@@ -33,8 +39,8 @@ writing to a closed channel is a panic.
|
|
|
func find_ansicolor(text string) [][]int {
|
|
|
var color_codes [][]int
|
|
|
|
|
|
- word, _ := regexp.Compile("\x1b\\[([0-9;]+)m")
|
|
|
- colors := word.FindAllStringIndex(text, -1)
|
|
|
+ // word, _ := regexp.Compile("\x1b\\[([0-9;]+)m")
|
|
|
+ colors := FindANSIColor.FindAllStringIndex(text, -1)
|
|
|
// regexp seems to be ignoring the capture groups.
|
|
|
// colors := word.FindAllSubmatchIndex([]byte(text), len(text))
|
|
|
for _, pos := range colors {
|
|
@@ -42,9 +48,9 @@ func find_ansicolor(text string) [][]int {
|
|
|
if txt == "" {
|
|
|
txt = "0"
|
|
|
}
|
|
|
- log.Printf("Text: [%s]\n", txt)
|
|
|
+ // log.Printf("Text: [%s]\n", txt)
|
|
|
codes := strings.Split(txt, ";")
|
|
|
- log.Printf("Codes: [%#v]\n", codes)
|
|
|
+ // log.Printf("Codes: [%#v]\n", codes)
|
|
|
code := make([]int, len(codes))
|
|
|
for idx, c := range codes {
|
|
|
var err error
|