Golang : Add ASCII art to command line application launching process




Problem : You worked hard on creating your application and you want add some ASCII art to prettify the launching process or simply want to make your program --help description pretty with a banner, version number, your name and etc.

For example :

a command line application with banner

Solution : Use github.com/common-nighthawk/go-figure package to add ASCII art in your application.

In case, you don't want your program to depend on external font .flf files, embed the font directly in your program as a constant and use strings.NewReader() function to load the font directly.

Here you go!


 package main

 import (
  "strings"

  figure "github.com/common-nighthawk/go-figure"
 )

 func main() {

  // basic stuff
  banner := figure.NewFigure("Hello World", "", true)
  banner.Print()

  // with isometric2 font
  // see the list of available fonts at
  // https://github.com/common-nighthawk/go-figure/tree/master/fonts
  banner2 := figure.NewFigure("Hello World2", "isometric2", true)
  banner2.Print()

  // in case you need to use your own font.
  // OR you just want to deploy your executable file WITHOUT including
  // the Figlet .flf font file.

  figure.NewFigureWithFont("My Awesome Program!!!", strings.NewReader(SubZeroFont), true).Print()

 }

 // Source :
 // https://raw.githubusercontent.com/xero/figlet-fonts/master/Sub-Zero.flf

 var SubZeroFont = `
 flf2a$ 6 5 17 -1 16

 "Sub-Zero" font by Sub-Zero
 ==============================


 -> Conversion to FigLet font by MEPH. (Part of ASCII Editor Service Pack I)
 (http://studenten.freepage.de/meph/ascii/ascii/editor/_index.htm)
 -> Defined: ASCII code alphabet
 -> Uppercase characters only.

 ScarecrowsASCIIArtArchive1.0.txt
 From: "Sub-Zero" <bodom@papaya.ucs.indiana.edu>
 "Here's a font I've been working on lately.  Can someone make the V, Q, and X
 look better?  Also, the B, P, and R could use an improvement too.
 Oh, here it is."

 $$$@
 $$$@
 $$$@
 $$$@
 $$$@
 $$$@@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
  ______ @
 /\  __ \ @
 \ \  __ \  @
  \ \_\ \_\ @
 \/_/\/_/ @
 @@
  ______ @
 /\  == \ @
 \ \  __< @
  \ \_____\ @
 \/_____/ @
 @@
  ______ @
 /\  ___\ @
 \ \ \____  @
  \ \_____\ @
 \/_____/ @
 @@
  _____ @
 /\  __-.  @
 \ \ \/\ \ @
  \ \____- @
 \/____/ @
 @@
  ______ @
 /\  ___\ @
 \ \  __\ @
  \ \_____\ @
 \/_____/ @
 @@
  ______  @
 /\  ___\ @
 \ \  __\ @
  \ \_\ @
 \/_/ @
 @@
  ______ @
 /\  ___\ @
 \ \ \__ \  @
  \ \_____\ @
 \/_____/ @
 @@
  __  __ @
 /\ \_\ \ @
 \ \  __ \  @
  \ \_\ \_\ @
 \/_/\/_/ @
 @@
  __ @
 /\ \ @
 \ \ \  @
  \ \_\ @
 \/_/ @
 @@
 __ @
 /\ \ @
  _\_\ \  @
 /\_____\ @
 \/_____/ @
 @@
  __  __ @
 /\ \/ / @
 \ \  _"-.  @
  \ \_\ \_\ @
 \/_/\/_/ @
 @@
  __ @
 /\ \ @
 \ \ \____  @
  \ \_____\ @
 \/_____/ @
 @@
  __ __ @
 /\ "-./  \ @
 \ \ \-./\ \  @
  \ \_\ \ \_\ @
 \/_/  \/_/ @
 @@
  __ __ @
 /\ "-.\ \ @
 \ \ \-.  \  @
  \ \_\\"\_\ @
 \/_/ \/_/ @
 @@
  ______ @
 /\  __ \ @
 \ \ \/\ \  @
  \ \_____\ @
 \/_____/ @
 @@
  ______  @
 /\  == \ @
 \ \  _-/ @
  \ \_\ @
 \/_/ @
 @@
  ______ @
 /\  __ \ @
 \ \ \/\_\  @
  \ \___\_\ @
 \/___/_/ @
 @@
  ______ @
 /\  == \ @
 \ \  __< @
  \ \_\ \_\ @
 \/_/ /_/ @
 @@
  ______ @
 /\  ___\ @
 \ \___  \  @
  \/\_____\ @
 \/_____/ @
 @@
  ______  @
 /\__  _\ @
 \/_/\ \/ @
 \ \_\ @
 \/_/ @
 @@
  __  __ @
 /\ \/\ \ @
 \ \ \_\ \  @
  \ \_____\ @
 \/_____/ @
 @@
  __ __  @
 /\ \ / /  @
 \ \ \'/ @
  \ \__| @
 \/_/ @
 @@
  __ __ @
 /\ \  _ \ \ @
 \ \ \/ ".\ \  @
  \ \__/".~\_\ @
 \/_/ \/_/ @
 @@
  __  __ @
 /\_\_\_\ @
 \/_/\_\/_  @
 /\_\/\_\ @
 \/_/\/_/ @
 @@
  __  __ @
 /\ \_\ \ @
 \ \____ \  @
  \/\_____\ @
 \/_____/ @
 @@
  ______ @
 /\___  \ @
 \/_/  /__  @
 /\_____\ @
 \/_____/ @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
  ______ @
 /\  __ \ @
 \ \  __ \  @
  \ \_\ \_\ @
 \/_/\/_/ @
 @@
  ______ @
 /\  == \ @
 \ \  __< @
  \ \_____\ @
 \/_____/ @
 @@
  ______ @
 /\  ___\ @
 \ \ \____  @
  \ \_____\ @
 \/_____/ @
 @@
  _____ @
 /\  __-.  @
 \ \ \/\ \ @
  \ \____- @
 \/____/ @
 @@
  ______ @
 /\  ___\ @
 \ \  __\ @
  \ \_____\ @
 \/_____/ @
 @@
  ______  @
 /\  ___\ @
 \ \  __\ @
  \ \_\ @
 \/_/ @
 @@
  ______ @
 /\  ___\ @
 \ \ \__ \  @
  \ \_____\ @
 \/_____/ @
 @@
  __  __ @
 /\ \_\ \ @
 \ \  __ \  @
  \ \_\ \_\ @
 \/_/\/_/ @
 @@
  __ @
 /\ \ @
 \ \ \  @
  \ \_\ @
 \/_/ @
 @@
 __ @
 /\ \ @
  _\_\ \  @
 /\_____\ @
 \/_____/ @
 @@
  __  __ @
 /\ \/ / @
 \ \  _"-.  @
  \ \_\ \_\ @
 \/_/\/_/ @
 @@
  __ @
 /\ \ @
 \ \ \____  @
  \ \_____\ @
 \/_____/ @
 @@
  __ __ @
 /\ "-./  \ @
 \ \ \-./\ \  @
  \ \_\ \ \_\ @
 \/_/  \/_/ @
 @@
  __ __ @
 /\ "-.\ \ @
 \ \ \-.  \  @
  \ \_\\"\_\ @
 \/_/ \/_/ @
 @@
  ______ @
 /\  __ \ @
 \ \ \/\ \  @
  \ \_____\ @
 \/_____/ @
 @@
  ______  @
 /\  == \ @
 \ \  _-/ @
  \ \_\ @
 \/_/ @
 @@
  ______ @
 /\  __ \ @
 \ \ \/\_\  @
  \ \___\_\ @
 \/___/_/ @
 @@
  ______ @
 /\  == \ @
 \ \  __< @
  \ \_\ \_\ @
 \/_/ /_/ @
 @@
  ______ @
 /\  ___\ @
 \ \___  \  @
  \/\_____\ @
 \/_____/ @
 @@
  ______  @
 /\__  _\ @
 \/_/\ \/ @
 \ \_\ @
 \/_/ @
 @@
  __  __ @
 /\ \/\ \ @
 \ \ \_\ \  @
  \ \_____\ @
 \/_____/ @
 @@
  __ __  @
 /\ \ / /  @
 \ \ \'/ @
  \ \__| @
 \/_/ @
 @@
  __ __ @
 /\ \  _ \ \ @
 \ \ \/ ".\ \  @
  \ \__/".~\_\ @
 \/_/ \/_/ @
 @@
  __  __ @
 /\_\_\_\ @
 \/_/\_\/_  @
 /\_\/\_\ @
 \/_/\/_/ @
 @@
  __  __ @
 /\ \_\ \ @
 \ \____ \  @
  \/\_____\ @
 \/_____/ @
 @@
  ______ @
 /\___  \ @
 \/_/  /__  @
 /\_____\ @
 \/_____/ @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 @
 @
 @
 @
 @
 @@
 `

Happy coding!

Reference :

https://github.com/common-nighthawk/go-figure

  See also : Golang : Image to ASCII art example





By Adam Ng(黃武俊)

IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.


Advertisement