Here is the code that will enter text and press enter:
terminal.insert("Hello");
var e = $.Event("keydown");
e.ctrlKey = false;
e.which = e.keyCode = 13;
$(document.documentElement || window).trigger(e);
instead of terminal::insert
you can also simulate entering text using jQuery events:
function enter(text) {
var e;
var $root = $(document.documentElement || window);
for (var i=0; i<text.length; ++i) {
e = $.Event("keypress");
e.which = text.charCodeAt(i);
$root.trigger(e);
}
}
NOTE: The code that bind keypress and keydown is in cmd
plugin at the end:
$(document.documentElement || window).bind('keypress.cmd', function(e) {
...
}).bind('keydown.cmd', keydown_event);
keydown_event is main function that process all short cuts and keypress is to enter text.
If you want to test what's inside terminal last echo text will be in:
terminal.find('.terminal-output div:last').html()
and the line before that will be prompt + text you enter (I should add specific class for those lines).
Also if you want to handle terminal formatting you will need to look at the rules of formatting in $.terminal.format function, it create span
for each formatting with inline style, class and attributes. Testing for html instead of text will give you better results I think. The line with prompt will not have formatting as spans they appear as text.