1

How can i submit a command without pressing the enter button? I need to make the terminal recognize the speech (that part is already done) and visualize it like a command, than virtually press enter to get an ajax response, is it possible? thanks

jcubic
  • 61,973
  • 54
  • 229
  • 402

1 Answers1

0

push create new interpreter when you have new prompt and new set of commands, to execute the command you can use exec:

term.exec('command');

it will echo the command and execute your command (if you pass true as second argument it will not echo prompt and command being executed), for instancec if you have:

var term = $('...').terminal({
  foo: function() {
    this.echo('foo');
  }
});

term.exec('foo');

will execute your foo function.

or you can simulate keydown event for enter:

var e = $.Event("keydown");
e.ctrlKey = ctrl;
e.altKey = alt;
e.shiftKey = shift;
e.which = e.keyCode = 13;
$(document.documentElement || window).trigger(e);

if you're adding text using term.insert('word'); it will be better to use key down event.

EDIT: key down event may not work with a recent version of jQuery Terminal to trigger the event with jQuery events look at Jest tests.

jcubic
  • 61,973
  • 54
  • 229
  • 402