303
303
var output = document.getElementById("console_output");
304
304
if (res.hasOwnProperty('okay'))
309
output.appendChild(document.createTextNode(res.okay + "\n"));
310
output.appendChild(span);
306
312
// set the prompt to >>>
307
var prompt = document.getElementById("console_prompt");
308
prompt.replaceChild(document.createTextNode(">>> "), prompt.firstChild);
310
315
else if (res.hasOwnProperty('exc'))
313
318
// print out the error message (res.exc)
314
var span = document.createElement("span");
315
span.setAttribute("class", "errorMsg");
316
span.appendChild(document.createTextNode(res.exc + "\n"));
317
output.appendChild(span);
319
print_error(res.exc);
318
321
// set the prompt to >>>
319
var prompt = document.getElementById("console_prompt");
320
prompt.replaceChild(document.createTextNode(">>> "), prompt.firstChild);
322
324
else if (res.hasOwnProperty('restart') && res.hasOwnProperty('key'))
329
331
// Print a reason to explain why we'd do such a horrible thing
330
332
// (console timeout, server error etc.)
331
var span = document.createElement("span");
332
span.setAttribute("class", "errorMsg");
333
span.appendChild(document.createTextNode("Console Restart: " + res.restart + "\n"));
334
output.appendChild(span);
333
print_error("Console Restart: " + res.restart);
335
335
// set the prompt to >>>
336
var prompt = document.getElementById("console_prompt");
337
prompt.replaceChild(document.createTextNode(">>> "), prompt.firstChild);
340
338
else if (res.hasOwnProperty('more'))
342
340
// Need more input, so set the prompt to ...
343
var prompt = document.getElementById("console_prompt");
344
prompt.replaceChild(document.createTextNode("... "), prompt.firstChild);
346
343
else if (res.hasOwnProperty('output'))
375
372
// Return early, so we don't re-enable the input box.
379
377
// assert res.hasOwnProperty('input')
380
var prompt = document.getElementById("console_prompt");
381
prompt.replaceChild(document.createTextNode("+++ "), prompt.firstChild);
384
381
if (inputbox != null)
396
393
divScroll.activeScroll();
398
395
// Focus the input box by default
399
document.getElementById("console_output").focus()
400
document.getElementById("console_inputText").focus()
396
document.getElementById("console_output").focus();
397
document.getElementById("console_inputText").focus();
403
400
function catch_input(key)
456
/** Resets the console by signalling the old console to expire and starting a
459
function console_reset()
461
// FIXME: We show some feedback here - either disable input or at very
462
// least the reset button.
464
// Restart the console
471
xhr = ajax_call(null, "consoleservice", "restart", {"key": server_key}, "POST");
472
console_response(null, null, null, xhr.responseText);
476
/** Prints an error line in the console **/
477
function print_error(error)
479
var output = document.getElementById("console_output");
482
var span = document.createElement("span");
483
span.setAttribute("class", "errorMsg");
484
span.appendChild(document.createTextNode(error + "\n"));
485
output.appendChild(span);
488
divScroll.activeScroll();
491
/** Sets the prompt text **/
492
function set_prompt(prompt_text)
494
var prompt = document.getElementById("console_prompt");
495
prompt.replaceChild(document.createTextNode(prompt_text + " "), prompt.firstChild);
459
498
/**** Following Code modified from ******************************************/
460
499
/**** http://radio.javaranch.com/pascarello/2006/08/17/1155837038219.html ***/
461
500
/****************************************************************************/
474
513
if (scrollDiv.scrollHeight > 0)
475
514
currentHeight = scrollDiv.scrollHeight;
477
if (objDiv.offsetHeight > 0)
478
currentHeight = scrollDiv.offsetHeight;
515
else if (scrollDiv.offsetHeight > 0)
516
currentHeight = scrollDiv.offsetHeight;
480
518
scrollDiv.scrollTop = currentHeight;