mirror_xterm.js/demo/main.js
Jean Bruenn d516d4df7c Update main.js
just a tiny change, if you are using the demo file as example to start working with, prompt as variable might cause trouble if you do use prompt() rather use shellprompt as variable name instead of prompt. I'd suggest to rename term's prompt() as well to not cause confusion.
2015-09-08 14:08:44 +02:00

33 lines
715 B
JavaScript

var terminalContainer = document.getElementById('terminal-container'),
term = new Terminal(),
shellprompt = '> ';
term.open(terminalContainer);
term.fit();
term.prompt = function () {
term.write('\r\n' + shellprompt);
};
term.writeln('Welcome to xterm.js');
term.writeln('Just type some keys in the prompt below.');
term.writeln('');
term.prompt();
term.on('key', function (key, ev) {
var printable = (!ev.altKey && !ev.altGraphKey && !ev.ctrlKey && !ev.metaKey);
if (ev.keyCode == 13) {
term.prompt();
} else if (ev.keyCode == 8) {
/*
* Do not delete the prompt
*/
if (term.x > 2) {
term.write('\b \b');
}
} else if (printable) {
term.write(key);
}
});