-
Notifications
You must be signed in to change notification settings - Fork 29.2k
/
terminalEditorSerializer.ts
49 lines (43 loc) · 2.12 KB
/
terminalEditorSerializer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { URI } from 'vs/base/common/uri';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IEditorSerializer } from 'vs/workbench/common/editor';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { ISerializedTerminalEditorInput, ITerminalEditorService, ITerminalInstance } from 'vs/workbench/contrib/terminal/browser/terminal';
import { TerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorInput';
export class TerminalInputSerializer implements IEditorSerializer {
constructor(
@ITerminalEditorService private readonly _terminalEditorService: ITerminalEditorService
) { }
public canSerialize(editorInput: TerminalEditorInput): boolean {
return !!editorInput.terminalInstance?.persistentProcessId;
}
public serialize(editorInput: TerminalEditorInput): string | undefined {
if (!editorInput.terminalInstance?.persistentProcessId || !editorInput.terminalInstance.shouldPersist) {
return;
}
const term = JSON.stringify(this._toJson(editorInput.terminalInstance));
return term;
}
public deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): EditorInput | undefined {
const terminalInstance = JSON.parse(serializedEditorInput);
terminalInstance.resource = URI.parse(terminalInstance.resource);
return this._terminalEditorService.reviveInput(terminalInstance);
}
private _toJson(instance: ITerminalInstance): ISerializedTerminalEditorInput {
return {
id: instance.persistentProcessId!,
pid: instance.processId || 0,
title: instance.title,
titleSource: instance.titleSource,
cwd: '',
icon: instance.icon,
color: instance.color,
resource: instance.resource.toString(),
hasChildProcesses: instance.hasChildProcesses
};
}
}