2

I have question, how can i add value in Jquery Terminal? Something like this:

jQuery(function($, undefined) {
 $('#terminal').terminal(function(command) {
     if(command == 'test ' + value) { // Value (something a user wrote)
        alert(value);
     }else{
     alert("You don't wrote anything."); 
     }

 }, {
 greetings: 'Hello.',
 name: 'Name',
 prompt: 'Terminal> ',
 color: 'some color'
 });
});

I mean something like this:

if(command == 'you type ' + userText) { 
alert(userText); 
} else { 
alert("You don't wrote anything."); 
}
jcubic
  • 61,973
  • 54
  • 229
  • 402

1 Answers1

0

You can do two things if value is previous command you can save it in variabe like this:

jQuery(function($, undefined) {
    var prev_command = '';
    $('#terminal').terminal(function(command) {
        if (command == 'test ' + prev_command) {
           alert(value);
        } else {
           alert("You don't wrote anything."); 
        }
        prev_command = command;
    }, {
       greetings: 'Hello.',
       name: 'Name',
       prompt: 'Terminal> '
  });
});

or you can use push:

jQuery(function($, undefined) {
   $('#terminal').terminal(function(command) {
      var value = command;
      this.push(function(command) {
        if (command == 'test ' + value) {
           alert(value);
        } else {
           alert("You don't wrote anything."); 
        }
        term.pop();
      });
   }, {
      greetings: 'Hello.',
      name: 'Name',
      prompt: 'Terminal> '
   });
});
jcubic
  • 61,973
  • 54
  • 229
  • 402