-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathsnakesay.py
More file actions
executable file
·42 lines (30 loc) · 898 Bytes
/
snakesay.py
File metadata and controls
executable file
·42 lines (30 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3.5
import sys
import textwrap
MESSAGE = '\n'.join([
'',
'{bubble}',
' \\',
' ~<:>>>>>>>>>',
])
def snakesay(*things):
bubble = '\n'.join(speech_bubble_lines(' '.join(things)))
return MESSAGE.format(bubble=bubble)
def speech_bubble_lines(speech):
lines, width = rewrap(speech)
if len(lines) <= 1:
text = ''.join(lines)
yield '< {text} >'.format(text=text)
else:
yield ' ' + '_' * width
yield '/ ' + (' ' * width) + ' \\'
for line in lines:
yield '| {} |'.format(line)
yield '\\ ' + (' ' * width) + ' /'
yield ' ' + '-' * width
def rewrap(speech):
lines = textwrap.wrap(speech)
width = max(len(l) for l in lines) if lines else 0
return [line.ljust(width) for line in lines], width
if __name__ == '__main__':
print(snakesay(*sys.argv[1:]))