~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/media/console/console.js

  • Committer: dcoles
  • Date: 2008-08-07 07:32:36 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:991
Console: Some improvements to the python console code - most notably the 
addition of a reset button (which causes the console to restarted to a new 
python-console process). It won't work against everything (ie. if the console 
is so tied up it doesn't even respond, but should be good enough for 'I just 
want to clear everything' situations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
303
303
    var output = document.getElementById("console_output");
304
304
    if (res.hasOwnProperty('okay'))
305
305
    {
 
306
        // Success!
 
307
        if (res.okay)
 
308
        {
 
309
            output.appendChild(document.createTextNode(res.okay + "\n"));
 
310
            output.appendChild(span);
 
311
        }
306
312
        // set the prompt to >>>
307
 
        var prompt = document.getElementById("console_prompt");
308
 
        prompt.replaceChild(document.createTextNode(">>> "), prompt.firstChild);
 
313
        set_prompt(">>>");
309
314
    }
310
315
    else if (res.hasOwnProperty('exc'))
311
316
    {
312
317
        // Failure!
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);
 
320
        
318
321
        // set the prompt to >>>
319
 
        var prompt = document.getElementById("console_prompt");
320
 
        prompt.replaceChild(document.createTextNode(">>> "), prompt.firstChild);
 
322
        set_prompt(">>>");
321
323
    }
322
324
    else if (res.hasOwnProperty('restart') && res.hasOwnProperty('key'))
323
325
    {
328
330
 
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);
 
334
        
335
335
        // set the prompt to >>>
336
 
        var prompt = document.getElementById("console_prompt");
337
 
        prompt.replaceChild(document.createTextNode(">>> "), prompt.firstChild);
338
 
 
 
336
        set_prompt(">>>");
339
337
    }
340
338
    else if (res.hasOwnProperty('more'))
341
339
    {
342
340
        // Need more input, so set the prompt to ...
343
 
        var prompt = document.getElementById("console_prompt");
344
 
        prompt.replaceChild(document.createTextNode("... "), prompt.firstChild);
 
341
        set_prompt("...");
345
342
    }
346
343
    else if (res.hasOwnProperty('output'))
347
344
    {
375
372
        // Return early, so we don't re-enable the input box.
376
373
        return;
377
374
    }
378
 
    else {
 
375
    else
 
376
    {
379
377
        // assert res.hasOwnProperty('input')
380
 
        var prompt = document.getElementById("console_prompt");
381
 
        prompt.replaceChild(document.createTextNode("+++ "), prompt.firstChild);
 
378
        set_prompt("...");
382
379
    }
383
380
 
384
381
    if (inputbox != null)
396
393
    divScroll.activeScroll();
397
394
 
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();
401
398
}
402
399
 
403
400
function catch_input(key)
456
453
    }
457
454
}
458
455
 
 
456
/** Resets the console by signalling the old console to expire and starting a 
 
457
 * new one.
 
458
 */
 
459
function console_reset()
 
460
{
 
461
    // FIXME: We show some feedback here - either disable input or at very 
 
462
    // least the reset button.
 
463
 
 
464
    // Restart the console
 
465
    if(!server_started)
 
466
    {
 
467
        start_server(null);
 
468
    }
 
469
    else
 
470
    {
 
471
        xhr = ajax_call(null, "consoleservice", "restart", {"key": server_key}, "POST");
 
472
        console_response(null, null, null, xhr.responseText);
 
473
    }
 
474
}
 
475
 
 
476
/** Prints an error line in the console **/
 
477
function print_error(error)
 
478
 
479
    var output = document.getElementById("console_output");
 
480
  
 
481
    // Create text block
 
482
    var span = document.createElement("span");
 
483
    span.setAttribute("class", "errorMsg");
 
484
    span.appendChild(document.createTextNode(error + "\n"));
 
485
    output.appendChild(span);
 
486
 
 
487
    // Autoscroll
 
488
    divScroll.activeScroll();
 
489
}
 
490
 
 
491
/** Sets the prompt text **/
 
492
function set_prompt(prompt_text)
 
493
{
 
494
    var prompt = document.getElementById("console_prompt");
 
495
    prompt.replaceChild(document.createTextNode(prompt_text + " "), prompt.firstChild);
 
496
}
 
497
 
459
498
/**** Following Code modified from ******************************************/
460
499
/**** http://radio.javaranch.com/pascarello/2006/08/17/1155837038219.html ***/
461
500
/****************************************************************************/
473
512
        
474
513
    if (scrollDiv.scrollHeight > 0)
475
514
        currentHeight = scrollDiv.scrollHeight;
476
 
    else 
477
 
        if (objDiv.offsetHeight > 0)
478
 
            currentHeight = scrollDiv.offsetHeight;
 
515
    else if (scrollDiv.offsetHeight > 0)
 
516
        currentHeight = scrollDiv.offsetHeight;
479
517
 
480
518
    scrollDiv.scrollTop = currentHeight;
481
519