componentDidUpdate(prevProps) { if (prevProps.rootdir !== this.state.cwd && prevProps.rootdir !== this.props.rootdir) { //Perform some operation this.setState({ cwd: prevProps.rootdir, rootDir: prevProps.rootdir }, () => { term.clear(); term.write(this.state.cwd + '\r\n' + '$'); shell.cd(this.state.cwd); }); } }
parent.addEventListener("touchmove", e => { if (this._lastTouchY) { let y = e.changedTouches[0].screenY; let deltaY = y - this._lastTouchY; this._lastTouchY = y; this.term.scrollLines(-Math.round(deltaY/10)); } });
this.term.attachCustomKeyEventHandler(e => { window.keyboard.keydownHandler(e); return true; });
parent.addEventListener("wheel", e => { this.term.scrollLines(Math.round(e.deltaY/10)); });
term.setOption('cursorStyle', 'block'); term.setOption('cursorBlink', true); term.setOption('fontSize', 14); term.open(document.getElementById('terminal')); let greeting = ''; term.fit(); term.on('key', (key, ev) => { const fileManipulation = new Set(['cp', 'mkdir', 'touch', 'rm', 'rmdir', 'mv']); switch (ev.keyCode) { this.setState({ cwd: newPath }); greeting = newPath; term.write('\r\n' + greeting + '\r\n'); term.write('$'); term.write('\b \b'); this.setState({ currCommand: this.state.currCommand.slice(0, -1) }); break; term.write(key); this.setState({ cursorIndex: this.state.cursorIndex - 1 }) } else if (ev.keyCode === 39) { term.write(key); this.setState({ cursorIndex: this.state.cursorIndex + 1 }); term.write(key); this.setState({ currCommand: this.state.currCommand + key, cursorIndex: this.state.cursorIndex + 1 });
write(dataString) { this._xterm.write(dataString); }
/** * Function to return the terminal buffer */ getBuffer(): IBuffer { return this.xterm.buffer; }
/** * Clears the entire Tty * * This function will erase all the lines that display on the tty, * and move the cursor in the beginning of the first line of the prompt. */ clearTty() { // Clear the screen this.xterm.write("\u001b[2J"); // Set the cursor to 0, 0 this.xterm.write("\u001b[0;0H"); this._cursor = 0; }
parent.addEventListener("touchmove", e => { if (this._lastTouchY) { let y = e.changedTouches[0].screenY; let deltaY = y - this._lastTouchY; this._lastTouchY = y; this.term.scrollLines(-Math.round(deltaY/10)); } });
this.term.attachCustomKeyEventHandler(e => { window.keyboard.keydownHandler(e); return true; });
parent.addEventListener("wheel", e => { this.term.scrollLines(Math.round(e.deltaY/10)); });
/** * Function to return the terminal buffer */ getBuffer(): IBuffer { return this.xterm.buffer; }