add truecolor support

This commit is contained in:
probandula
2016-11-02 16:46:47 +01:00
parent 9e6c45dd86
commit 76dcd98705
5 changed files with 123 additions and 35 deletions

15
char.go
View File

@@ -2,7 +2,6 @@ package figlet4go
import (
"errors"
"github.com/fatih/color"
)
// Represents a single ascii character
@@ -10,7 +9,7 @@ type asciiChar struct {
// Slice with the lines of the Char
Lines []string
// Color of the char
Color color.Attribute
Color Color
}
// Creates a new ascii character
@@ -28,9 +27,13 @@ func newAsciiChar(font *font, char rune) (*asciiChar, error) {
// Return a line of the char as string with color if set
func (char *asciiChar) GetLine(index int) string {
if char.Color != 0 {
colorFunc := color.New(char.Color).SprintFunc()
return colorFunc(char.Lines[index])
prefix := ""
suffix := ""
if char.Color != nil {
prefix = char.Color.getPrefix()
suffix = char.Color.getSuffix()
}
return char.Lines[index]
return prefix + char.Lines[index] + suffix
}