diff --git a/util.go b/util.go index 380e7ab..4fe5f7a 100644 --- a/util.go +++ b/util.go @@ -15,7 +15,7 @@ import ( "github.com/mattn/go-runewidth" ) -var ansi = regexp.MustCompile("\033\\[(?:[0-9]{1,3}(?:;[0-9]{1,3})*)?[m|K]") +var ansi = regexp.MustCompile("\033(?:\\[(?:[0-9]{1,3}(?:;[0-9]{1,3})*)?[m|K]|\\]8;;.*?\033\\\\)") func DisplayWidth(str string) int { return runewidth.StringWidth(ansi.ReplaceAllLiteralString(str, "")) diff --git a/wrap_test.go b/wrap_test.go index a03f9fc..ed606cf 100644 --- a/wrap_test.go +++ b/wrap_test.go @@ -55,4 +55,7 @@ func TestDisplayWidth(t *testing.T) { } input = "\033[43;30m" + input + "\033[00m" checkEqual(t, DisplayWidth(input), want) + + input = "\033]8;;idea://open/?file=/path/somefile.php&line=12\033\\some URL\033]8;;\033\\" + checkEqual(t, DisplayWidth(input), 8) }