mirror of
https://git.proxmox.com/git/mirror_xterm.js
synced 2025-10-05 01:48:08 +00:00

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.
33 lines
715 B
JavaScript
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);
|
|
}
|
|
});
|