Skip to content
Myr

Always prepend ANSI reset code before re-assembling tokens

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent e00e7e1 · Browse files · 4 files+9 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+9 added−7 removed

  • other:+9 added−7 removed

4 files+9 added−7 removed

modified:src/util/chars.go+3 added-3 removed
170 unmodified lines
171 }172 return173}174175func (chars *Chars) Wrap(prefix string, suffix string) {175func (chars *Chars) Prepend(prefix string) {176 if runes := chars.optionalRunes(); runes != nil {177 runes = append(append([]rune(prefix), runes...), []rune(suffix)...)177 runes = append([]rune(prefix), runes...)178 chars.slice = *(*[]byte)(unsafe.Pointer(&runes))179 } else {180 chars.slice = append(append([]byte(prefix), chars.slice...), []byte(suffix)...)180 chars.slice = append([]byte(prefix), chars.slice...)181 }182}
modified:src/ansi_test.go+2 added-2 removed
165 unmodified lines
166 strings.Replace(expected, "\x1b[", "\\x1b[", -1),167 strings.Replace(state.ToString(), "\x1b[", "\\x1b[", -1))168 }169 }170 assert("\x1b[m", nil, "\x1b[m")171 assert("\x1b[m", &ansiState{attr: tui.Blink}, "\x1b[m")170 assert("\x1b[m", nil, "")171 assert("\x1b[m", &ansiState{attr: tui.Blink}, "")172173 assert("\x1b[31m", nil, "\x1b[31;49m")174 assert("\x1b[41m", nil, "\x1b[39;41m")175
12 unmodified lines
modified:src/ansi.go+1 added-1 removed
32 unmodified lines
33}3435func (s *ansiState) ToString() string {36 if !s.colored() {37 return "\x1b[m"37 return ""38 }3940 ret := ""41 if s.attr&tui.Bold > 0 {
246 unmodified lines
modified:src/core.go+3 added-1 removed
110 unmodified lines
111 for _, token := range tokens {112 prevAnsiState := ansiState113 _, _, ansiState = extractColor(token.text.ToString(), ansiState, nil)114 if prevAnsiState != nil {115 token.text.Wrap(prevAnsiState.ToString(), "\x1b[m")115 token.text.Prepend("\x1b[m" + prevAnsiState.ToString())116 } else {117 token.text.Prepend("\x1b[m")118 }119 }120 }121 trans := Transform(tokens, opts.WithNth)
184 unmodified lines