How to easily print ascii-art text?

  • pyfiglet – pure Python implementation of http://www.figlet.org pip install pyfiglet
  • termcolor – helper functions for ANSI color formatting pip install termcolor
  • colorama – multiplatform support (Windows) pip install colorama
import sys

from colorama import init
init(strip=not sys.stdout.isatty()) # strip colors if stdout is redirected
from termcolor import cprint 
from pyfiglet import figlet_format

cprint(figlet_format('missile!', font='starwars'),
       'yellow', 'on_red', attrs=['bold'])

Example

$ python print-warning.py 
$ python print-warning.py | cat
.___  ___.  __       _______.     _______. __   __       _______  __
|   \/   | |  |     /       |    /       ||  | |  |     |   ____||  |
|  \  /  | |  |    |   (----`   |   (----`|  | |  |     |  |__   |  |
|  |\/|  | |  |     \   \        \   \    |  | |  |     |   __|  |  |
|  |  |  | |  | .----)   |   .----)   |   |  | |  `----.|  |____ |__|
|__|  |__| |__| |_______/    |_______/    |__| |_______||_______|(__)

Leave a Comment