Skip to content

Commit

Permalink
Support detach from process in remote
Browse files Browse the repository at this point in the history
Part of #118276
  • Loading branch information
Tyriar committed Jun 16, 2021
1 parent 16facd8 commit 152d422
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/vs/workbench/contrib/terminal/browser/remotePty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export class RemotePty extends Disposable implements ITerminalChildProcess {
return undefined;
}

async detach(): Promise<void> {
await this._startBarrier.wait();
return this._remoteTerminalChannel.detachFromProcess(this.id);
}

shutdown(immediate: boolean): void {
this._startBarrier.wait().then(_ => {
this._remoteTerminalChannel.shutdown(this._id, immediate);
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/terminal/browser/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ export interface ITerminalInstance {
/**
* Inform the process that the terminal is now detached.
*/
detachFromProcess(): void;
detachFromProcess(): Promise<void>;

/**
* Forces the terminal to redraw its viewport.
Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/contrib/terminal/browser/terminalActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,8 @@ export function registerTerminalActions() {
});
}
async run(accessor: ServicesAccessor) {
accessor.get(ITerminalService).doWithActiveInstance(instance => instance.detachFromProcess());
const terminalService = accessor.get(ITerminalService);
await terminalService.getActiveInstance()?.detachFromProcess();
}
});
registerAction2(class extends Action2 {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/terminal/browser/terminalInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -984,8 +984,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
super.dispose();
}

detachFromProcess(): void {
this._processManager.detachFromProcess();
async detachFromProcess(): Promise<void> {
await this._processManager.detachFromProcess();
this.dispose();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,15 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
});
}

detachFromProcess(): void {
this._process?.detach?.();
async detachFromProcess(): Promise<void> {
if (!this._process) {
return;
}
if (this._process.detach) {
await this._process.detach();
} else {
throw new Error('This terminal process does not support detaching');
}
this._process = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ export class RemoteTerminalChannelClient {
attachToProcess(id: number): Promise<void> {
return this._channel.call('$attachToProcess', [id]);
}
detachFromProcess(id: number): Promise<void> {
return this._channel.call('$detachFromProcess', [id]);
}
listProcesses(): Promise<IProcessDetails[]> {
return this._channel.call('$listProcesses');
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export interface ITerminalProcessManager extends IDisposable {
readonly onEnvironmentVariableInfoChanged: Event<IEnvironmentVariableInfo>;

dispose(immediate?: boolean): void;
detachFromProcess(): void;
detachFromProcess(): Promise<void>;
createProcess(shellLaunchConfig: IShellLaunchConfig, cols: number, rows: number, isScreenReaderModeEnabled: boolean): Promise<ITerminalLaunchError | undefined>;
relaunch(shellLaunchConfig: IShellLaunchConfig, cols: number, rows: number, isScreenReaderModeEnabled: boolean, reset: boolean): Promise<ITerminalLaunchError | undefined>;
write(data: string): void;
Expand Down

0 comments on commit 152d422

Please sign in to comment.