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);
312
306
// set the prompt to >>>
307
var prompt = document.getElementById("console_prompt");
308
prompt.replaceChild(document.createTextNode(">>> "), prompt.firstChild);
315
310
else if (res.hasOwnProperty('exc'))
318
313
// print out the error message (res.exc)
319
print_error(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);
321
318
// set the prompt to >>>
319
var prompt = document.getElementById("console_prompt");
320
prompt.replaceChild(document.createTextNode(">>> "), prompt.firstChild);
324
322
else if (res.hasOwnProperty('restart') && res.hasOwnProperty('key'))
331
329
// Print a reason to explain why we'd do such a horrible thing
332
330
// (console timeout, server error etc.)
333
print_error("Console Restart: " + res.restart);
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);
335
335
// set the prompt to >>>
336
var prompt = document.getElementById("console_prompt");
337
prompt.replaceChild(document.createTextNode(">>> "), prompt.firstChild);
338
340
else if (res.hasOwnProperty('more'))
340
342
// Need more input, so set the prompt to ...
343
var prompt = document.getElementById("console_prompt");
344
prompt.replaceChild(document.createTextNode("... "), prompt.firstChild);
343
346
else if (res.hasOwnProperty('output'))
372
375
// Return early, so we don't re-enable the input box.
377
379
// assert res.hasOwnProperty('input')
380
var prompt = document.getElementById("console_prompt");
381
prompt.replaceChild(document.createTextNode("+++ "), prompt.firstChild);
381
384
if (inputbox != null)
393
396
divScroll.activeScroll();
395
398
// Focus the input box by default
396
document.getElementById("console_output").focus();
397
document.getElementById("console_inputText").focus();
399
document.getElementById("console_output").focus()
400
document.getElementById("console_inputText").focus()
400
403
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);
498
459
/**** Following Code modified from ******************************************/
499
460
/**** http://radio.javaranch.com/pascarello/2006/08/17/1155837038219.html ***/
500
461
/****************************************************************************/
513
474
if (scrollDiv.scrollHeight > 0)
514
475
currentHeight = scrollDiv.scrollHeight;
515
else if (scrollDiv.offsetHeight > 0)
516
currentHeight = scrollDiv.offsetHeight;
477
if (objDiv.offsetHeight > 0)
478
currentHeight = scrollDiv.offsetHeight;
518
480
scrollDiv.scrollTop = currentHeight;