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() { } }