Documentation
¶
Overview ¶
Package gofiglet renders ASCII art text using figlet fonts (.flf). It supports ANSI colors, true color (RGB), and per-character coloring. Built-in fonts are embedded and available without external file paths.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Colors = map[string]Color{ "default": TrueColorPink206, "none": ColorNone, "black": ColorBlack, "red": ColorRed, "green": ColorGreen, "yellow": ColorYellow, "blue": ColorBlue, "magenta": ColorMagenta, "cyan": ColorCyan, "white": ColorWhite, "darkGray": ColorHiBlack, "lightRed": ColorHiRed, "lightGreen": ColorHiGreen, "lightYellow": ColorHiYellow, "lightBlue": ColorHiBlue, "lightMagenta": ColorHiMagenta, "lightCyan": ColorHiCyan, "lightWhite": ColorHiWhite, "pink": TrueColorPink206, "neonyellow": TrueColorYellowNeon, "gold": TrueColorGold, }
Colors maps human-friendly color names to Color values, used by ResolveColor for named lookups. Named entries mirror the ANSI/ TrueColor variables declared above.
Functions ¶
func CmdBanner ¶
CmdBanner renders b as a colored ASCII art string. It returns an error if b.FontPath is set but fails to load, or if rendering fails (e.g. b.FontName cannot be found, or a Title segment contains a non-ASCII character).
func PrintCmdBanner ¶
PrintCmdBanner renders and prints b to stdout. It returns an error if rendering fails; see CmdBanner.
Types ¶
type ASCIIRender ¶
type ASCIIRender struct {
// contains filtered or unexported fields
}
ASCIIRender is the core rendering engine. It wraps a fontManager and exposes methods to render strings to ASCII art.
func NewASCIIRender ¶
func NewASCIIRender() *ASCIIRender
NewASCIIRender creates a new ASCIIRender with a fresh fontManager, preloaded with the embedded builtin fonts.
func (*ASCIIRender) LoadFont ¶
func (ar *ASCIIRender) LoadFont(fontPath string) error
LoadFont registers all *.flf font files found recursively under fontPath, making them available for later rendering by name. Fonts are discovered but not parsed until they are actually requested.
func (*ASCIIRender) Render ¶
func (ar *ASCIIRender) Render(str string) (string, error)
Render renders str using default RenderOptions (the default font, no color). It is a convenience wrapper around RenderOpts.
func (*ASCIIRender) RenderOpts ¶
func (ar *ASCIIRender) RenderOpts(str string, opt *RenderOptions) (string, error)
RenderOpts renders str as ASCII art according to opt, returning the fully composed multi-line output (including a trailing newline after each glyph row). It returns an error if opt.FontName cannot be found, or if str contains a rune outside the printable ASCII range (0-127).
type AnsiColor ¶
type AnsiColor struct {
// contains filtered or unexported fields
}
AnsiColor is a standard 16-color ANSI terminal color.
var ( ColorBlack AnsiColor = AnsiColor{30} ColorRed AnsiColor = AnsiColor{31} ColorGreen AnsiColor = AnsiColor{32} ColorYellow AnsiColor = AnsiColor{33} ColorBlue AnsiColor = AnsiColor{34} ColorMagenta AnsiColor = AnsiColor{35} ColorCyan AnsiColor = AnsiColor{36} ColorWhite AnsiColor = AnsiColor{37} ColorHiBlack AnsiColor = AnsiColor{90} ColorHiRed AnsiColor = AnsiColor{91} ColorHiGreen AnsiColor = AnsiColor{92} ColorHiYellow AnsiColor = AnsiColor{93} ColorHiBlue AnsiColor = AnsiColor{94} ColorHiMagenta AnsiColor = AnsiColor{95} ColorHiCyan AnsiColor = AnsiColor{96} ColorHiWhite AnsiColor = AnsiColor{97} )
Standard 16-color ANSI terminal colors (normal intensity).
func (AnsiColor) GetColorCode ¶
GetColorCode returns the raw ANSI color code as a string, without any escape sequence wrapping.
type Banner ¶
type Banner struct {
// Title holds the banner's text segments. Segments are concatenated
// with no separator before rendering; each segment is colored
// independently via Colors.
Title []string
// Colors holds one color per Title segment, applied cyclically by
// index (segment i gets Colors[i % len(Colors)]). NewCmdBanner
// requires len(Colors) == len(Title).
Colors []Color
// FontName is the figlet font to render with, by name.
FontName string
// FontPath, if set, is an on-disk directory to load additional fonts
// from (in addition to the embedded builtin fonts) before rendering.
FontPath string
// TopPadding, if true, adds a single leading newline before the
// rendered output. It does not affect kerning or layout.
TopPadding bool
}
Banner holds configuration for rendering a multi-segment ASCII banner. Each entry in Title is rendered with the corresponding color from Colors.
func NewCmdBanner ¶
func NewCmdBanner(title []string, options ...BannerOptions) (*Banner, error)
NewCmdBanner creates a Banner with sensible defaults for CLI tool banners. Title entries represent command and subcommand names (e.g., ["cmd", "sub"]). Colors must match the number of Title entries.
type BannerOptions ¶
type BannerOptions func(b *Banner)
BannerOptions configures a Banner via the functional options pattern.
func WithColors ¶
func WithColors(colors ...string) BannerOptions
WithColors sets the color palette for each Title segment.
func WithFont ¶
func WithFont(f string) BannerOptions
WithFont sets the figlet font name to use for rendering.
func WithLocalFont ¶
func WithLocalFont(f string, p string) BannerOptions
WithLocalFont sets the font name and loads additional fonts from a local directory.
func WithZeroPadding ¶
func WithZeroPadding() BannerOptions
WithZeroPadding disables the leading newline added by default when TopPadding is true.
type Color ¶
Color wraps ANSI escape sequences for terminal coloring.
func ResolveColor ¶
ResolveColor returns a Color by named lookup or hex string (#RRGGBB). Falls back to TrueColorPink206 if the input is unrecognized.
type NoColor ¶
type NoColor struct{}
NoColor is a no-op Color that produces no escape sequences.
ColorNone is the no-op Color; using it renders text without any ANSI color escape sequences.
func (NoColor) GetColorCode ¶
GetColorCode returns an empty string; NoColor has no underlying code.
type RenderOptions ¶
type RenderOptions struct {
// FontName selects the font to render with. If the named font
// cannot be found, RenderOpts returns an error.
FontName string
// FontColor, if non-empty, is applied cyclically across the
// characters of the rendered string (character i gets
// FontColor[i % len(FontColor)]). If empty, no color is applied.
FontColor []Color
}
RenderOptions configures a single ASCIIRender.RenderOpts call: which font to render with, and optionally a per-character color cycle.
func NewRenderOptions ¶
func NewRenderOptions() *RenderOptions
NewRenderOptions creates a new RenderOptions with FontName set to defaultFont ("standard") and no FontColor.
type TrueColor ¶
type TrueColor struct {
// contains filtered or unexported fields
}
TrueColor is a 24-bit RGB terminal color.
var ( TrueColorPink206 TrueColor = TrueColor{/* contains filtered or unexported fields */} TrueColorYellowNeon TrueColor = TrueColor{/* contains filtered or unexported fields */} TrueColorGold TrueColor = TrueColor{/* contains filtered or unexported fields */} )
Preset 24-bit TrueColor values used as defaults elsewhere in the package (e.g. Colors["default"], NewCmdBanner's default palette).
func NewTrueColorFromHexString ¶
NewTrueColorFromHexString returns a TrueColor parsed from a hex string.
func (TrueColor) GetColorCode ¶
GetColorCode returns the raw ANSI 24-bit color code as a string, without any escape sequence wrapping.