1
0
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:
Jesse Duffield
2021-11-02 16:39:15 +11:00
parent 2fc1498517
commit 802cfb1a04
53 changed files with 543 additions and 284 deletions

View File

@@ -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
}