mirror of
https://github.com/KevinMidboe/motdGO.git
synced 2025-10-29 17:50:24 +00:00
add font color
This commit is contained in:
@@ -1,13 +1,16 @@
|
|||||||
package figlet
|
package figlet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
//"github.com/fatih/color"
|
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"github.com/fatih/color"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RenderOptions struct {
|
type RenderOptions struct {
|
||||||
FontName string
|
FontName string // font name
|
||||||
|
|
||||||
|
FontColor []color.Attribute // every ascii byte's color
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRenderOptions() *RenderOptions {
|
func NewRenderOptions() *RenderOptions {
|
||||||
@@ -78,9 +81,18 @@ func (this *AsciiRender) render(asciiStr string, opt *RenderOptions) (string, er
|
|||||||
|
|
||||||
result := ""
|
result := ""
|
||||||
|
|
||||||
|
wordColorFunc := make([]func(a ...interface{}) string, len(wordlist))
|
||||||
|
for i, _ := range wordColorFunc {
|
||||||
|
if i < len(opt.FontColor) {
|
||||||
|
wordColorFunc[i] = color.New(opt.FontColor[i]).SprintFunc()
|
||||||
|
} else {
|
||||||
|
wordColorFunc[i] = fmt.Sprint
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for i := 0; i < font.height; i++ {
|
for i := 0; i < font.height; i++ {
|
||||||
for j := 0; j < len(wordlist); j++ {
|
for j := 0; j < len(wordlist); j++ {
|
||||||
result += wordlist[j][i]
|
result += wordColorFunc[j]((wordlist[j][i]))
|
||||||
}
|
}
|
||||||
result += "\n"
|
result += "\n"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user