Alex Rivera | Logout

How to easily print ascii-art text?

Asked 2012-03-09T11:05:43.003
66

I have a program that dumps a lot of output, and I want some of that output to really stand out. One way could be to render important text with ascii art, like this web service does for example:

 #    #   ##   #####  #    # # #    #  ####  
 #    #  #  #  #    # ##   # # ##   # #    # 
 #    # #    # #    # # #  # # # #  # #      
 # ## # ###### #####  #  # # # #  # # #  ### 
 ##  ## #    # #   #  #   ## # #   ## #    # 
 #    # #    # #    # #    # # #    #  ####  

other solutions could be colored or bold output. So how to do this sort of stuff easily in Python?

Edit
Report

1 Answer

110
  • 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 

missile

$ python print-warning.py | cat
.___  ___.  __       _______.     _______. __   __       _______  __
|   \/   | |  |     /       |    /       ||  | |  |     |   ____||  |
|  \  /  | |  |    |   (----`   |   (----`|  | |  |     |  |__   |  |
|  |\/|  | |  |     \   \        \   \    |  | |  |     |   __|  |  |
|  |  |  | |  | .----)   |   .----)   |   |  | |  `----.|  |____ |__|
|__|  |__| |__| |_______/    |_______/    |__| |_______||_______|(__)
answered 2012-03-09T17:38:33.080

Your Answer