1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03:00

Fix Decolorise to also strip hyperlinks

This is needed so that the information view is correctly aligned when we add
hyperlinks to it.
This commit is contained in:
Stefan Haller
2024-08-16 12:23:57 +02:00
parent fb97c30080
commit b411897a5a
2 changed files with 8 additions and 0 deletions

View File

@ -25,7 +25,9 @@ func Decolorise(str string) string {
}
re := regexp.MustCompile(`\x1B\[([0-9]{1,3}(;[0-9]{1,3})*)?[mGK]`)
linkRe := regexp.MustCompile(`\x1B]8;[^;]*;(.*?)(\x1B.|\x07)`)
ret := re.ReplaceAllString(str, "")
ret = linkRe.ReplaceAllString(ret, "")
decoloriseMutex.Lock()
decoloriseCache[str] = ret

View File

@ -2,6 +2,8 @@ package utils
import (
"testing"
"github.com/jesseduffield/lazygit/pkg/gui/style"
)
func TestDecolorise(t *testing.T) {
@ -189,6 +191,10 @@ func TestDecolorise(t *testing.T) {
input: "\x1b[38;2;157;205;18mta\x1b[0m",
output: "ta",
},
{
input: "a_" + style.PrintSimpleHyperlink("xyz") + "_b",
output: "a_xyz_b",
},
}
for _, test := range tests {