Created
February 7, 2019 01:30
-
-
Save spyoungtech/14753add9b640785efb768ef3729211f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import builtins | |
from textwrap import dedent | |
from unittest import mock | |
from contextlib import contextmanager | |
from itertools import cycle | |
_print = builtins.print | |
TEMPLATE_HEART = dedent(''' | |
#### #### | |
# # # # | |
# # # | |
# # | |
# # | |
# # | |
# # | |
# # | |
# | |
''') | |
def to_hearts(text): | |
chars = cycle(list(text)) | |
num_hearts = (len(text) // len(TEMPLATE_HEART)) + 1 | |
for heart in range(num_hearts): | |
lines = [] | |
for line in TEMPLATE_HEART.split('\n'): | |
while '#' in line: | |
line = line.replace('#', next(chars), 1) | |
lines.append(line) | |
yield '\n'.join(lines) | |
def _lovely_print(*things_to_print, **kwargs): | |
things_to_print = list(things_to_print) | |
for thing in things_to_print: | |
for heart in to_hearts(thing): | |
_print(heart, **kwargs) | |
@contextmanager | |
def lovely_print(*args, **kwargs): | |
with mock.patch('builtins.print', new=_lovely_print) as m: | |
yield m | |
if __name__ == '__main__': | |
with lovely_print(): | |
print('Hello World!') | |
print('I do not like', 'green eggs and ham') | |
print('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment