diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-11-02 16:39:15 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-11-05 07:58:21 +1100 |
commit | 802cfb1a0436568c72fc998249f10f8150b352a3 (patch) | |
tree | 599f8a8bd52b786312a11f3b3cac2a2d5b7c597e /pkg/utils | |
parent | 2fc1498517523a20a3080816ec50ee9e7fbe533d (diff) |
render commit graph
Diffstat (limited to 'pkg/utils')
-rw-r--r-- | pkg/utils/color.go | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/pkg/utils/color.go b/pkg/utils/color.go index 18b04db1f..76e4c41c1 100644 --- a/pkg/utils/color.go +++ b/pkg/utils/color.go @@ -6,21 +6,24 @@ import ( ) var decoloriseCache = make(map[string]string) -var decoloriseMutex sync.Mutex +var decoloriseMutex sync.RWMutex // Decolorise strips a string of color func Decolorise(str string) string { - decoloriseMutex.Lock() - defer decoloriseMutex.Unlock() + decoloriseMutex.RLock() + val := decoloriseCache[str] + decoloriseMutex.RUnlock() - if decoloriseCache[str] != "" { - return decoloriseCache[str] + if val != "" { + return val } re := regexp.MustCompile(`\x1B\[([0-9]{1,3}(;[0-9]{1,3})*)?[mGK]`) ret := re.ReplaceAllString(str, "") + decoloriseMutex.Lock() decoloriseCache[str] = ret + decoloriseMutex.Unlock() return ret } |