Skip to content

Commit

Permalink
(#41) Improve -uncolor
Browse files Browse the repository at this point in the history
  • Loading branch information
hahwul committed Apr 26, 2022
1 parent 1bc0af0 commit b36214e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/gee/string.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gee

import (
"regexp"
"strconv"
"strings"

Expand All @@ -16,6 +17,8 @@ func StringProc(l string, stdLine int, options model.Options) (string, string) {
var resultPlainArr []string
var returnString string
var returnPlainString string
const ansi = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
var ansiRegex = regexp.MustCompile(ansi)

if options.Reverse {
result = setReverse(result)
Expand Down Expand Up @@ -76,6 +79,10 @@ func StringProc(l string, stdLine int, options model.Options) (string, string) {
returnString = "<tr>" + returnString + "</tr>\n"
returnPlainString = "<tr>" + returnPlainString + "</tr>\n"
}
if !options.Color {
ansiRegex.ReplaceAllString(returnString, "")
ansiRegex.ReplaceAllString(returnPlainString, "")
}
return returnString, returnPlainString
}

Expand Down

0 comments on commit b36214e

Please sign in to comment.