-
Notifications
You must be signed in to change notification settings - Fork 1
/
goatse
executable file
·187 lines (159 loc) · 5.94 KB
/
goatse
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/env python
"""
* g o a t s e x * g o a t s e x * g o a t s e x *
g g
o / \ \ / \ o
a| | \ | | a
t| `. | | : t
s` | | \| | s
e \ | / / \\\ --__ \\ : e
x \ \/ _--~~ ~--__| \ | x
* \ \_-~ ~-_\ | *
g \_ \ _.--------.______\| | g
o \ \______// _ ___ _ (_(__> \ | o
a \ . C ___) ______ (_(____> | / a
t /\ | C ____)/ \ (_____> |_/ t
s / /\| C_____) hello | (___> / \ s
e | ( _C_____)\______/ // _/ / \ e
x | \ |__ \\_________// (__/ | x
* | \ \____) `---- --' | *
g | \_ ___\ /_ _/ | g
o | / | | \ | o
a | | / \ \ | a
t | / / | | \ |t
s | / / \__/\___/ | |s
e | / | | | |e
x | | | | | |x
* g o a t s e x * g o a t s e x * g o a t s e x *
"""
import sys
import re
import terminalsize as terminal
header = """
* g o a t s e x * g o a t s e x * g o a t s e x *
g g
o / \ \ / \ o
a| | \ | | a
t| `. | | : t
s` | | \| | s
e \ | / / \\\ --__ \\ : e
x \ \/ _--~~ ~--__| \ | x
* \ \_-~ ~-_\ | *
g \_ \ _.--------.______\| | g
o \ \______// _ ___ _ (_(__> \ | o
a \ . C ___) ______ (_(____> | / a
t /\ | C ____)/ \ (_____> |_/ t"""
left_decal = """
* g o a t s e x * g o a t s e x * g o a t s e x *
g g
o / \
a| |
t| `.
s` |
e \ | /
x \ \/
* \ \_-~
g \_ \
o \ \______
a \ . C ___)
t /\ | C ____)
s / /\| C_____)
e | ( _C_____)
x | \ |__
* | \ \____)
g | \_
o |
a |
t |
s |
e |
x |
* g o a t s e x * g o a t s e x * g o a t s e x *
"""
right_decal = """
g
\ o
| a
: t
| s
: e
\ | x
_\ | *
.______\| | g
(_(__> \ | o
(_(____> | / a
(_____> |_/ t
(___> / \ s
_/ / \ e
(__/ | x
| *
_/ | g
| o
| a
|t
|s
|e
|x
* g o a t s e x * g o a t s e x * g o a t s e x *
"""
footer = """
g | \_ ___\ /_ _/ | g
o | / | | \ | o
a | | / \ \ | a
t | / / | | \ |t
s | / / \__/\___/ | |s
e | / | | | |e
x | | | | | |x
* g o a t s e x * g o a t s e x * g o a t s e x *
"""
LEFT_EDGE_MARGIN = 24
RIGHT_EDGE_MARGIN = 21
LEFT_MARGIN = 23
RIGHT_MARGIN = 21
def get_terminal_size():
return terminal.get_terminal_size()
def get_viewport_width(terminal_size, margins):
if not isinstance(margins, list):
margins = [margins]
(terminal_width, terminal_heght) = terminal_size
margins = [(terminal_width - (left_margin + right_margin)) for (left_margin, right_margin) in margins]
if margins:
return min(margins)
return terminal_width
def render_left_aligned_line(line, viewport_width):
lines = []
width = 0
current_line = []
for word in line:
word_length = len(word)
if word_length > viewport_width:
# TODO split word
pass
elif (width + word_length + 1) < viewport_width:
current_line.append(word)
width += word_length + 1
else:
lines.append(current_line)
width = word_length
current_line = [word]
if current_line:
lines.append(current_line)
return lines
def render(lines, terminal_size, margins):
viewport_width = get_viewport_width(terminal_size, margins)
prepared_lines = []
for line in lines:
prepared_lines += render_left_aligned_line(line, viewport_width)
for line in prepared_lines:
print ' '.join(line)
def split_to_lines(args):
lines = []
for arg in args:
lines += map(lambda x: x.strip(), arg.split('\n'))
return [re.split(r'\s+', line) for line in lines]
def main():
terminal_size = get_terminal_size()
lines = split_to_lines(sys.argv[1:])
render(lines, terminal_size, [(LEFT_EDGE_MARGIN, RIGHT_EDGE_MARGIN), (LEFT_MARGIN, RIGHT_MARGIN)])
if __name__ == '__main__':
main()