Skip to content

Commit

Permalink
Start fixed width terminals
Browse files Browse the repository at this point in the history
Scroll bars don't work yet and only a command for discovery

Part of #74501
  • Loading branch information
Tyriar committed Aug 13, 2021
1 parent 449f192 commit cdbed49
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/vs/workbench/contrib/terminal/browser/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,8 +717,12 @@ export interface ITerminalInstance {

waitForTitle(): Promise<string>;

// TODO: Clarify name
setDimensions(dimensions: ITerminalDimensions): void;

// TODO: Doc
setFixedDimensions(): Promise<void>;

addDisposable(disposable: IDisposable): void;

toggleEscapeSequenceLogging(): void;
Expand Down
15 changes: 15 additions & 0 deletions src/vs/workbench/contrib/terminal/browser/terminalActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,21 @@ export function registerTerminalActions() {
}
});

registerAction2(class extends Action2 {
constructor() {
super({
id: TerminalCommandId.SetDimensions,
title: { value: localize('workbench.action.terminal.setFixedDimensions', "Set Fixed Dimensions"), original: 'Set Fixed Dimensions' },
f1: true,
category,
precondition: TerminalContextKeys.isOpen
});
}
async run(accessor: ServicesAccessor) {
await accessor.get(ITerminalService).doWithActiveInstance(t => t.setFixedDimensions());
}
});

// Some commands depend on platform features
if (BrowserFeatures.clipboard.writeText) {
registerAction2(class extends Action2 {
Expand Down
43 changes: 43 additions & 0 deletions src/vs/workbench/contrib/terminal/browser/terminalInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
private _terminalA11yTreeFocusContextKey: IContextKey<boolean>;
private _cols: number = 0;
private _rows: number = 0;
private _fixedCols: number | undefined = undefined;
private _fixedRows: number | undefined = undefined;
private _dimensionsOverride: ITerminalDimensionsOverride | undefined;
private _xtermReadyPromise: Promise<XTermTerminal>;
private _titleReadyPromise: Promise<string>;
Expand Down Expand Up @@ -166,6 +168,9 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
get instanceId(): number { return this._instanceId; }
get resource(): URI { return this._resource; }
get cols(): number {
if (this._fixedCols !== undefined) {
return this._fixedCols;
}
if (this._dimensionsOverride && this._dimensionsOverride.cols) {
if (this._dimensionsOverride.forceExactSize) {
return this._dimensionsOverride.cols;
Expand All @@ -175,6 +180,9 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
return this._cols;
}
get rows(): number {
if (this._fixedRows !== undefined) {
return this._fixedRows;
}
if (this._dimensionsOverride && this._dimensionsOverride.rows) {
if (this._dimensionsOverride.forceExactSize) {
return this._dimensionsOverride.rows;
Expand Down Expand Up @@ -1795,6 +1803,41 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
}
}

async setFixedDimensions(): Promise<void> {
const cols = await this._quickInputService.input({
// TODO: nls
title: 'Set Fixed Dimensions: Column',
placeHolder: 'Enter a number or leave empty size automatically',
validateInput: async (text) => text.length > 0 && !text.match(/^\d+$/) ? { content: 'Enter a number or leave empty size automatically', severity: Severity.Error } : undefined
});
if (cols === undefined) {
return;
}
this._fixedCols = this._parseFixedDimension(cols);
const rows = await this._quickInputService.input({
// TODO: nls
title: 'Set Fixed Dimensions: Row',
placeHolder: 'Enter a number or leave empty size automatically',
validateInput: async (text) => text.length > 0 && !text.match(/^\d+$/) ? { content: 'Enter a number or leave empty size automatically', severity: Severity.Error } : undefined
});
if (rows === undefined) {
return;
}
this._fixedRows = this._parseFixedDimension(rows);
this._resize();
}

private _parseFixedDimension(value: string): number | undefined {
if (value === '') {
return undefined;
}
const parsed = parseInt(value);
if (parsed <= 0) {
throw new Error(`Could not parse dimension "${value}"`);
}
return parsed;
}

private _setResolvedShellLaunchConfig(shellLaunchConfig: IShellLaunchConfig): void {
this._shellLaunchConfig.args = shellLaunchConfig.args;
this._shellLaunchConfig.cwd = shellLaunchConfig.cwd;
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ export const enum TerminalCommandId {
MoveToEditor = 'workbench.action.terminal.moveToEditor',
MoveToEditorInstance = 'workbench.action.terminal.moveToEditorInstance',
MoveToTerminalPanel = 'workbench.action.terminal.moveToTerminalPanel',
SetDimensions = 'workbench.action.terminal.setDimensions',
}

export const DEFAULT_COMMANDS_TO_SKIP_SHELL: string[] = [
Expand Down

0 comments on commit cdbed49

Please sign in to comment.