1
digest_constant = "hello";
7
/* Starts the console server.
8
* Returns an object with fields "host", "port", "magic" describing the
11
function start_server()
13
var xhr = ajax_call("consoleservice", "start", {}, "POST");
14
var json_text = xhr.responseText;
15
return JSON.parse(json_text);
20
/* Start the server */
21
var server_info = start_server();
22
server_host = server_info.host;
23
server_port = server_info.port;
24
server_magic = server_info.magic;
27
/* Below here imported from trunk/console/console.js
41
function historyDown()
43
if (this.cursor < this.items.length)
49
function historyCurr()
51
if (this.cursor < 0 || this.cursor >= this.items.length)
55
return this.items[this.cursor];
58
function historyAdd(text)
60
this.items[this.items.length] = text;
61
this.cursor = this.items.length;
64
function historyShow()
67
if (this.cursor == -1)
71
for (var i = 0; i < this.items.length; i++)
77
res += this.items[i].toString();
84
if (this.cursor == this.items.length)
93
this.items = new Array();
96
this.down = historyDown;
97
this.curr = historyCurr;
98
this.add = historyAdd;
99
this.show = historyShow;
102
var hist = new History();
104
function enter_line()
106
var inp = document.getElementById('inputText');
107
var digest = hex_md5(inp.value + magic);
108
var args = {"host": server_host, "port": server_port,
109
"digest":digest, "text":inp.value};
110
var xmlhttp = ajax_call("consoleservice", "chat", args, "POST");
112
var res = JSON.parse(xmlhttp.responseText);
113
var output = document.getElementById("output");
115
var pre = document.createElement("pre");
116
pre.setAttribute("class", "inputMsg");
117
pre.appendChild(document.createTextNode(inp.value + "\n"));
118
output.appendChild(pre);
120
if (res.hasOwnProperty('okay'))
123
// print out the output (res.okay[0])
124
var pre = document.createElement("pre");
125
pre.setAttribute("class", "outputMsg");
126
pre.appendChild(document.createTextNode(res.okay[0]));
127
output.appendChild(pre);
128
// print out the return value (res.okay[1])
131
var pre = document.createElement("pre");
132
pre.setAttribute("class", "outputMsg");
133
pre.appendChild(document.createTextNode(res.okay[1] + "\n"));
134
output.appendChild(pre);
136
// set the prompt to >>>
137
var prompt = document.getElementById("prompt");
138
prompt.replaceChild(document.createTextNode(">>> "), prompt.firstChild);
140
else if (res.hasOwnProperty('exc'))
143
// print out the error message (res.exc)
144
var pre = document.createElement("pre");
145
pre.setAttribute("class", "errorMsg");
146
pre.appendChild(document.createTextNode(res.exc));
147
output.appendChild(pre);
149
else if (res.hasOwnProperty('more'))
151
// Need more input, so set the prompt to ...
152
var prompt = document.getElementById("prompt");
153
prompt.replaceChild(document.createTextNode("... "), prompt.firstChild);
156
// assert res.hasOwnProperty('input')
157
var prompt = document.getElementById("prompt");
158
prompt.replaceChild(document.createTextNode("+++ "), prompt.firstChild);
162
function catch_input(key)
164
var inp = document.getElementById('inputText');
169
inp.value = hist.curr();
174
inp.value = hist.curr();
179
inp.value = hist.curr();