mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-22 21:05:09 +00:00
Always prepend ANSI reset code before re-assembling tokens
This commit is contained in:
parent
e00e7e1e56
commit
85c1f8a9e0
@ -34,7 +34,7 @@ func (s *ansiState) equals(t *ansiState) bool {
|
||||
|
||||
func (s *ansiState) ToString() string {
|
||||
if !s.colored() {
|
||||
return "\x1b[m"
|
||||
return ""
|
||||
}
|
||||
|
||||
ret := ""
|
||||
|
@ -167,8 +167,8 @@ func TestAnsiCodeStringConversion(t *testing.T) {
|
||||
strings.Replace(state.ToString(), "\x1b[", "\\x1b[", -1))
|
||||
}
|
||||
}
|
||||
assert("\x1b[m", nil, "\x1b[m")
|
||||
assert("\x1b[m", &ansiState{attr: tui.Blink}, "\x1b[m")
|
||||
assert("\x1b[m", nil, "")
|
||||
assert("\x1b[m", &ansiState{attr: tui.Blink}, "")
|
||||
|
||||
assert("\x1b[31m", nil, "\x1b[31;49m")
|
||||
assert("\x1b[41m", nil, "\x1b[39;41m")
|
||||
|
@ -112,7 +112,9 @@ func Run(opts *Options, revision string) {
|
||||
prevAnsiState := ansiState
|
||||
_, _, ansiState = extractColor(token.text.ToString(), ansiState, nil)
|
||||
if prevAnsiState != nil {
|
||||
token.text.Wrap(prevAnsiState.ToString(), "\x1b[m")
|
||||
token.text.Prepend("\x1b[m" + prevAnsiState.ToString())
|
||||
} else {
|
||||
token.text.Prepend("\x1b[m")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -172,11 +172,11 @@ func (chars *Chars) CopyRunes(dest []rune) {
|
||||
return
|
||||
}
|
||||
|
||||
func (chars *Chars) Wrap(prefix string, suffix string) {
|
||||
func (chars *Chars) Prepend(prefix string) {
|
||||
if runes := chars.optionalRunes(); runes != nil {
|
||||
runes = append(append([]rune(prefix), runes...), []rune(suffix)...)
|
||||
runes = append([]rune(prefix), runes...)
|
||||
chars.slice = *(*[]byte)(unsafe.Pointer(&runes))
|
||||
} else {
|
||||
chars.slice = append(append([]byte(prefix), chars.slice...), []byte(suffix)...)
|
||||
chars.slice = append([]byte(prefix), chars.slice...)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user