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

Implemented fit method for Terminal objects, which: - Fits the terminal's columns to its parent element width - Fits the terminal's rows to its parent element height
27 lines
636 B
JavaScript
27 lines
636 B
JavaScript
var terminalContainer = document.getElementById('terminal-container'),
|
|
term = new Terminal();
|
|
|
|
term.open(terminalContainer);
|
|
term.fit();
|
|
|
|
term.prompt = function () {
|
|
term.write('\r\n> ');
|
|
}
|
|
|
|
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.keyIdentifier == 'Enter') {
|
|
ev.preventDefault();
|
|
term.prompt();
|
|
} else if (ev.keyCode == 8) {
|
|
term.write('\b \b');
|
|
} else if (printable) {
|
|
term.write(key);
|
|
}
|
|
}); |