Skip to content

Commit

Permalink
Fix two byte character issue
Browse files Browse the repository at this point in the history
The colored string contains the context of the input string rune by rune
with each rune having a respective color setting. However, the parsing
transferred the input string byte by byte into the colored string. There
is a problem for inputs that contain multi byte characters. Copying them
required that the two byte characters are processed at once.

Switch copy for look to work on a rune slice rather than bytes.
  • Loading branch information
HeavyWombat committed Nov 7, 2020
1 parent b792f2d commit 878a878
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func ParseString(input string, opts ...ParseOption) (*String, error) {
fullMatchStart, fullMatchEnd := submatch[0], submatch[1]
settingsStart, settingsEnd := submatch[2], submatch[3]

for i := pointer; i < fullMatchStart; i++ {
result = append(result, ColoredRune{rune(input[i]), current})
for _, r := range input[pointer:fullMatchStart] {
result = append(result, ColoredRune{r, current})
}

current, err = parseSelectGraphicRenditionEscapeSequence(input[settingsStart:settingsEnd])
Expand All @@ -81,8 +81,8 @@ func ParseString(input string, opts ...ParseOption) (*String, error) {
}

// Flush the remaining input string part into the result
for i := pointer; i < len(input); i++ {
result = append(result, ColoredRune{rune(input[i]), current})
for _, r := range input[pointer:] {
result = append(result, ColoredRune{r, current})
}

// Process optional parser options
Expand Down
2 changes: 1 addition & 1 deletion render.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (s String) String() string {
current = coloredRune.Settings
}

_ = buffer.WriteByte(byte(coloredRune.Symbol))
_, _ = buffer.WriteRune(coloredRune.Symbol)
}

// Make sure to finish with a reset escape sequence
Expand Down

0 comments on commit 878a878

Please sign in to comment.