From cf195201d2f9333f541dc6994bc2220ffc531fb0 Mon Sep 17 00:00:00 2001 From: honggengwei Date: Thu, 16 Oct 2014 15:22:01 +0800 Subject: [PATCH] add font color --- figlet/render.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/figlet/render.go b/figlet/render.go index a647b3f..36a9d0a 100644 --- a/figlet/render.go +++ b/figlet/render.go @@ -1,13 +1,16 @@ package figlet import ( - //"github.com/fatih/color" "errors" + "fmt" + "github.com/fatih/color" "strings" ) type RenderOptions struct { - FontName string + FontName string // font name + + FontColor []color.Attribute // every ascii byte's color } func NewRenderOptions() *RenderOptions { @@ -78,9 +81,18 @@ func (this *AsciiRender) render(asciiStr string, opt *RenderOptions) (string, er 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 j := 0; j < len(wordlist); j++ { - result += wordlist[j][i] + result += wordColorFunc[j]((wordlist[j][i])) } result += "\n" }