#!/usr/bin/env python3 import os, sys, random from os.path import dirname, realpath, exists import ponysay import argparse, textwrap if __name__ == '__main__': termwidth = 80 try: termwidth = os.get_terminal_size()[0] except: pass parser = argparse.ArgumentParser(description='Cowsay with ponies') parser.add_argument('-p', '--pony', type=str, default='random', help='The name of the pony to be used. Use "-p list" to list all ponies, "-p random" (default) to use a random pony.') parser.add_argument('-q', '--quote', action='store_true', help='Use a random quote of the pony being displayed as text') parser.add_argument('-c', '--center', action='store_true', help='Use a random quote of the pony being displayed as text') parser.add_argument('-C', '--center-text', action='store_true', help='Center the text in the bubble') parser.add_argument('-w', '--width', type=int, default=termwidth, help='Terminal width. Use 0 for unlimited width. Default: autodetect') parser.add_argument('-b', '--balloon', type=str, default='cowsay', help='Balloon style to use. Use "-b list" to list available styles.') parser.add_argument('text', type=str, nargs='*', help='The text to be placed in the speech bubble') args = parser.parse_args() think = sys.argv[0].endswith('think') if args.pony == "list": print('\n'.join(sorted(ponysay.list_ponies() if not args.quote else ponysay.list_ponies_with_quotes()))) sys.exit() if args.balloon == 'list': print('\n'.join([ s.replace('.think', '') for s in ponysay.balloonstyles.keys() if s.endswith('.think') == think ])) sys.exit() pony = args.pony if pony == "random": pony = random.choice(ponysay.list_ponies() if not args.quote else ponysay.list_ponies_with_quotes()) text = ' '.join(args.text) or None if text == '-': text = '\n'.join(sys.stdin.readlines()) if args.quote: text = ponysay.random_quote(pony) balloonstyle = None if think: balloonstyle = ponysay.balloonstyles[args.balloon+'.think'] else: balloonstyle = ponysay.balloonstyles[args.balloon] print(ponysay.render_pony(pony, text, balloonstyle=balloonstyle, width=args.width or sys.maxint, center=args.center, centertext=args.center_text))