From 1b8fc4834108c9bc00345a6e969210ecae1f3ade Mon Sep 17 00:00:00 2001 From: wyy Date: Thu, 23 Oct 2014 12:45:57 +0800 Subject: [PATCH] update readme.md and make demo.go's str optional. --- README.md | 61 +++++++++++++---------------------------------- demo/demo.go | 67 +++++++++++++++++++++++++++++----------------------- 2 files changed, 54 insertions(+), 74 deletions(-) diff --git a/README.md b/README.md index 1a2ac4d..6fb1c42 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -#figlet4go +# figlet4go _______ __ _______ __ _______ .___________. _ _ _______ ______ | ____|| | / _____|| | | ____|| || || | / _____| / __ \ | |__ | | | | __ | | | |__ `---| |----`| || |_ | | __ | | | | @@ -9,53 +9,24 @@ A port of [figlet](http://www.figlet.org/) to golang. Make it easier to use,add some new feature such as colorized outputs. -##Usage +## Usage -###Install - go get -u github.com/getwe/figlet4go -###Demo -```go -package main +### Install -import ( - "fmt" - "github.com/fatih/color" - "github.com/getwe/figlet4go" -) - -func main() { - str := "golang" - ascii := figlet4go.NewAsciiRender() - // most simple Usage - renderStr, _ := ascii.Render(str) - fmt.Println(renderStr) - - // change the font color - options := figlet4go.NewRenderOptions() - options.FontColor = make([]color.Attribute, len(str)) - options.FontColor[0] = color.FgMagenta - options.FontColor[1] = color.FgYellow - options.FontColor[2] = color.FgBlue - options.FontColor[3] = color.FgCyan - options.FontColor[4] = color.FgRed - options.FontColor[5] = color.FgWhite - renderStr, _ = ascii.RenderOpts(str, options) - fmt.Println(renderStr) - - // change the font - options.FontName = "larry3d" - // except the default font,others need to be load from disk - // here is the font : - // ftp://ftp.figlet.org/pub/figlet/fonts/contributed.tar.gz - // ftp://ftp.figlet.org/pub/figlet/fonts/international.tar.gz - // download and extract to the disk,then specify the file path to load - ascii.LoadFont("/usr/local/Cellar/figlet/2.2.5/share/figlet/fonts/") - - renderStr, _ = ascii.RenderOpts(str, options) - fmt.Println(renderStr) - -} +``` +go get -u github.com/getwe/figlet4go ``` +### Demo + +``` +cd demo/ +go build +./demo -str="golang" +#Maybe you have to `brew install figlet` if you need 3D fond in mac osx. +``` + +see details in `demo/demo.go` . + ![screenshot](./screenshot/demo1.jpg) diff --git a/demo/demo.go b/demo/demo.go index d60a259..5990aff 100644 --- a/demo/demo.go +++ b/demo/demo.go @@ -1,40 +1,49 @@ package main import ( - "fmt" - "github.com/fatih/color" - "github.com/getwe/figlet4go" + "fmt" + "github.com/fatih/color" + "github.com/getwe/figlet4go" + "flag" ) +var flag_str = flag.String("str", "golang", "input string") + func main() { - str := "golang" - ascii := figlet4go.NewAsciiRender() - // most simple Usage - renderStr, _ := ascii.Render(str) - fmt.Println(renderStr) + flag.Parse() + str := *flag_str + ascii := figlet4go.NewAsciiRender() + // most simple Usage + renderStr, _ := ascii.Render(str) + fmt.Println(renderStr) - // change the font color - options := figlet4go.NewRenderOptions() - options.FontColor = make([]color.Attribute, len(str)) - options.FontColor[0] = color.FgMagenta - options.FontColor[1] = color.FgYellow - options.FontColor[2] = color.FgBlue - options.FontColor[3] = color.FgCyan - options.FontColor[4] = color.FgRed - options.FontColor[5] = color.FgWhite - renderStr, _ = ascii.RenderOpts(str, options) - fmt.Println(renderStr) + // change the font color + colors := [...]color.Attribute{ + color.FgMagenta, + color.FgYellow, + color.FgBlue, + color.FgCyan, + color.FgRed, + color.FgWhite, + } + options := figlet4go.NewRenderOptions() + options.FontColor = make([]color.Attribute, len(str)) + for i := range options.FontColor { + options.FontColor[i] = colors[i % len(colors)] + } + renderStr, _ = ascii.RenderOpts(str, options) + fmt.Println(renderStr) - // change the font - options.FontName = "larry3d" - // except the default font,others need to be load from disk - // here is the font : - // ftp://ftp.figlet.org/pub/figlet/fonts/contributed.tar.gz - // ftp://ftp.figlet.org/pub/figlet/fonts/international.tar.gz - // download and extract to the disk,then specify the file path to load - ascii.LoadFont("/usr/local/Cellar/figlet/2.2.5/share/figlet/fonts/") + // change the font + options.FontName = "larry3d" + // except the default font,others need to be load from disk + // here is the font : + // ftp://ftp.figlet.org/pub/figlet/fonts/contributed.tar.gz + // ftp://ftp.figlet.org/pub/figlet/fonts/international.tar.gz + // download and extract to the disk,then specify the file path to load + ascii.LoadFont("/usr/local/Cellar/figlet/2.2.5/share/figlet/fonts/") - renderStr, _ = ascii.RenderOpts(str, options) - fmt.Println(renderStr) + renderStr, _ = ascii.RenderOpts(str, options) + fmt.Println(renderStr) }