1
>
/*---------------------------------------------------------------------------------------------
history.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { Disposable } from '../../../../../base/common/lifecycle.js';
7
>
import { LRUCache } from '../../../../../base/common/map.js';
8
>
import { Schemas } from '../../../../../base/common/network.js';
9
>
import { join } from '../../../../../base/common/path.js';
10
>
import { isWindows, OperatingSystem } from '../../../../../base/common/platform.js';
11
>
import { env } from '../../../../../base/common/process.js';
12
>
import { isNumber } from '../../../../../base/common/types.js';
13
>
import { URI } from '../../../../../base/common/uri.js';
14
>
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';
15
>
import { FileOperationError, FileOperationResult, IFileContent, IFileService } from '../../../../../platform/files/common/files.js';
16
>
import { IInstantiationService, ServicesAccessor } from '../../../../../platform/instantiation/common/instantiation.js';
17
>
import { IStorageService, StorageScope, StorageTarget } from '../../../../../platform/storage/common/storage.js';
18
>
import { GeneralShellType, PosixShellType, TerminalShellType } from '../../../../../platform/terminal/common/terminal.js';
19
>
import { IRemoteAgentService } from '../../../../services/remote/common/remoteAgentService.js';
20
>
import { TerminalHistorySettingId } from './terminal.history.js';
21
>
22
>
/**
23
>
* Tracks a list of generic entries.
24
>
*/
25
>
export interface ITerminalPersistedHistory<T> {
26
>
/**
27
>
* The persisted entries.
28
>
*/
29
>
readonly entries: IterableIterator<[string, T]>;
30
>
/**
31
>
* Adds an entry.
32
>
*/
33
>
add(key: string, value: T): void;
34
>
/**
35
>
* Removes an entry.
36
>
*/
37
>
remove(key: string): void;
38
>
/**
39
>
* Clears all entries.
40
>
*/
41
>
clear(): void;
42
>
}
43
>
44
>
interface ISerializedCache<T> {
45
>
entries: { key: string; value: T }[];
46
>
}
47
>
48
>
const enum Constants {
49
>
DefaultHistoryLimit = 100
50
>
}
51
>
52
>
const enum StorageKeys {
53
>
Entries = 'terminal.history.entries',
54
>
Timestamp = 'terminal.history.timestamp'
55
>
}
56
>
57
>
let directoryHistory: ITerminalPersistedHistory<{ remoteAuthority?: string }> | undefined = undefined;
58
>
export function getDirectoryHistory(accessor: ServicesAccessor): ITerminalPersistedHistory<{ remoteAuthority?: string }> {
59
if (!directoryHistory) {
60
directoryHistory = accessor.get(IInstantiationService).createInstance(TerminalPersistedHistory, 'dirs') as TerminalPersistedHistory<{ remoteAuthority?: string }>;