| name | figlet-go |
| description | Guide for using the figlet-go library to generate ASCII art text in Go applications. Use when working with the figlet-go package, creating ASCII art output, rendering animated ASCII art, or integrating FIGlet functionality into Go CLI tools. Covers rendering, fonts, colors, animations, and configuration. |
| allowed-tools | Read, Grep, Bash(go doc *) |
figlet-go Skill
Guide for using the figlet-go library (github.com/lsferreira42/figlet-go/figlet) to generate ASCII art text in Go applications.
Installation
go get github.com/lsferreira42/figlet-go/figlet
Quick Start
Simple Rendering
import (
"fmt"
"log"
"github.com/lsferreira42/figlet-go/figlet"
)
result, err := figlet.Render("Hello!")
if err != nil {
log.Fatal(err)
}
fmt.Print(result)
With Specific Font
result, err := figlet.RenderWithFont("Go!", "slant")
if err != nil {
log.Fatal(err)
}
fmt.Print(result)
API Patterns
Functional Options Pattern
Use option functions for configuration:
result, err := figlet.Render("Text",
figlet.WithFont("big"),
figlet.WithWidth(60),
figlet.WithJustification(1),
figlet.WithParser("terminal-color"),
figlet.WithColors(figlet.ColorRed, figlet.ColorGreen),
)
Direct Config Usage
For advanced control, use the Config struct directly:
cfg := figlet.New()
cfg.Fontname = "banner"
cfg.Outputwidth = 100
if err := cfg.LoadFont(); err != nil {
log.Fatal(err)
}
result := cfg.RenderString("Config")
Available Options
| Option | Description |
|---|
WithFont(name) | Set font (146 available, see ListFonts()) |
WithWidth(width) | Set output width in characters |
WithJustification(n) | 0=left, 1=center, 2=right |
WithParser(type) | terminal, terminal-color, html |
WithColors(colors...) | ANSI colors or TrueColor |
Colors
ANSI Colors
result, err := figlet.Render("Colors!",
figlet.WithColors(figlet.ColorRed, figlet.ColorGreen, figlet.ColorBlue),
)
TrueColor (24-bit RGB)
tcRed, _ := figlet.NewTrueColorFromHexString("FF0000")
tcGreen, _ := figlet.NewTrueColorFromHexString("00FF00")
result, err := figlet.Render("TrueColor",
figlet.WithColors(tcRed, tcGreen),
)
Utility Functions
fonts := figlet.ListFonts()
version := figlet.GetVersion()
versionInt := figlet.GetVersionInt()
Popular Fonts
standard - Default font
banner - Large banner style
big - Large block letters
slant - Slanted text
shadow - Shadow effect
script - Script style
doom - DOOM game style
starwars - Star Wars style
Output Formats
terminal - Plain text (default)
terminal-color - ANSI colored output
html - HTML formatted output
Animations
FIGlet-Go supports generating animated ASCII art with several animation types:
import (
"fmt"
"time"
"github.com/lsferreira42/figlet-go/figlet"
)
func main() {
cfg := figlet.New()
cfg.Fontname = "slant"
animator := figlet.NewAnimator(cfg)
frames, err := animator.GenerateAnimation("GO!", "reveal", 50*time.Millisecond)
if err != nil {
panic(err)
}
figlet.PlayAnimation(frames)
}
Animation Types
| Type | Description |
|---|
reveal | Reveals text character by character from left to right |
scroll | Scrolls text from the right margin to final position |
rain | Characters "fall" into place from the top |
wave | Sinusoidal wave effect that settles over time |
explosion | Text explodes into particles and reforms |
HTML Animation Player
When using the html parser, PlayAnimation automatically generates a standalone HTML animation player with:
- Professional terminal aesthetic
- Optimized monospaced fonts
- High-performance JavaScript for fluid playback
- Stable color mapping (colors stay pinned to characters)
frames, _ := animator.GenerateAnimation("GO!", "explode", 50*time.Millisecond)
figlet.PlayAnimation(frames)
List Available Animations
animations := figlet.ListAnimations()
for _, anim := range animations {
fmt.Println(anim)
}
Advanced Configuration
Config Struct Fields
For fine-grained control, use the Config struct directly:
cfg := figlet.New()
cfg.Fontname = "banner"
cfg.Fontdirname = "/path/to/fonts"
cfg.Outputwidth = 120
cfg.Justification = 1
cfg.Right2left = 0
cfg.Smushmode = 0
cfg.Smushoverride = 0
cfg.Paragraphflag = false
cfg.Deutschflag = false
cfg.AddControlFile("utf8")
if err := cfg.LoadFont(); err != nil {
log.Fatal(err)
}
result := cfg.RenderString("Hello")
Smushing Modes
Control how characters overlap:
figlet.WithFullWidth()
figlet.WithKerning()
figlet.WithSmushing()
figlet.WithOverlapping()
Version Info
fmt.Println("Version:", figlet.GetVersion())
fmt.Println("Version Int:", figlet.GetVersionInt())
fmt.Println("Columns:", figlet.GetColumns())
Example
See complete working examples:
Resources