Skip to content

Commit

Permalink
Fallback to 80x30 dimensions in terminal
Browse files Browse the repository at this point in the history
This fixes an issue where when the terminal would be created without a container
it initializes with 0x0 dimensions which gets set to the minimum of 2x1 instead
of the expected default of 80x30 (which node-pty respects). This 80x30 is now
hardcoded in VS Code.

Fixes #128342
  • Loading branch information
Tyriar committed Jul 14, 2021
1 parent 268e9da commit 3bea1f0
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/vs/workbench/contrib/terminal/browser/terminalInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ const enum Constants {
* terminal process. This period helps ensure the terminal has good initial dimensions to work
* with if it's going to be a foreground terminal.
*/
WaitForContainerThreshold = 100
WaitForContainerThreshold = 100,

DefaultCols = 80,
DefaultRows = 30,
}

let xtermConstructor: Promise<typeof XTermTerminal> | undefined;
Expand Down Expand Up @@ -538,9 +541,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
const editorOptions = this._configurationService.getValue<IEditorOptions>('editor');

const xterm = new Terminal({
// TODO: Replace null with undefined when https://github.com/xtermjs/xterm.js/issues/3329 is resolved
cols: this._cols || null as any,
rows: this._rows || null as any,
cols: this._cols || Constants.DefaultCols,
rows: this._rows || Constants.DefaultRows,
altClickMovesCursor: config.altClickMovesCursor && editorOptions.multiCursorModifier === 'alt',
scrollback: config.scrollback,
theme: this._getXtermTheme(),
Expand Down Expand Up @@ -1159,8 +1161,15 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
if (this._isDisposed) {
return;
}

// Re-evaluate dimensions if the container has been set since the xterm instance was created
if (this._container && this._cols === 0 && this._rows === 0) {
this._initDimensions();
this._xterm?.resize(this._cols || Constants.DefaultCols, this._rows || Constants.DefaultRows);
}

const hadIcon = !!this.shellLaunchConfig.icon;
await this._processManager.createProcess(this._shellLaunchConfig, this._cols, this._rows, this._accessibilityService.isScreenReaderOptimized()).then(error => {
await this._processManager.createProcess(this._shellLaunchConfig, this._cols || Constants.DefaultCols, this._rows || Constants.DefaultRows, this._accessibilityService.isScreenReaderOptimized()).then(error => {
if (error) {
this._onProcessExit(error);
}
Expand Down

0 comments on commit 3bea1f0

Please sign in to comment.