diff options
-rw-r--r-- | src/ansi.go | 2 | ||||
-rw-r--r-- | src/ansi_test.go | 4 | ||||
-rw-r--r-- | src/core.go | 4 | ||||
-rw-r--r-- | src/util/chars.go | 6 |
4 files changed, 9 insertions, 7 deletions
diff --git a/src/ansi.go b/src/ansi.go index 3579b99a..c31a4f4f 100644 --- a/src/ansi.go +++ b/src/ansi.go @@ -34,7 +34,7 @@ func (s *ansiState) equals(t *ansiState) bool { func (s *ansiState) ToString() string { if !s.colored() { - return "\x1b[m" + return "" } ret := "" diff --git a/src/ansi_test.go b/src/ansi_test.go index 5acbc131..e10893c9 100644 --- a/src/ansi_test.go +++ b/src/ansi_test.go @@ -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") diff --git a/src/core.go b/src/core.go index 62edd089..2db5b3ae 100644 --- a/src/core.go +++ b/src/core.go @@ -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") } } } diff --git a/src/util/chars.go b/src/util/chars.go index 35b28297..04a66d7d 100644 --- a/src/util/chars.go +++ b/src/util/chars.go @@ -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...) } } |