asciiart

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2025 License: MIT Imports: 10 Imported by: 0

README

⭐   the project to show your appreciation. :arrow_upper_right:

ASCII ART for Go

Description

Prints beautiful ASCII art from text. It supports FIGlet files, and most of its features.

This package is a fork of go-figure.

UPDATES: go.mod support was added, the API was cleaned up, and font-loading was done as plugins to save memory.

Installation

go get github.com/romance-dev/ascii-art

Adding new fonts

If you have a *.flf file for a font, you can create a plugin by following the simple template found in the /fonts sub-directory.

The plugin must call: RegisterFont("<font name identifier>", font) inside an func init().

To load the font, you can blank import it the plugin package.

Basic Example

package main

import(
    "github.com/romance-dev/ascii-art"
    _ "github.com/romance-dev/ascii-art/fonts" // load all fonts
    // _ "github.com/romance-dev/ascii-art/fonts/alphabet" // load a specific font
)

func main() {
  myFigure := asciiart.NewFigure("Hello World", "", true)
  myFigure.Print()
}
  _   _          _   _          __        __                 _       _ 
 | | | |   ___  | | | |   ___   \ \      / /   ___    _ __  | |   __| |
 | |_| |  / _ \ | | | |  / _ \   \ \ /\ / /   / _ \  | '__| | |  / _` |
 |  _  | |  __/ | | | | | (_) |   \ V  V /   | (_) | | |    | | | (_| |
 |_| |_|  \___| |_| |_|  \___/     \_/\_/     \___/  |_|    |_|  \__,_|

You can also make colorful figures:

func main() {
  myFigure := asciiart.NewColorFigure("Hello World", "", asciiart.Green, true)
  myFigure.Print()
}

More Examples

asciiart.NewFigure("Go-Figure", "isometric1", true).Print()

      ___           ___           ___                       ___           ___           ___           ___     
     /\  \         /\  \         /\  \          ___        /\  \         /\__\         /\  \         /\  \    
    /::\  \       /::\  \       /::\  \        /\  \      /::\  \       /:/  /        /::\  \       /::\  \   
   /:/\:\  \     /:/\:\  \     /:/\:\  \       \:\  \    /:/\:\  \     /:/  /        /:/\:\  \     /:/\:\  \  
  /:/  \:\  \   /:/  \:\  \   /::\~\:\  \      /::\__\  /:/  \:\  \   /:/  /  ___   /::\~\:\  \   /::\~\:\  \ 
 /:/__/_\:\__\ /:/__/ \:\__\ /:/\:\ \:\__\  __/:/\/__/ /:/__/_\:\__\ /:/__/  /\__\ /:/\:\ \:\__\ /:/\:\ \:\__\
 \:\  /\ \/__/ \:\  \ /:/  / \/__\:\ \/__/ /\/:/  /    \:\  /\ \/__/ \:\  \ /:/  / \/_|::\/:/  / \:\~\:\ \/__/
  \:\ \:\__\    \:\  /:/  /       \:\__\   \::/__/      \:\ \:\__\    \:\  /:/  /     |:|::/  /   \:\ \:\__\  
   \:\/:/  /     \:\/:/  /         \/__/    \:\__\       \:\/:/  /     \:\/:/  /      |:|\/__/     \:\ \/__/  
    \::/  /       \::/  /                    \/__/        \::/  /       \::/  /       |:|  |        \:\__\    
     \/__/         \/__/                                   \/__/         \/__/         \|__|         \/__/    

asciiart.NewFigure("Foo Bar Pop", "smkeyboard", true).Print()

 ____  ____  ____  ____  ____  ____  ____  ____  ____ 
||F ||||o ||||o ||||B ||||a ||||r ||||P ||||o ||||p ||
||__||||__||||__||||__||||__||||__||||__||||__||||__||
|/__\||/__\||/__\||/__\||/__\||/__\||/__\||/__\||/__\|

asciiart.NewFigure("Keep Your Eyes On Me", "rectangles", true).Print()

                                                                                          
 _____                 __ __                 _____                 _____       _____      
|  |  | ___  ___  ___ |  |  | ___  _ _  ___ |   __| _ _  ___  ___ |     | ___ |     | ___ 
|    -|| -_|| -_|| . ||_   _|| . || | ||  _||   __|| | || -_||_ -||  |  ||   || | | || -_|
|__|__||___||___||  _|  |_|  |___||___||_|  |_____||_  ||___||___||_____||_|_||_|_|_||___|
                 |_|                               |___|                                  

asciiart.NewFigure("ABCDEFGHIJ", "eftichess", true).Print()

#########         #########   ___   #########         #########                           
##[`'`']#  \`~'/  ##'\v/`##  /\*/\  ##|`+'|##  '\v/`  ##\`~'/##  [`'`']   '\v/`    \`~'/  
###|  |##  (o o)  ##(o 0)## /(o o)\ ##(o o)##  (o 0)  ##(o o)##   |  |    (o 0)    (o o)  
###|__|##   \ / \ ###(_)###   (_)   ###(_)###   (_)   ###\ / \#   |__|     (_)      \ / \ 
#########    "    #########         #########         ####"####                      "    

Supported Fonts

  • 3-d
  • 3x5
  • 5lineoblique
  • acrobatic
  • alligator
  • alligator2
  • alphabet
  • avatar
  • banner
  • banner3-D
  • banner3
  • banner4
  • barbwire
  • basic
  • bell
  • big
  • bigchief
  • binary
  • block
  • bubble
  • bulbhead
  • calgphy2
  • calligraphy
  • catwalk
  • chunky
  • coinstak
  • colossal
  • computer
  • contessa
  • contrast
  • cosmic
  • cosmike
  • cricket
  • cursive
  • cyberlarge
  • cybermedium
  • cybersmall
  • diamond
  • digital
  • doh
  • doom
  • dotmatrix
  • drpepper
  • eftichess
  • eftifont
  • eftipiti
  • eftirobot
  • eftitalic
  • eftiwall
  • eftiwater
  • epic
  • fender
  • fourtops
  • fuzzy
  • goofy
  • gothic
  • graffiti
  • hollywood
  • invita
  • isometric1
  • isometric2
  • isometric3
  • isometric4
  • italic
  • ivrit
  • jazmine
  • jerusalem
  • katakana
  • kban
  • larry3d
  • lcd
  • lean
  • letters
  • linux
  • lockergnome
  • madrid
  • marquee
  • maxfour
  • mike
  • mini
  • mirror
  • mnemonic
  • morse
  • moscow
  • nancyj-fancy
  • nancyj-underlined
  • nancyj
  • nipples
  • ntgreek
  • o8
  • ogre
  • pawp
  • peaks
  • pebbles
  • pepper
  • poison
  • puffy
  • pyramid
  • rectangles
  • relief
  • relief2
  • rev
  • roman
  • rot13
  • rounded
  • rowancap
  • rozzo
  • runic
  • runyc
  • sblood
  • script
  • serifcap
  • shadow
  • short
  • slant
  • slide
  • slscript
  • small
  • smisome1
  • smkeyboard
  • smscript
  • smshadow
  • smslant
  • smtengwar
  • speed
  • stampatello
  • standard
  • starwars
  • stellar
  • stop
  • straight
  • tanja
  • tengwar
  • term
  • thick
  • thin
  • threepoint
  • ticks
  • ticksslant
  • tinker-toy
  • tombstone
  • trek
  • tsalagi
  • twopoint
  • univers
  • usaflag
  • wavy
  • weird

Documentation

Index

Constants

View Source
const (
	Black  = "black"
	Red    = "red"
	Green  = "green"
	Yellow = "yellow"
	Blue   = "blue"
	Purple = "purple"
	Cyan   = "cyan"
	Gray   = "gray"
	White  = "white"
)

Variables

This section is empty.

Functions

func RegisterFont

func RegisterFont(name string, font []byte)

RegisterFont registers a new font. Builtin fonts can be blank imported from the fonts sub-package individually or en masse.

func Write

func Write(w io.Writer, fig Figure)

Write outputs the figure to an arbitrary io.Writer.

Types

type Figure

type Figure struct {
	// contains filtered or unexported fields
}

func NewColorFigure

func NewColorFigure(phrase, font string, color string, strict bool) Figure

NewColorFigure converts a phrase to a Figure that can then be printed to an io.Writer (such as io.Stdout).

font must be loaded beforehand. The default is "standard" (provided it is already loaded).

color can be Red, Green, Yellow, Blue, Purple, Cyan, Gray or White.

If strict mode is enabled, then any unprintable ASCII characters will produce a panic. Otherwise, it will be replaced by a '?'.

func NewFigure

func NewFigure(phrase, font string, strict bool) Figure

NewFigure converts a phrase to a Figure that can then be printed to an io.Writer (such as io.Stdout).

font must be loaded beforehand. The default is "standard" (provided it is already loaded).

If strict mode is enabled, then any unprintable ASCII characters will produce a panic. Otherwise, it will be replaced by a '?'.

func (fig Figure) Blink(duration, timeOn, timeOff time.Duration)

Blink animates the figure with blinking. duration: total time the banner will display.

timeOn: duration of time the text will blink on.

timeOff: duration of time the text will blink off.

For an even blink, set `timeOff` to -1 (same as setting `timeOff` to the value of `timeOn`).

func (Figure) ColorString

func (fig Figure) ColorString() string

Returns the figure as a colored string.

func (Figure) Dance

func (fig Figure) Dance(duration, freeze time.Duration)

Dance writes the figure and animates it with "dancing".

duration: total time the banner will display.

freeze: duration of time between dance moves.

NOTE: The lower the freeze the faster the dancing.

func (Figure) Print

func (fig Figure) Print()

Print outputs the figure to io.Stdout.

func (Figure) Scroll

func (fig Figure) Scroll(duration, stillness time.Duration, direction string)

Scrolls writes the figure and then animates it with scrolling. duration: total time the banner will display.

stillness: duration of time the text will not move; the lower the stillness the faster the scroll speed.

direction: can be either "right" or "left".

func (Figure) Slicify

func (figure Figure) Slicify() (rows []string)

Slicify returns a slice of the figure.

func (Figure) String

func (fig Figure) String() string

Returns the figure as a string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL