aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TerminalWrapper.js78
-rw-r--r--index.html7
-rw-r--r--studentPage.html6
3 files changed, 89 insertions, 2 deletions
diff --git a/TerminalWrapper.js b/TerminalWrapper.js
new file mode 100644
index 0000000..c6cc9a4
--- /dev/null
+++ b/TerminalWrapper.js
@@ -0,0 +1,78 @@
+import Terminal from 'xterm';
+import 'xterm/lib/xterm.css';
+
+export class TerminalWrapper extends React.Component {
+ constructor() {
+ this.terminal = new Terminal();
+ this.command = "";
+ }
+
+ constructor(nrows, ncolumns) {
+ this.terminal = new Terminal({ rows: nrows, cols: ncolumns });
+ this.command = "";
+ }
+
+ attachTerminalTo(block) {
+ this.terminal.open(block);
+
+ // Default text
+ this.terminal.write("Welcome to Featherfall Software!");
+ this.writePrompt();
+ }
+
+ // Terminal writing functions
+ write(text) {
+
+ switch (text) {
+ // text is Enter
+ case '\r':
+ if (this.command == 'clear') {
+ this.clear();
+ }
+
+ this.command = "";
+ this.writePrompt();
+ break;
+
+ // text is Backspace
+ case '\u007F':
+ if (this.command.length > 0) {
+ this.command = this.command.substring(0, this.command.length - 1);
+ this.terminal.write('\b \b');
+ }
+ break;
+
+ // text is Ctrl+C
+ case '\u0003':
+ this.terminal.write('^C');
+ this.writePrompt();
+ break;
+
+ default:
+ if ((text <= String.fromCharCode(0x7B) && text.String.fromCharCode(0x20)) || text >= '\u00a0') {
+ this.command += text;
+ this.terminal.write(text);
+ }
+ break;
+ }
+
+ }
+
+ writePrompt() {
+ this.terminal.writeln('');
+ this.terminal.write('$ ');
+ }
+
+ clear() {
+ this.terminal.clear();
+ }
+
+ // Socket functions for connecting the terminal to server
+ beginListening() {
+
+ }
+
+ sendUsrInput() {
+
+ }
+} \ No newline at end of file
diff --git a/index.html b/index.html
index bd5c973..947b8aa 100644
--- a/index.html
+++ b/index.html
@@ -63,7 +63,12 @@
var termPrompt = "$ ";
var command = "";
term.open(document.getElementById("terminal"));
- term.write("Hello from \x1B[1;3;31mxterm.js\x1B[0m $ ");
+
+ term.write("Welcome to Featherfall Software!");
+ term.writeln('');
+ term.write(termPrompt);
+
+ //handles typing in terminal
term.onKey(function (key) {
//console.log("Key is '" + key.key + "'");
diff --git a/studentPage.html b/studentPage.html
index 770d7c4..7980d53 100644
--- a/studentPage.html
+++ b/studentPage.html
@@ -53,7 +53,11 @@
var termPrompt = "$ ";
var command = "";
term.open(document.getElementById("terminal"));
- term.write("Hello from \x1B[1;3;31mxterm.js\x1B[0m $ ");
+
+ term.write("Welcome to Featherfall Software!");
+ term.writeln('');
+ term.write(termPrompt);
+
term.onKey(function (key) {
console.log("Key is '" + key.key + "'");