mirror of
https://git.proxmox.com/git/mirror_xterm.js
synced 2025-10-04 21:16:40 +00:00
32 lines
704 B
JavaScript
32 lines
704 B
JavaScript
var terminalContainer = document.getElementById('terminal-container'),
|
|
term = new Terminal(),
|
|
prompt = '> ';
|
|
|
|
term.open(terminalContainer);
|
|
term.fit();
|
|
|
|
term.prompt = function () {
|
|
term.write('\r\n' + prompt);
|
|
};
|
|
|
|
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);
|
|
}
|
|
}); |