Skip to content

Commit

Permalink
ignore coloring when the character is whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Code-Hex committed Nov 2, 2021
1 parent 375e98e commit 850360c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions rainbow.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cowsay
import (
"fmt"
"math"
"unicode"
)

const (
Expand Down Expand Up @@ -32,7 +33,11 @@ func (cow *Cow) Rainbow(mow string) string {
cow.buf.WriteRune(char)
continue
}
fmt.Fprintf(&cow.buf, "\x1b[%d%sm%c\x1b[0m", rainbow[i%6], attribute, char)
if unicode.IsSpace(char) {
cow.buf.WriteRune(char)
} else {
fmt.Fprintf(&cow.buf, "\x1b[%d%sm%c\x1b[0m", rainbow[i%len(rainbow)], attribute, char)
}
i++
}

Expand All @@ -53,7 +58,11 @@ func (cow *Cow) Aurora(i int, mow string) string {
cow.buf.WriteRune(char)
continue
}
fmt.Fprintf(&cow.buf, "\033[38;5;%d%sm%c\033[0m", rgb(float64(i)), attribute, char)
if unicode.IsSpace(char) {
cow.buf.WriteRune(char)
} else {
fmt.Fprintf(&cow.buf, "\033[38;5;%d%sm%c\033[0m", rgb(float64(i)), attribute, char)
}
i++
}
return cow.buf.String()
Expand Down

0 comments on commit 850360c

Please sign in to comment.