diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-10-31 22:29:43 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-10-31 22:33:39 +1100 |
commit | 9989c96321685ac3493642fb8e1fa511896175e3 (patch) | |
tree | 1742d16e270373c0a6ffdffa792506fc80f08157 /pkg/utils/color.go | |
parent | f91892b8f1180f43c6b0cf18cc118d42f3648a1a (diff) |
better formatting
Diffstat (limited to 'pkg/utils/color.go')
-rw-r--r-- | pkg/utils/color.go | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/pkg/utils/color.go b/pkg/utils/color.go index 84d5196d5..18b04db1f 100644 --- a/pkg/utils/color.go +++ b/pkg/utils/color.go @@ -2,12 +2,27 @@ package utils import ( "regexp" + "sync" ) +var decoloriseCache = make(map[string]string) +var decoloriseMutex sync.Mutex + // Decolorise strips a string of color func Decolorise(str string) string { + decoloriseMutex.Lock() + defer decoloriseMutex.Unlock() + + if decoloriseCache[str] != "" { + return decoloriseCache[str] + } + re := regexp.MustCompile(`\x1B\[([0-9]{1,3}(;[0-9]{1,3})*)?[mGK]`) - return re.ReplaceAllString(str, "") + ret := re.ReplaceAllString(str, "") + + decoloriseCache[str] = ret + + return ret } func IsValidHexValue(v string) bool { |