mirror of
https://github.com/KevinMidboe/motdGOi.git
synced 2025-10-29 17:50:24 +00:00
update readme.md and make demo.go's str optional.
This commit is contained in:
61
README.md
61
README.md
@@ -1,4 +1,4 @@
|
|||||||
#figlet4go
|
# figlet4go
|
||||||
_______ __ _______ __ _______ .___________. _ _ _______ ______
|
_______ __ _______ __ _______ .___________. _ _ _______ ______
|
||||||
| ____|| | / _____|| | | ____|| || || | / _____| / __ \
|
| ____|| | / _____|| | | ____|| || || | / _____| / __ \
|
||||||
| |__ | | | | __ | | | |__ `---| |----`| || |_ | | __ | | | |
|
| |__ | | | | __ | | | |__ `---| |----`| || |_ | | __ | | | |
|
||||||
@@ -9,53 +9,24 @@
|
|||||||
A port of [figlet](http://www.figlet.org/) to golang.
|
A port of [figlet](http://www.figlet.org/) to golang.
|
||||||
Make it easier to use,add some new feature such as colorized outputs.
|
Make it easier to use,add some new feature such as colorized outputs.
|
||||||
|
|
||||||
##Usage
|
## Usage
|
||||||
|
|
||||||
###Install
|
|
||||||
go get -u github.com/getwe/figlet4go
|
|
||||||
|
|
||||||
###Demo
|
### Install
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
```
|
||||||
"fmt"
|
go get -u github.com/getwe/figlet4go
|
||||||
"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)
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 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` .
|
||||||
|
|
||||||

|

|
||||||
|
|||||||
67
demo/demo.go
67
demo/demo.go
@@ -1,40 +1,49 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/getwe/figlet4go"
|
"github.com/getwe/figlet4go"
|
||||||
|
"flag"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var flag_str = flag.String("str", "golang", "input string")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
str := "golang"
|
flag.Parse()
|
||||||
ascii := figlet4go.NewAsciiRender()
|
str := *flag_str
|
||||||
// most simple Usage
|
ascii := figlet4go.NewAsciiRender()
|
||||||
renderStr, _ := ascii.Render(str)
|
// most simple Usage
|
||||||
fmt.Println(renderStr)
|
renderStr, _ := ascii.Render(str)
|
||||||
|
fmt.Println(renderStr)
|
||||||
|
|
||||||
// change the font color
|
// change the font color
|
||||||
options := figlet4go.NewRenderOptions()
|
colors := [...]color.Attribute{
|
||||||
options.FontColor = make([]color.Attribute, len(str))
|
color.FgMagenta,
|
||||||
options.FontColor[0] = color.FgMagenta
|
color.FgYellow,
|
||||||
options.FontColor[1] = color.FgYellow
|
color.FgBlue,
|
||||||
options.FontColor[2] = color.FgBlue
|
color.FgCyan,
|
||||||
options.FontColor[3] = color.FgCyan
|
color.FgRed,
|
||||||
options.FontColor[4] = color.FgRed
|
color.FgWhite,
|
||||||
options.FontColor[5] = color.FgWhite
|
}
|
||||||
renderStr, _ = ascii.RenderOpts(str, options)
|
options := figlet4go.NewRenderOptions()
|
||||||
fmt.Println(renderStr)
|
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
|
// change the font
|
||||||
options.FontName = "larry3d"
|
options.FontName = "larry3d"
|
||||||
// except the default font,others need to be load from disk
|
// except the default font,others need to be load from disk
|
||||||
// here is the font :
|
// here is the font :
|
||||||
// ftp://ftp.figlet.org/pub/figlet/fonts/contributed.tar.gz
|
// ftp://ftp.figlet.org/pub/figlet/fonts/contributed.tar.gz
|
||||||
// ftp://ftp.figlet.org/pub/figlet/fonts/international.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
|
// 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/")
|
ascii.LoadFont("/usr/local/Cellar/figlet/2.2.5/share/figlet/fonts/")
|
||||||
|
|
||||||
renderStr, _ = ascii.RenderOpts(str, options)
|
renderStr, _ = ascii.RenderOpts(str, options)
|
||||||
fmt.Println(renderStr)
|
fmt.Println(renderStr)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user