Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
200 lines (174 sloc) 5.04 KB
<!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>