Skip to content

Instantly share code, notes, and snippets.

@sleepygarden
Last active December 22, 2015 18:59
Show Gist options
  • Save sleepygarden/6516359 to your computer and use it in GitHub Desktop.
Save sleepygarden/6516359 to your computer and use it in GitHub Desktop.
pretty print a justified banner with colorama
# auto banner
import colorama
from colorama import Fore, Back, init
if __name__ == "__init__":
init()
def print_banner(banner_lines, fg=Fore.WHITE, bg=Back.BLACK, offset=0):
'''
prints all lines in list "banner_lines" justified by <'s or >'s, with
at least "offset" of each on each side of a line.
fg and bg are foreground color and bg color, and use colorama color codes.
ex: print_banner(["Hello World!","sleepy 2013"], fg=Fore.BLUE, offset=5)
>>> <<<<< ~ Hello World! ~ >>>>>
<<<<< ~ sleepy 2013 ~ >>>>>>
'''
longest = 0
for line in banner_lines:
if len(line) > longest:longest=len(line)
for line in banner_lines:
line_offset = (longest-len(line))/2+offset
print fg+bg+line_offset*"<"+ " ~ "+line+" ~ "+line_offset*">"
print Fore.RESET
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment