Skip to content

Instantly share code, notes, and snippets.

@loxaxs
Created May 6, 2019 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loxaxs/5a318bc347fb7c77c2757cc7011ae468 to your computer and use it in GitHub Desktop.
Save loxaxs/5a318bc347fb7c77c2757cc7011ae468 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# (Advice: use IPython)
# Dependencies:
# sudo -H pip3 install plumbum art
from plumbum import cmd as c
from art import text2art
ponyList = (c.ponysay["+A"] | c.sed["s/\x1b\[[0-9;]*m//g;s/(.*)//g"] | c.grep["-v", "located"])().split()
font="basic"
tHeight, tWidth = map(int, c.stty["size"].run_tee()[1].split())
tHeight -= 10
print()
def chunk(l, n):
"""Yield successive n-sized chunks from l."""
for i in range(0, len(l), n):
yield l[i:i + n]
try:
# Group (unique) pony names into chunks
for ponyChunk in chunk(sorted(set(ponyList))[60:], 4):
# Get text art from the pony names. Truncate it to the terminal width
textart = [line[:tWidth] for line in text2art(" ".join(ponyChunk), font=font).split("\n")]
remainingHeight = tHeight - textart.count("\n") - 1
frameChunk = []
for pony in ponyChunk:
# Get the pony image ponysay
image = c.ponysay("-oF", pony).split("\n")[:-1]
# Remove the colors through sed, split lines, get the 3rd line, get its length and create
# a string of spaces of the same length to be used as filler at the bottom of the image
filler = (len((c.sed["s/\x1b\\[[0-9;]*m//g"] << image[3])()) - 1) * " "
frameBottom = (remainingHeight - len(image)) * [filler]
# For each pony image, add the filler at the bottom of the image
frame = image + frameBottom
frameChunk.append(frame)
lineMatrix = zip(*frameChunk)
print("\n".join(textart + ["".join(lineList) for lineList in lineMatrix]))
import time; time.sleep(0.8)
except KeyboardInterrupt: pass
print(c.clear())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment