diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2015-03-22 17:19:30 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2015-03-22 17:22:52 +0900 |
commit | 618706a5f5b56b24d08857af075877135baa1ea6 (patch) | |
tree | 2959af66ad1ad3a9683556da5137c9310e740b0b /src | |
parent | 9ffcd26d5072f2d9594a4d23034d841918ebcc5d (diff) |
Fix ANSI output in the presence of multibyte characters
tree -C | fzf --ansi --tac
Diffstat (limited to 'src')
-rw-r--r-- | src/ansi.go | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/ansi.go b/src/ansi.go index fbfa0501..42c69166 100644 --- a/src/ansi.go +++ b/src/ansi.go @@ -5,6 +5,7 @@ import ( "regexp" "strconv" "strings" + "unicode/utf8" ) type ansiOffset struct { @@ -44,7 +45,6 @@ func extractColor(str *string) (*string, []ansiOffset) { idx := 0 for _, offset := range ansiRegex.FindAllStringIndex(*str, -1) { output.WriteString((*str)[idx:offset[0]]) - newLen := int32(output.Len()) newState := interpretCode((*str)[offset[0]:offset[1]], state) if !newState.equals(state) { @@ -56,6 +56,7 @@ func extractColor(str *string) (*string, []ansiOffset) { if newState.colored() { // Append new offset state = newState + newLen := int32(utf8.RuneCount(output.Bytes())) offsets = append(offsets, ansiOffset{[2]int32{newLen, newLen}, *state}) } else { // Discard state @@ -71,7 +72,7 @@ func extractColor(str *string) (*string, []ansiOffset) { output.WriteString(rest) if state != nil { // Update last offset - (&offsets[len(offsets)-1]).offset[1] = int32(output.Len()) + (&offsets[len(offsets)-1]).offset[1] = int32(utf8.RuneCount(output.Bytes())) } } outputStr := output.String() |