LEFT | RIGHT |
1 // Copyright 2012 The Go Authors. All rights reserved. | 1 // Copyright 2012 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 (function() { | 5 (function() { |
6 "use strict"; | 6 "use strict"; |
7 | 7 |
8 var websocket, outputs = {}; | 8 var websocket, outputs = {}; |
9 | 9 |
10 function showMessage(o, m, className) { | 10 function showMessage(o, m, className) { |
11 var span = document.createElement("span"); | 11 var span = document.createElement("span"); |
12 var needScroll = (o.scrollTop + o.offsetHeight) == o.scrollHeight | 12 var needScroll = (o.scrollTop + o.offsetHeight) == o.scrollHeight; |
13 m = m.replace(/&/g, "&"); | 13 m = m.replace(/&/g, "&"); |
14 m = m.replace(/</g, "<"); | 14 m = m.replace(/</g, "<"); |
15 span.innerHTML = m; | 15 span.innerHTML = m; |
16 span.className = className; | 16 span.className = className; |
17 o.appendChild(span); | 17 o.appendChild(span); |
18 if (needScroll && o.scrollByLines) | 18 if (needScroll) |
19 o.scrollByLines(1) | 19 o.scrollTop = o.scrollHeight - o.offsetHeight; |
20 } | 20 } |
21 | 21 |
22 function onMessage(e) { | 22 function onMessage(e) { |
23 var m = JSON.parse(e.data); | 23 var m = JSON.parse(e.data); |
24 var o = outputs[m.Id]; | 24 var o = outputs[m.Id]; |
25 if (o === null) { | 25 if (o === null) { |
26 return; | 26 return; |
27 } | 27 } |
28 if (m.Kind === "stdout" || m.Kind === "stderr") { | 28 if (m.Kind === "stdout" || m.Kind === "stderr") { |
29 showMessage(o, m.Body, m.Kind); | 29 showMessage(o, m.Body, m.Kind); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 init(play[i]); | 132 init(play[i]); |
133 } | 133 } |
134 if (play.length > 0) { | 134 if (play.length > 0) { |
135 // TODO(adg): pass the host and port through from gopresent | 135 // TODO(adg): pass the host and port through from gopresent |
136 websocket = new WebSocket("ws://localhost:3999/socket"); | 136 websocket = new WebSocket("ws://localhost:3999/socket"); |
137 websocket.onmessage = onMessage; | 137 websocket.onmessage = onMessage; |
138 websocket.onclose = onClose; | 138 websocket.onclose = onClose; |
139 } | 139 } |
140 | 140 |
141 })(); | 141 })(); |
LEFT | RIGHT |