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); }); } }
componentWillUnmount() { term.destroy(); term = new Terminal({ theme: { background: '#090c0f' } }); term.write(this.state.cwd + '\r\n' + '$'); }
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); }
/** * Prints a message and properly handles new-lines */ print(message: string, sync?: boolean) { const normInput = message.replace(/[\r\n]+/g, "\n").replace(/\n/g, "\r\n"); if (sync) { // We write it synchronously via hacking a bit on xterm //@ts-ignore this.xterm._core.writeSync(normInput); //@ts-ignore this.xterm._core._renderService._renderer._runOperation(renderer => renderer.onGridChanged(0, this.xterm.rows - 1) ); } else { //@ts-ignore this.xterm.write(normInput); } }
/** * 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; }
/** * Clears the current prompt * * This function will erase all the lines that display the current prompt * and move the cursor in the beginning of the first line of the prompt. */ clearInput() { const currentPrompt = this.applyPrompts(this._input); // Get the overall number of lines to clear const allRows = countLines(currentPrompt, this._termSize.cols); // Get the line we are currently in const promptCursor = this.applyPromptOffset(this._input, this._cursor); const { col, row } = offsetToColRow( currentPrompt, promptCursor, this._termSize.cols ); // First move on the last line const moveRows = allRows - row - 1; for (let i = 0; i < moveRows; ++i) this.xterm.write("\x1B[E"); // Clear current input line(s) this.xterm.write("\r\x1B[K"); for (let i = 1; i < allRows; ++i) this.xterm.write("\x1B[F\x1B[K"); }
/** * 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; }
/** * Prints a message and properly handles new-lines */ print(message: string, sync?: boolean) { const normInput = message.replace(/[\r\n]+/g, "\n").replace(/\n/g, "\r\n"); if (sync) { // We write it synchronously via hacking a bit on xterm //@ts-ignore this.xterm._core.writeSync(normInput); //@ts-ignore this.xterm._core._renderService._renderer._runOperation(renderer => renderer.onGridChanged(0, this.xterm.rows - 1) ); } else { //@ts-ignore this.xterm.write(normInput); } }
/** * Clears the current prompt * * This function will erase all the lines that display the current prompt * and move the cursor in the beginning of the first line of the prompt. */ clearInput() { const currentPrompt = this.applyPrompts(this._input); // Get the overall number of lines to clear const allRows = countLines(currentPrompt, this._termSize.cols); // Get the line we are currently in const promptCursor = this.applyPromptOffset(this._input, this._cursor); const { col, row } = offsetToColRow( currentPrompt, promptCursor, this._termSize.cols ); // First move on the last line const moveRows = allRows - row - 1; for (let i = 0; i < moveRows; ++i) this.xterm.write("\x1B[E"); // Clear current input line(s) this.xterm.write("\r\x1B[K"); for (let i = 1; i < allRows; ++i) this.xterm.write("\x1B[F\x1B[K"); }