-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwmas
executable file
·270 lines (240 loc) · 7.72 KB
/
wmas
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/usr/bin/php
<?php
$menu = array(
"1" => "We",
"2" => "Make",
"3" => "Awesome",
"4" => "Sh.it",
"a" => false,
"5" => "Blog",
"6" => "Contact",
"b" => false,
"7" => "IRC",
"8" => "Git",
"9" => "Wiki"
);
$shortcuts = array(
"7" => "open https://www.irccloud.com/#!/ircs://irc.freenode.net:6697/%23wmas",
"8" => "open http://git.wmas.it",
"9" => "open http://wiki.wemakeawesomesh.it"
);
$method = $argv[1];
foreach($menu as $key => $val) {
if (strtolower($val) === strtolower($method)) {
if (isset($shortcuts[$key])) {
exec($shortcuts[$key]);
exit;
}
}
}
require_once('includes/tools.php');
function get_input() {
return trim(fgets(fopen ("php://stdin","r")));
}
function echo_line($str, $foreground = "light_gray", $background = "black") {
$colors = new Colors();
echo $colors->getColoredString($str,$foreground, $background)."\n";
}
class Colors {
private $foreground_colors = array();
private $background_colors = array();
public function __construct() {
// Set up shell colors
$this->foreground_colors['black'] = '0;30';
$this->foreground_colors['dark_gray'] = '1;30';
$this->foreground_colors['blue'] = '0;34';
$this->foreground_colors['light_blue'] = '1;34';
$this->foreground_colors['green'] = '0;32';
$this->foreground_colors['light_green'] = '1;32';
$this->foreground_colors['cyan'] = '0;36';
$this->foreground_colors['light_cyan'] = '1;36';
$this->foreground_colors['red'] = '0;31';
$this->foreground_colors['light_red'] = '1;31';
$this->foreground_colors['purple'] = '0;35';
$this->foreground_colors['light_purple'] = '1;35';
$this->foreground_colors['brown'] = '0;33';
$this->foreground_colors['yellow'] = '1;33';
$this->foreground_colors['light_gray'] = '0;37';
$this->foreground_colors['white'] = '1;37';
$this->background_colors['black'] = '40';
$this->background_colors['red'] = '41';
$this->background_colors['green'] = '42';
$this->background_colors['yellow'] = '43';
$this->background_colors['blue'] = '44';
$this->background_colors['magenta'] = '45';
$this->background_colors['cyan'] = '46';
$this->background_colors['light_gray'] = '47';
}
// Returns colored string
public function getColoredString($string, $foreground_color = null, $background_color = null) {
$colored_string = "";
// Check if given foreground color found
if (isset($this->foreground_colors[$foreground_color])) {
$colored_string .= "\033[" . $this->foreground_colors[$foreground_color] . "m";
}
// Check if given background color found
if (isset($this->background_colors[$background_color])) {
$colored_string .= "\033[" . $this->background_colors[$background_color] . "m";
}
// Add string and end coloring
$colored_string .= $string . "\033[0m";
return $colored_string;
}
// Returns all foreground color names
public function getForegroundColors() {
return array_keys($this->foreground_colors);
}
// Returns all background color names
public function getBackgroundColors() {
return array_keys($this->background_colors);
}
}
function ascii_art($file) {
if (!file_exists($file)) return;
try {
$img = imagecreatefromstring(file_get_contents($file));
} catch (Exception $e) {
return;
}
list($width, $height) = getimagesize($file);
$scale = 10;
$chars = array(
' ', '\'', '.', ':',
'|', 'T', 'X', '0',
'#',
);
$chars = array_reverse($chars);
$c_count = count($chars);
if ($width) {
for($y = 0; $y < 15; $y++) {
for($x = 0; $x < 30; $x++) {
$dw = $width / 30;
$dh = $height / 15;
$rgb = imagecolorat($img, $x * $dw, $y*$dh);
$r = (($rgb >> 16) & 0xFF);
$g = (($rgb >> 8) & 0xFF);
$b = ($rgb & 0xFF);
$sat = ($r + $g + $b) / (255 * 3);
echo $chars[ (int)( $sat * ($c_count - 1) ) ];
}
echo PHP_EOL;
}
}
}
echo_line("What would you like to do?", "light_red", null);
function display_column($str, $count, $foreground = null, $background = null) {
$colors = new Colors();
$line_width = 150;
$col_padding = 4;
$char_length = $line_width / $count;
$max_char_length = $char_length - $col_padding;
$display_string = "";
for ($i = 0; $i < $max_char_length;$i++) {
if (isset($str[$i])) $display_string .= $str[$i];
else $display_string .= " ";
}
for ($i = 0; $i < $col_padding; $i++) {
$display_string .= " ";
}
echo $colors->getColoredString($display_string, $foreground, $background);
}
function display_menu() {
global $menu;
$options = $menu;
foreach ($options as $key => $value) {
if ($value === false) echo "\n";
else echo_line("$key) $value", "white", null);
}
echo "\n";
while (true) {
echo echo_line( "Enter your choice here: (e.g. 1) ", "light_red", null);
$option = get_input();
if (trim($option) === "" || !isset($options[$option])) {
echo echo_line("ERROR: $option is not valid", "black", "red");
echo echo_line("You need to enter an available option", "black", "red");
} else break;
}
echo echo_line( "You selected ".$options[$option]."\n\n", "light_green", null);
return $option;
}
function respond($response) {
global $menu;
global $shortcuts;
switch($response) {
case "1":
$people = get_content("people");
foreach($people as $person) {
echo_line($person->name." (@".$person->handle.")", "light_gray");
ascii_art("build/assets/img/avatars/".$person->image);
echo "\n";
}
echo "\n".file_get_contents("content/we.md")."\n";
break;
case "2":
$count = 0;
$projects = get_content("projects");
$slugs = array();
foreach ($projects as $slug => $project) {
$slugs[] = $slug;
display_column(($count+1).") ".$project->title,3, "light_blue", null);
$count++;
if ($count%3 === 0) echo "\n";
}
echo "\n";
echo echo_line( "Which project: (e.g. 1) ", "light_red", null);
while (true) {
$option = get_input();
if (trim($option) === "" || !isset($projects->$slugs[$option-1])) {
echo echo_line("ERROR: $option is not valid", "black", "red");
echo echo_line("You need to enter an available option", "black", "red");
} else break;
}
$project = get_project($slugs[$option-1]);
echo_line($project->title);
if ($project->subtitle)
echo_line($project->subtitle);
echo_line($project->tags);
echo_line("");
if ($project->url) {
echo_line($project->url);
echo_line("");
}
if (file_exists("build/assets/img/".$project->image))
ascii_art("build/assets/img/".$project->image);
if (file_exists("content/projects/".$slugs[$option].".md"))
echo "\n".file_get_contents("content/projects/".$slugs[$option].".md")."\n";
else
echo $option->content;
break;
case "3":
echo "Show clients";
break;
case "4":
echo "Press responses";
break;
case "5":
exec("open http://wemakeawesomesh.tumblr.com");
break;
case "6":
exec("open mailto:[email protected]");
echo "✉ [email protected]\n";
echo "URL: http://wemakeawesomesh.it\n";
echo "T: @wemakeawesomesh\n";
echo "F: fb.com/wemakeawesomesh\n";
break;
default:
exec($shortcuts[$response]);
break;
}
}
while(true) {
$response = display_menu();
respond($response);
echo "\n";
echo "\n";
echo echo_line( "Would you like to continue? (Y/N)", "light_red", null);
$option = get_input();
if (strpos(strtolower($option), "y") === false) {
exit;
}
}