JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
738d7d7f965e16f25901b806743a544dfa0fa740
[watch-my-terminal.git] / index.html
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4         <title>Remote Terminal Viewer</title>
5         <script src="/jquery.js"></script>
6         <script src="/terminal.js"></script>
7         <script src="/socket.io/socket.io.js"></script>
8         <script>
9                 $(function() {
10                         var term = null;
11                         // 8-14 are bolded versions
12                         var palette = [
13                                 '2e3436',
14                                 'cc0000',
15                                 '4e9a06',
16                                 'c4a000',
17                                 '3465a4',
18                                 '75507b',
19                                 '06989a',
20                                 'd3d7cf',
21                                 '555753',
22                                 'ef2929',
23                                 '8ae234',
24                                 'fce94f',
25                                 '729fcf',
26                                 'ad7fa8',
27                                 '34e2e2',
28                                 'eeeeec',
29
30                                 // 256 colors
31                                 '000000',
32                                 '00005f',
33                                 '000087',
34                                 '0000af',
35                                 '0000d7',
36                                 '0000ff',
37                                 '005f00',
38                                 '005f5f',
39                                 '005f87',
40                                 '005faf',
41                                 '005fd7',
42                                 '005fff',
43                                 '008700',
44                                 '00875f',
45                                 '008787',
46                                 '0087af',
47                                 '0087d7',
48                                 '0087ff',
49                                 '00af00',
50                                 '00af5f',
51                                 '00af87',
52                                 '00afaf',
53                                 '00afd7',
54                                 '00afff',
55                                 '00d700',
56                                 '00d75f',
57                                 '00d787',
58                                 '00d7af',
59                                 '00d7d7',
60                                 '00d7ff',
61                                 '00ff00',
62                                 '00ff5f',
63                                 '00ff87',
64                                 '00ffaf',
65                                 '00ffd7',
66                                 '00ffff',
67                                 '5f0000',
68                                 '5f005f',
69                                 '5f0087',
70                                 '5f00af',
71                                 '5f00d7',
72                                 '5f00ff',
73                                 '5f5f00',
74                                 '5f5f5f',
75                                 '5f5f87',
76                                 '5f5faf',
77                                 '5f5fd7',
78                                 '5f5fff',
79                                 '5f8700',
80                                 '5f875f',
81                                 '5f8787',
82                                 '5f87af',
83                                 '5f87d7',
84                                 '5f87ff',
85                                 '5faf00',
86                                 '5faf5f',
87                                 '5faf87',
88                                 '5fafaf',
89                                 '5fafd7',
90                                 '5fafff',
91                                 '5fd700',
92                                 '5fd75f',
93                                 '5fd787',
94                                 '5fd7af',
95                                 '5fd7d7',
96                                 '5fd7ff',
97                                 '5fff00',
98                                 '5fff5f',
99                                 '5fff87',
100                                 '5fffaf',
101                                 '5fffd7',
102                                 '5fffff',
103                                 '870000',
104                                 '87005f',
105                                 '870087',
106                                 '8700af',
107                                 '8700d7',
108                                 '8700ff',
109                                 '875f00',
110                                 '875f5f',
111                                 '875f87',
112                                 '875faf',
113                                 '875fd7',
114                                 '875fff',
115                                 '878700',
116                                 '87875f',
117                                 '878787',
118                                 '8787af',
119                                 '8787d7',
120                                 '8787ff',
121                                 '87af00',
122                                 '87af5f',
123                                 '87af87',
124                                 '87afaf',
125                                 '87afd7',
126                                 '87afff',
127                                 '87d700',
128                                 '87d75f',
129                                 '87d787',
130                                 '87d7af',
131                                 '87d7d7',
132                                 '87d7ff',
133                                 '87ff00',
134                                 '87ff5f',
135                                 '87ff87',
136                                 '87ffaf',
137                                 '87ffd7',
138                                 '87ffff',
139                                 'af0000',
140                                 'af005f',
141                                 'af0087',
142                                 'af00af',
143                                 'af00d7',
144                                 'af00ff',
145                                 'af5f00',
146                                 'af5f5f',
147                                 'af5f87',
148                                 'af5faf',
149                                 'af5fd7',
150                                 'af5fff',
151                                 'af8700',
152                                 'af875f',
153                                 'af8787',
154                                 'af87af',
155                                 'af87d7',
156                                 'af87ff',
157                                 'afaf00',
158                                 'afaf5f',
159                                 'afaf87',
160                                 'afafaf',
161                                 'afafd7',
162                                 'afafff',
163                                 'afd700',
164                                 'afd75f',
165                                 'afd787',
166                                 'afd7af',
167                                 'afd7d7',
168                                 'afd7ff',
169                                 'afff00',
170                                 'afff5f',
171                                 'afff87',
172                                 'afffaf',
173                                 'afffd7',
174                                 'afffff',
175                                 'd70000',
176                                 'd7005f',
177                                 'd70087',
178                                 'd700af',
179                                 'd700d7',
180                                 'd700ff',
181                                 'd75f00',
182                                 'd75f5f',
183                                 'd75f87',
184                                 'd75faf',
185                                 'd75fd7',
186                                 'd75fff',
187                                 'd78700',
188                                 'd7875f',
189                                 'd78787',
190                                 'd787af',
191                                 'd787d7',
192                                 'd787ff',
193                                 'd7af00',
194                                 'd7af5f',
195                                 'd7af87',
196                                 'd7afaf',
197                                 'd7afd7',
198                                 'd7afff',
199                                 'd7d700',
200                                 'd7d75f',
201                                 'd7d787',
202                                 'd7d7af',
203                                 'd7d7d7',
204                                 'd7d7ff',
205                                 'd7ff00',
206                                 'd7ff5f',
207                                 'd7ff87',
208                                 'd7ffaf',
209                                 'd7ffd7',
210                                 'd7ffff',
211                                 'ff0000',
212                                 'ff005f',
213                                 'ff0087',
214                                 'ff00af',
215                                 'ff00d7',
216                                 'ff00ff',
217                                 'ff5f00',
218                                 'ff5f5f',
219                                 'ff5f87',
220                                 'ff5faf',
221                                 'ff5fd7',
222                                 'ff5fff',
223                                 'ff8700',
224                                 'ff875f',
225                                 'ff8787',
226                                 'ff87af',
227                                 'ff87d7',
228                                 'ff87ff',
229                                 'ffaf00',
230                                 'ffaf5f',
231                                 'ffaf87',
232                                 'ffafaf',
233                                 'ffafd7',
234                                 'ffafff',
235                                 'ffd700',
236                                 'ffd75f',
237                                 'ffd787',
238                                 'ffd7af',
239                                 'ffd7d7',
240                                 'ffd7ff',
241                                 'ffff00',
242                                 'ffff5f',
243                                 'ffff87',
244                                 'ffffaf',
245                                 'ffffd7',
246                                 'ffffff',
247                                 '080808',
248                                 '121212',
249                                 '1c1c1c',
250                                 '262626',
251                                 '303030',
252                                 '3a3a3a',
253                                 '444444',
254                                 '4e4e4e',
255                                 '585858',
256                                 '626262',
257                                 '6c6c6c',
258                                 '767676',
259                                 '808080',
260                                 '8a8a8a',
261                                 '949494',
262                                 '9e9e9e',
263                                 'a8a8a8',
264                                 'b2b2b2',
265                                 'bcbcbc',
266                                 'c6c6c6',
267                                 'd0d0d0',
268                                 'dadada',
269                                 'e4e4e4',
270                                 'eeeeee'
271                         ];
272                         var $body = $('body');
273                         var socket = io.connect('http://localhost');
274                         var color_to_css = function(i) {
275                                 index = i & 0xff
276                                 // lighten the basic 8 colors when they're bold
277                                 if (i & 0x10000 && index < 8) {
278                                         index += 8;
279                                 }
280                                 return 'color: #' + palette[index] + '; ';
281                         };
282                         var bg_color_to_css = function(i) {
283                                 return 'background-' + color_to_css((i&0x10000) | ((i&0xff00) >> 8));
284                         };
285                         var stylize = function (txt, style) {
286                                 if (txt.length == 0 || style == 0) {
287                                         return txt
288                                 }
289                                 css = ''
290                                 if (style & 0x10000) css += 'font-weight: bold; ';
291                                 if (style & 0x20000) css += 'text-decoration: underline; ';
292                                 if (style & 0x40000) css += 'text-decoration: underline; '; // blink
293                                 if (style & 0x80000) css += 'text-decoration: line-through; '; // invisible
294                                 if (style & 0x000ff) css += color_to_css(style);
295                                 if (style & 0x0ff00) css += bg_color_to_css(style);
296                                 return $('<span style="'+css+'"></span>').text(txt);
297                         };
298                         var redraw_wait = false;
299                         var redraw_again = false;
300                         var redraw_now = function () {
301                                 $body.children().remove();
302                                 for (i in term.text) {
303                                         div = $('<div>');
304                                         txt = ''
305                                         a = 0;
306                                         for (j in term.text[i]) {
307                                                 if (term.attributes[i][j] != a) {
308                                                         if (txt.length) {
309                                                                 div.append(stylize(txt, a));
310                                                                 txt = ''
311                                                         }
312                                                         a = term.attributes[i][j]
313                                                 }
314                                                 txt += term.text[i][j]
315                                         }
316                                         if(txt.length) {
317                                                 div.append(stylize(txt, a));
318                                         }
319                                         $body.append(div);
320                                 }
321                         }
322                         // limit to 50fps
323                         var redraw = function () {
324                                 if (redraw_wait) {
325                                         redraw_again = true;
326                                 } else {
327                                         redraw_now()
328                                         redraw_wait = true;
329                                         redraw_again = false;
330                                         setTimeout(function () {
331                                                 redraw_wait = false;
332                                                 if(redraw_again) {
333                                                         redraw_again = false;
334                                                         redraw();
335                                                 }
336                                         }, 20);
337                                 }
338                         }
339                         var update = function (data) {
340                                 if (term) {
341                                         term.update(data);
342                                         redraw();
343                                 }
344                         };
345
346                         socket.on('data', function (data) {
347                                 update(data);
348                         });
349                         socket.on('init', function (v) {
350                                 term = terminal.new(v.width, v.height);
351                                 term.x = v.x;
352                                 term.y = v.y;
353                                 term.a = v.a;
354                                 term.text = v.text;
355                                 term.attributes = v.attributes;
356                                 redraw();
357                         });
358                 });
359         </script>
360         <style>
361                 body {
362                         color: #d3d7cf;
363                         background: #2e3436;
364                         font-family: monospace;
365                         font-size: 12px;
366                         line-height: 14px;
367                         white-space: pre;
368                 }
369         </style>
370 </head>
371 <body>
372 </body>
373 </html>