mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 04:19:41 -08:00
parent
096cb8e997
commit
d4fbbaebb3
|
@ -17,11 +17,11 @@ func measureText(text string) int {
|
||||||
text = strings.ReplaceAll(text, match["STR"], match["TEXT"])
|
text = strings.ReplaceAll(text, match["STR"], match["TEXT"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
text = textWithoutAnsi(text)
|
text = TrimAnsi(text)
|
||||||
return utf8.RuneCountInString(text)
|
return utf8.RuneCountInString(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
func textWithoutAnsi(text string) string {
|
func TrimAnsi(text string) string {
|
||||||
if len(text) == 0 || !strings.Contains(text, "\x1b") {
|
if len(text) == 0 || !strings.Contains(text, "\x1b") {
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ type Title struct {
|
||||||
|
|
||||||
func (t *Title) GetTitle() string {
|
func (t *Title) GetTitle() string {
|
||||||
title := t.getTitleTemplateText()
|
title := t.getTitleTemplateText()
|
||||||
|
title = color.TrimAnsi(title)
|
||||||
title = t.Ansi.EscapeText(title)
|
title = t.Ansi.EscapeText(title)
|
||||||
return t.Ansi.Title(title)
|
return t.Ansi.Title(title)
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,10 @@ func TestGetConsoleTitleIfGethostnameReturnsError(t *testing.T) {
|
||||||
ShellName: "PowerShell",
|
ShellName: "PowerShell",
|
||||||
Expected: "\x1b]0;MyUser@ :: PowerShell\a",
|
Expected: "\x1b]0;MyUser@ :: PowerShell\a",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Template: "\x1b[93m[\x1b[39m\x1b[96mconsole-title\x1b[39m\x1b[96m ≡\x1b[39m\x1b[31m +0\x1b[39m\x1b[31m ~1\x1b[39m\x1b[31m -0\x1b[39m\x1b[31m !\x1b[39m\x1b[93m]\x1b[39m",
|
||||||
|
Expected: "\x1b]0;[console-title ≡ +0 ~1 -0 !]\a",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
|
|
Loading…
Reference in a new issue