]>
git.proxmox.com Git - mirror_xterm.js.git/blob - demo/main.js
6 var terminalContainer
= document
.getElementById('terminal-container');
8 cursorBlink
: document
.querySelector('#option-cursor-blink')
11 optionElements
.cursorBlink
.addEventListener('change', createTerminal
);
15 function createTerminal() {
16 while (terminalContainer
.children
.length
) {
17 terminalContainer
.removeChild(terminalContainer
.children
[0]);
20 cursorBlink
: optionElements
.cursorBlink
.checked
22 protocol
= (location
.protocol
=== 'https:') ? 'wss://' : 'ws://';
23 socketURL
= protocol
+ location
.hostname
+ ((location
.port
) ? (':' + location
.port
) : '') + '/bash';
24 socket
= new WebSocket(socketURL
);
26 term
.open(terminalContainer
);
29 socket
.onopen
= runRealTerminal
;
30 socket
.onclose
= runFakeTerminal
;
31 socket
.onerror
= runFakeTerminal
;
35 function runRealTerminal() {
37 term
._initialized
= true;
40 function runFakeTerminal() {
41 if (term
._initialized
) {
45 term
._initialized
= true;
47 var shellprompt
= '$ ';
49 term
.prompt = function () {
50 term
.write('\r\n' + shellprompt
);
53 term
.writeln('Welcome to xterm.js');
54 term
.writeln('This is a local terminal emulation, without a real terminal in the back-end.');
55 term
.writeln('Type some keys and commands to play around.');
59 term
.on('key', function (key
, ev
) {
61 !ev
.altKey
&& !ev
.altGraphKey
&& !ev
.ctrlKey
&& !ev
.metaKey
64 if (ev
.keyCode
== 13) {
66 } else if (ev
.keyCode
== 8) {
68 * Do not delete the prompt
73 } else if (printable
) {
78 term
.on('paste', function (data
, ev
) {