mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-11-23 22:24:51 +02:00
render commit graph
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user