Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
useEffect(() => {
if (connected && terminalElement && !terminal.element) {
terminal.open(terminalElement);
// @see https://github.com/xtermjs/xterm.js/issues/2265
// @see https://github.com/xtermjs/xterm.js/issues/2230
TerminalFit.fit(terminal);
// Add support for copying terminal text.
terminal.attachCustomKeyEventHandler((e: KeyboardEvent) => {
// Ctrl + C
if (e.ctrlKey && (e.key === 'c')) {
document.execCommand('copy');
return false;
}
return true;
});
}
}, [ terminal, connected, terminalElement ]);
private _resizeTerminal() {
fit(this._term);
if (this._offsetWidth === -1) {
this._offsetWidth = this.node.offsetWidth;
}
if (this._offsetHeight === -1) {
this._offsetHeight = this.node.offsetHeight;
}
this._setSessionSize();
this._needsResize = false;
}
private setupTerminal() {
this.terminal = new Terminal({
cursorBlink: false,
});
this.terminal.open(this.terminalContainer.nativeElement);
this.terminal.focus();
fit(this.terminal);
}
}
public resizeTerminal(width: number = this.terminalContainer.nativeElement.offsetWidth) {
const charHeight = 25;
const charWidth = Math.floor((width - 20) / 8.39);
if (width > 0) {
this.terminal.resize(charWidth, charHeight);
fit(this.terminal);
}
return {
charHeight,
charWidth
};
}
@autobind handleResize(dimensions) {
if (!this.term.element)
return;
fit(this.term);
}
resize() {
fitTerm(this.tty);
}