1

I have jQuery.terminal embedded on my page and I am able to send commands by typing into it. I have numerous console.log and console.dir commands inside the script I am working on, I would like the terminal to also output those but it doesn't.

I was thinking it might be something like what the guys on this SO question did; by overriding console.log:

Embed JS Console within website

I would like to do something like this with jQuery.terminal

console.log=function(str){term.echo(str);};

I can't see how it is suppose to work. As I am failing to access the terminal through Chromes console (I can't find the part that does the echo).

var log;

$('#term').terminal(function(command,term){
    if(command!==''){
        try{
            var result=window.eval(command);
            if(result!==undefined){
                term.echo(new String(result));
                }}
        catch(e){
            term.error(new String(e));
            }}
    else{
        term.echo('');
        }},{
    welcome:false,
    height:200,
    prompt:'> ',
    onInit:function(term){
        log=term;                 // now log should reference to term
        alert('hello');           // I don't see this alert
        }});

console.log('hello');     //only the browsers own console shows this message

Then if I manually type into Chromes console:

log.echo('hi'); // Cannot read property 'echo' of undefined

I see there is a $.terminal object but, I don't see a way to access echo from this ether. How do I do this properly or rather is there a defined way the developers have set to do this that I am missing? I don't want to mess up comma separated logs or dir objects.

Community
  • 1
  • 1
Ben Muircroft
  • 2,936
  • 8
  • 39
  • 66

1 Answers1

0

Plugin return terminal instance so you should do something like:

var term = $('#term').terminal(function(command,term) {
 ...
}, {...});

console.log = function(str){ term.echo(str); };

also if you want to access current terminal you can use:

var term = $.terminal.active();
jcubic
  • 61,973
  • 54
  • 229
  • 402