mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 19:18:59 +01:00
hide terminal proxy
This commit is contained in:
@@ -47,7 +47,7 @@ export interface IExtHostTerminalService extends ExtHostTerminalServiceShape, ID
|
||||
|
||||
export const IExtHostTerminalService = createDecorator<IExtHostTerminalService>('IExtHostTerminalService');
|
||||
|
||||
export class ExtHostTerminal implements vscode.Terminal {
|
||||
export class ExtHostTerminal {
|
||||
private _disposed: boolean = false;
|
||||
private _pidPromise: Promise<number | undefined>;
|
||||
private _cols: number | undefined;
|
||||
@@ -57,6 +57,8 @@ export class ExtHostTerminal implements vscode.Terminal {
|
||||
|
||||
public isOpen: boolean = false;
|
||||
|
||||
readonly value: vscode.Terminal;
|
||||
|
||||
constructor(
|
||||
private _proxy: MainThreadTerminalServiceShape,
|
||||
public _id: TerminalIdentifier,
|
||||
@@ -65,6 +67,49 @@ export class ExtHostTerminal implements vscode.Terminal {
|
||||
) {
|
||||
this._creationOptions = Object.freeze(this._creationOptions);
|
||||
this._pidPromise = new Promise<number | undefined>(c => this._pidPromiseComplete = c);
|
||||
|
||||
const that = this;
|
||||
this.value = {
|
||||
get name(): string {
|
||||
return that._name || '';
|
||||
},
|
||||
get processId(): Promise<number | undefined> {
|
||||
return that._pidPromise;
|
||||
},
|
||||
get creationOptions(): Readonly<vscode.TerminalOptions | vscode.ExtensionTerminalOptions> {
|
||||
return that._creationOptions;
|
||||
},
|
||||
get exitStatus(): vscode.TerminalExitStatus | undefined {
|
||||
return that._exitStatus;
|
||||
},
|
||||
sendText(text: string, addNewLine: boolean = true): void {
|
||||
that._checkDisposed();
|
||||
that._proxy.$sendText(that._id, text, addNewLine);
|
||||
},
|
||||
show(preserveFocus: boolean): void {
|
||||
that._checkDisposed();
|
||||
that._proxy.$show(that._id, preserveFocus);
|
||||
},
|
||||
hide(): void {
|
||||
that._checkDisposed();
|
||||
that._proxy.$hide(that._id);
|
||||
},
|
||||
dispose(): void {
|
||||
if (!that._disposed) {
|
||||
that._disposed = true;
|
||||
that._proxy.$dispose(that._id);
|
||||
}
|
||||
},
|
||||
get dimensions(): vscode.TerminalDimensions | undefined {
|
||||
if (that._cols === undefined || that._rows === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
columns: that._cols,
|
||||
rows: that._rows
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public async create(
|
||||
@@ -95,41 +140,16 @@ export class ExtHostTerminal implements vscode.Terminal {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
if (!this._disposed) {
|
||||
this._disposed = true;
|
||||
this._proxy.$dispose(this._id);
|
||||
}
|
||||
}
|
||||
|
||||
private _checkDisposed() {
|
||||
if (this._disposed) {
|
||||
throw new Error('Terminal has already been disposed');
|
||||
}
|
||||
}
|
||||
|
||||
public get name(): string {
|
||||
return this._name || '';
|
||||
}
|
||||
|
||||
public set name(name: string) {
|
||||
this._name = name;
|
||||
}
|
||||
|
||||
public get exitStatus(): vscode.TerminalExitStatus | undefined {
|
||||
return this._exitStatus;
|
||||
}
|
||||
|
||||
public get dimensions(): vscode.TerminalDimensions | undefined {
|
||||
if (this._cols === undefined || this._rows === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
columns: this._cols,
|
||||
rows: this._rows
|
||||
};
|
||||
}
|
||||
|
||||
public setExitCode(code: number | undefined) {
|
||||
this._exitStatus = Object.freeze({ code });
|
||||
}
|
||||
@@ -147,29 +167,6 @@ export class ExtHostTerminal implements vscode.Terminal {
|
||||
return true;
|
||||
}
|
||||
|
||||
public get processId(): Promise<number | undefined> {
|
||||
return this._pidPromise;
|
||||
}
|
||||
|
||||
public get creationOptions(): Readonly<vscode.TerminalOptions | vscode.ExtensionTerminalOptions> {
|
||||
return this._creationOptions;
|
||||
}
|
||||
|
||||
public sendText(text: string, addNewLine: boolean = true): void {
|
||||
this._checkDisposed();
|
||||
this._proxy.$sendText(this._id, text, addNewLine);
|
||||
}
|
||||
|
||||
public show(preserveFocus: boolean): void {
|
||||
this._checkDisposed();
|
||||
this._proxy.$show(this._id, preserveFocus);
|
||||
}
|
||||
|
||||
public hide(): void {
|
||||
this._checkDisposed();
|
||||
this._proxy.$hide(this._id);
|
||||
}
|
||||
|
||||
public _setProcessId(processId: number | undefined): void {
|
||||
// The event may fire 2 times when the panel is restored
|
||||
if (this._pidPromiseComplete) {
|
||||
@@ -284,8 +281,8 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I
|
||||
private readonly _terminalLinkCache: Map<number, Map<number, ICachedLinkEntry>> = new Map();
|
||||
private readonly _terminalLinkCancellationSource: Map<number, CancellationTokenSource> = new Map();
|
||||
|
||||
public get activeTerminal(): ExtHostTerminal | undefined { return this._activeTerminal; }
|
||||
public get terminals(): ExtHostTerminal[] { return this._terminals; }
|
||||
public get activeTerminal(): vscode.Terminal | undefined { return this._activeTerminal?.value; }
|
||||
public get terminals(): vscode.Terminal[] { return this._terminals.map(term => term.value); }
|
||||
|
||||
protected readonly _onDidCloseTerminal: Emitter<vscode.Terminal> = new Emitter<vscode.Terminal>();
|
||||
public get onDidCloseTerminal(): Event<vscode.Terminal> { return this._onDidCloseTerminal && this._onDidCloseTerminal.event; }
|
||||
@@ -336,7 +333,7 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I
|
||||
this._terminalProcessDisposables[id] = disposable;
|
||||
});
|
||||
this._terminals.push(terminal);
|
||||
return terminal;
|
||||
return terminal.value;
|
||||
}
|
||||
|
||||
public attachPtyToTerminal(id: number, pty: vscode.Pseudoterminal): void {
|
||||
@@ -362,7 +359,7 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I
|
||||
if (terminal) {
|
||||
this._activeTerminal = terminal;
|
||||
if (original !== this._activeTerminal) {
|
||||
this._onDidChangeActiveTerminal.fire(this._activeTerminal);
|
||||
this._onDidChangeActiveTerminal.fire(this._activeTerminal.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -370,7 +367,7 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I
|
||||
public async $acceptTerminalProcessData(id: number, data: string): Promise<void> {
|
||||
const terminal = this._getTerminalById(id);
|
||||
if (terminal) {
|
||||
this._onDidWriteTerminalData.fire({ terminal, data });
|
||||
this._onDidWriteTerminalData.fire({ terminal: terminal.value, data });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,8 +376,8 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I
|
||||
if (terminal) {
|
||||
if (terminal.setDimensions(cols, rows)) {
|
||||
this._onDidChangeTerminalDimensions.fire({
|
||||
terminal: terminal,
|
||||
dimensions: terminal.dimensions as vscode.TerminalDimensions
|
||||
terminal: terminal.value,
|
||||
dimensions: terminal.value.dimensions as vscode.TerminalDimensions
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -400,11 +397,11 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I
|
||||
}
|
||||
|
||||
public async $acceptTerminalClosed(id: number, exitCode: number | undefined): Promise<void> {
|
||||
const index = this._getTerminalObjectIndexById(this.terminals, id);
|
||||
const index = this._getTerminalObjectIndexById(this._terminals, id);
|
||||
if (index !== null) {
|
||||
const terminal = this._terminals.splice(index, 1)[0];
|
||||
terminal.setExitCode(exitCode);
|
||||
this._onDidCloseTerminal.fire(terminal);
|
||||
this._onDidCloseTerminal.fire(terminal.value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,9 +411,9 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I
|
||||
const index = this._getTerminalObjectIndexById(this._terminals, extHostTerminalId);
|
||||
if (index !== null) {
|
||||
// The terminal has already been created (via createTerminal*), only fire the event
|
||||
this.terminals[index]._id = id;
|
||||
this._terminals[index]._id = id;
|
||||
this._onDidOpenTerminal.fire(this.terminals[index]);
|
||||
this.terminals[index].isOpen = true;
|
||||
this._terminals[index].isOpen = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -431,7 +428,7 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I
|
||||
};
|
||||
const terminal = new ExtHostTerminal(this._proxy, id, creationOptions, name);
|
||||
this._terminals.push(terminal);
|
||||
this._onDidOpenTerminal.fire(terminal);
|
||||
this._onDidOpenTerminal.fire(terminal.value);
|
||||
terminal.isOpen = true;
|
||||
}
|
||||
|
||||
@@ -455,7 +452,7 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I
|
||||
await new Promise<void>(r => {
|
||||
// Ensure open is called after onDidOpenTerminal
|
||||
const listener = this.onDidOpenTerminal(async e => {
|
||||
if (e === terminal) {
|
||||
if (e === terminal.value) {
|
||||
listener.dispose();
|
||||
r();
|
||||
}
|
||||
@@ -564,7 +561,7 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I
|
||||
this._terminalLinkCancellationSource.set(terminalId, cancellationSource);
|
||||
|
||||
const result: ITerminalLinkDto[] = [];
|
||||
const context: vscode.TerminalLinkContext = { terminal, line };
|
||||
const context: vscode.TerminalLinkContext = { terminal: terminal.value, line };
|
||||
const promises: vscode.ProviderResult<{ provider: vscode.TerminalLinkProvider, links: vscode.TerminalLink[] }>[] = [];
|
||||
|
||||
for (const provider of this._linkProviders) {
|
||||
|
||||
Reference in New Issue
Block a user