aboutsummaryrefslogtreecommitdiffstats
path: root/functions.js
blob: af88f499776c23dfdf8945f35908390dea2c9bde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// import { Terminal } from './node_modules/xterm/lib/xterm.js'; 
import { Terminal } from "xterm"; 

var terminal        = new Terminal({rows: 48, cols: 140});
var termPrompt      = '$ ';
var command         = '';
var backspaceLimit  = 2;

terminal.open(document.getElementById('terminal'));
terminal.write('Welcome to Featherfall Containers!');

terminal.writePrompt = function() {
    terminal.write('\r\n' + termPrompt);
};

terminal.on('key',
    function (key, eVal) {
        var isPrintable = (
            !eVal.metaKey && !eVal.altKey && !eVal.ctrlKey
        );

        switch (ev.key) {
            case 'Enter':
                if (command == 'clear') {
                    terminal.clear();
                }

                command = '';

                terminal.writePrompt();
                break;
            case 'Backspace':
                console.log(terminal.rows);

                if (terminal.x > backspaceLimit) {
                    terminal.write('\b \b');
                }
                break;
            default:
                if (isPrintable) {
                    command += key;
                    terminal.write(key);
                }
                break;
        }
    }
);

terminal.on('paste', 
    function (copiedData, eVal) {
        terminal.write(copiedData);
    }
);

function toStudentView() {
    location.replace("index.html")
}
function logOut(){
    location.replace("login.html")
}