forked from Connorhd/node_debug
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
199 lines (174 loc) · 5.04 KB
/
index.html
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/>
<title>Node</title>
<link rel="stylesheet" href="jquery.treeview.css" />
<link rel="stylesheet" href="screen.css" />
<script src="jquery.js" type="text/javascript"></script>
<script src="jquery.cookie.js" type="text/javascript"></script>
<script src="jquery.treeview.js" type="text/javascript"></script>
<script src="jquery.treeview.async.js" type="text/javascript"></script>
<script type="text/javascript">
// Generate an ID to distinguish requests from other open consoles
var id = Math.floor(Math.random()*10000);
$(document).ready(function (){
$.ajaxSetup({ cache: false });
var linesCurrent = 0;
var lines = [];
$("#input").keydown(function (e) {
// Deal with up/down arrowkeys
if (e.keyCode == 38) {
if (linesCurrent == lines.length) {
if ($("#input").val() != '') {
lines.push($("#input").val());
}
} else if ($("#input").val() != lines[linesCurrent]) {
lines.push($("#input").val());
}
if (linesCurrent > 0) {
linesCurrent--;
$("#input").val(lines[linesCurrent]);
}
return false;
} else if (e.keyCode == 40) {
if (linesCurrent == lines.length) {
if ($("#input").val() != '') {
lines.push($("#input").val());
linesCurrent++;
$("#input").val('');
}
} else {
if ($("#input").val() != lines[linesCurrent]) {
lines.push($("#input").val());
}
linesCurrent++;
if (lines[linesCurrent] != null) {
$("#input").val(lines[linesCurrent]);
} else {
$("#input").val('');
}
}
return false;
}
if (e.keyCode != 13 /* Return */) return;
lines.push($("#input").val());
linesCurrent = lines.length;
var msg = $("#input").val().replace("\n", "");
//if (!util.isBlank(msg)) send(msg);
evalStr(msg);
$("#input").attr("value", ""); // clear the input field.
});
longPollConsole();
});
function evalStr (str) {
// TODO This should be a POST
$.getJSON("/eval?id="+id+"&eval="+encodeURIComponent(str),
function (data) {
var response;
if (data.error !== true) {
response = '<div class="response">'
+ ' <code class="command">'+data.str+'</code>'
+ ' <ul class="tree" id="cmd_'+data.cmd+'"></ul>'
+ '</div>'
;
} else {
response = '<div class="response error">'
+ ' <code class="command">'+data.str+'</code>'
+ ' <code class="result">Error: '+data.result.message+'</code>'
+ ' <pre class="stack">' + data.result.stack + '</pre>'
+ '</div>'
;
}
$("#console").prepend(response);
if (data.error !== true) {
$("#cmd_"+data.cmd).treeview({
url: "/tree?cmd="+data.cmd+"&id="+id,
unique: true
});
}
});
}
function longPollConsole() {
$.getJSON("/console?id="+id,
function(data){
$.each(data, function(i, x) {
response = '<div class="response">'
+ ' <ul class="tree" id="cmd_'+x+'"></ul>'
+ '</div>'
;
$("#console").prepend(response);
$("#cmd_"+x).treeview({
url: "/tree?cmd="+x+"&id="+id,
unique: true
});
});
longPollConsole();
});
}
</script>
<style type="text/css">
#console {
overflow: auto;
width: 100%;
bottom: 0;
top: 4em;
position: absolute;
}
#input {
width: 100%;
font-size: inherit;
margin: 0;
border-width: 0;
border-bottom: 0.5em solid #aaa;
background: #eee;
outline-width: 0;
clear: both;
height: 1.5em;
}
/* Padding for response and input should be same. */
#input, .response {
padding: 1em;
font-size: inherit;
}
.response {
border-bottom: 1px dashed grey;
}
.error {
background: #ebb;
}
.response .command {
display: block;
}
.response .result {
display: block;
font-weight: bold;
}
code, pre {
max-height: 200px;
overflow: auto;
font-family: "Lucida Console", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", Consolas, "Andale Mono", "Courier New";
padding: 10px;
margin: 0;
}
pre.result {
padding: 0;
}
.type {
width: 6em;
color: #888;
display: block;
float: left;
}
body {
overflow: hidden;
}
</style>
</head>
<body>
<div id="inputBar">
<input tabindex="1" type="text" id="input"/>
</div>
<div id="console"></div>
</body>
</html>