mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-06 11:02:41 +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:
@@ -25,7 +25,9 @@ func Decolorise(str string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
re := regexp.MustCompile(`\x1B\[([0-9]{1,3}(;[0-9]{1,3})*)?[mGK]`)
|
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 := re.ReplaceAllString(str, "")
|
||||||
|
ret = linkRe.ReplaceAllString(ret, "")
|
||||||
|
|
||||||
decoloriseMutex.Lock()
|
decoloriseMutex.Lock()
|
||||||
decoloriseCache[str] = ret
|
decoloriseCache[str] = ret
|
||||||
|
@@ -2,6 +2,8 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDecolorise(t *testing.T) {
|
func TestDecolorise(t *testing.T) {
|
||||||
@@ -189,6 +191,10 @@ func TestDecolorise(t *testing.T) {
|
|||||||
input: "\x1b[38;2;157;205;18mta\x1b[0m",
|
input: "\x1b[38;2;157;205;18mta\x1b[0m",
|
||||||
output: "ta",
|
output: "ta",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
input: "a_" + style.PrintSimpleHyperlink("xyz") + "_b",
|
||||||
|
output: "a_xyz_b",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
Reference in New Issue
Block a user