aboutsummaryrefslogtreecommitdiffstats
path: root/functions.js
diff options
context:
space:
mode:
Diffstat (limited to 'functions.js')
-rw-r--r--functions.js58
1 files changed, 51 insertions, 7 deletions
diff --git a/functions.js b/functions.js
index 8b05e96..af88f49 100644
--- a/functions.js
+++ b/functions.js
@@ -1,12 +1,56 @@
-import Terminal from "node_modules/xterm/lib/xterm.js";
+// import { Terminal } from './node_modules/xterm/lib/xterm.js';
+import { Terminal } from "xterm";
-// we'll finish this some day
-// function createTerminal(rows, columns) {
-// var term = new Terminal({rows: rows, cols: columns});
-// term.open(document.getElementById('terminal'));
-// term.write('Hello from \x1B[1;3;31mxterm.js\x1B[0m $ ')
+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")