output.ts 5.0 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

M
Matt Bierner 已提交
6
import { Event, Emitter } from 'vs/base/common/event';
7
import { Registry } from 'vs/platform/registry/common/platform';
8
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
J
Johannes Rieken 已提交
9
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
10
import { URI } from 'vs/base/common/uri';
E
Erich Gamma 已提交
11

B
Benjamin Pasero 已提交
12 13 14 15 16
/**
 * Mime type used by the output editor.
 */
export const OUTPUT_MIME = 'text/x-code-output';

E
Erich Gamma 已提交
17
/**
18
 * Output resource scheme.
E
Erich Gamma 已提交
19
 */
20
export const OUTPUT_SCHEME = 'output';
E
Erich Gamma 已提交
21

22
/**
S
Sandeep Somavarapu 已提交
23 24 25 26 27 28 29 30 31 32 33
 * Id used by the output editor.
 */
export const OUTPUT_MODE_ID = 'Log';

/**
 * Mime type used by the log output editor.
 */
export const LOG_MIME = 'text/x-code-log-output';

/**
 * Log resource scheme.
34 35 36
 */
export const LOG_SCHEME = 'log';

E
Erich Gamma 已提交
37
/**
S
Sandeep Somavarapu 已提交
38
 * Id used by the log output editor.
E
Erich Gamma 已提交
39
 */
S
Sandeep Somavarapu 已提交
40
export const LOG_MODE_ID = 'log';
E
Erich Gamma 已提交
41

I
isidor 已提交
42 43 44 45 46
/**
 * Output panel id
 */
export const OUTPUT_PANEL_ID = 'workbench.panel.output';

E
Erich Gamma 已提交
47 48 49 50 51 52
export const Extensions = {
	OutputChannels: 'workbench.contributions.outputChannels'
};

export const OUTPUT_SERVICE_ID = 'outputService';

53 54
export const MAX_OUTPUT_LENGTH = 10000 /* Max. number of output lines to show in output */ * 100 /* Guestimated chars per line */;

I
isidor 已提交
55 56
export const CONTEXT_IN_OUTPUT = new RawContextKey<boolean>('inOutput', false);

S
Sandeep Somavarapu 已提交
57 58
export const CONTEXT_ACTIVE_LOG_OUTPUT = new RawContextKey<boolean>('activeLogOutput', false);

B
Benjamin Pasero 已提交
59
export const IOutputService = createDecorator<IOutputService>(OUTPUT_SERVICE_ID);
E
Erich Gamma 已提交
60 61 62 63 64

/**
 * The output service to manage output from the various processes running.
 */
export interface IOutputService {
65
	_serviceBrand: any;
I
isidor 已提交
66

67 68
	/**
	 * Given the channel id returns the output channel instance.
I
isidor 已提交
69
	 * Channel should be first registered via OutputChannelRegistry.
70
	 */
71
	getChannel(id: string): IOutputChannel | undefined;
E
Erich Gamma 已提交
72

73
	/**
74
	 * Returns an array of all known output channels descriptors.
75
	 */
76
	getChannelDescriptors(): IOutputChannelDescriptor[];
77

I
isidor 已提交
78
	/**
I
isidor 已提交
79 80
	 * Returns the currently active channel.
	 * Only one channel can be active at a given moment.
I
isidor 已提交
81
	 */
82
	getActiveChannel(): IOutputChannel | undefined;
I
isidor 已提交
83

E
Erich Gamma 已提交
84
	/**
S
Sandeep Somavarapu 已提交
85
	 * Show the channel with the passed id.
E
Erich Gamma 已提交
86
	 */
J
Johannes Rieken 已提交
87
	showChannel(id: string, preserveFocus?: boolean): Promise<void>;
E
Erich Gamma 已提交
88

I
isidor 已提交
89
	/**
90
	 * Allows to register on active output channel change.
I
isidor 已提交
91 92
	 */
	onActiveOutputChannel: Event<string>;
E
Erich Gamma 已提交
93 94
}

I
isidor 已提交
95 96
export interface IOutputChannel {

I
isidor 已提交
97 98 99 100 101 102 103 104 105 106
	/**
	 * Identifier of the output channel.
	 */
	id: string;

	/**
	 * Label of the output channel to be displayed to the user.
	 */
	label: string;

107 108 109
	/**
	 * Returns the value indicating whether the channel has scroll locked.
	 */
110
	scrollLock: boolean;
111

112
	/**
113
	 * Appends output to the channel.
114
	 */
115
	append(output: string): void;
116

117 118 119 120 121
	/**
	 * Update the channel.
	 */
	update(): void;

122
	/**
123
	 * Clears all received output for this channel.
124
	 */
S
Sandeep Somavarapu 已提交
125
	clear(till?: number): void;
126 127 128 129 130

	/**
	 * Disposes the output channel.
	 */
	dispose(): void;
I
isidor 已提交
131 132
}

133
export interface IOutputChannelDescriptor {
134 135
	id: string;
	label: string;
136
	log: boolean;
S
Sandeep Somavarapu 已提交
137
	file?: URI;
138 139
}

S
Sandeep Somavarapu 已提交
140 141 142 143
export interface IFileOutputChannelDescriptor extends IOutputChannelDescriptor {
	file: URI;
}

E
Erich Gamma 已提交
144 145
export interface IOutputChannelRegistry {

S
Sandeep Somavarapu 已提交
146 147 148
	readonly onDidRegisterChannel: Event<string>;
	readonly onDidRemoveChannel: Event<string>;

E
Erich Gamma 已提交
149 150 151
	/**
	 * Make an output channel known to the output world.
	 */
152
	registerChannel(descriptor: IOutputChannelDescriptor): void;
E
Erich Gamma 已提交
153 154 155 156

	/**
	 * Returns the list of channels known to the output world.
	 */
157
	getChannels(): IOutputChannelDescriptor[];
158

159 160 161
	/**
	 * Returns the channel with the passed id.
	 */
162
	getChannel(id: string): IOutputChannelDescriptor | undefined;
163

164 165 166 167
	/**
	 * Remove the output channel with the passed id.
	 */
	removeChannel(id: string): void;
E
Erich Gamma 已提交
168 169 170
}

class OutputChannelRegistry implements IOutputChannelRegistry {
171
	private channels = new Map<string, IOutputChannelDescriptor>();
E
Erich Gamma 已提交
172

173
	private readonly _onDidRegisterChannel = new Emitter<string>();
S
Sandeep Somavarapu 已提交
174 175
	readonly onDidRegisterChannel: Event<string> = this._onDidRegisterChannel.event;

176
	private readonly _onDidRemoveChannel = new Emitter<string>();
S
Sandeep Somavarapu 已提交
177 178
	readonly onDidRemoveChannel: Event<string> = this._onDidRemoveChannel.event;

179 180 181 182
	public registerChannel(descriptor: IOutputChannelDescriptor): void {
		if (!this.channels.has(descriptor.id)) {
			this.channels.set(descriptor.id, descriptor);
			this._onDidRegisterChannel.fire(descriptor.id);
E
Erich Gamma 已提交
183 184 185
		}
	}

186 187
	public getChannels(): IOutputChannelDescriptor[] {
		const result: IOutputChannelDescriptor[] = [];
188 189 190 191
		this.channels.forEach(value => result.push(value));
		return result;
	}

192
	public getChannel(id: string): IOutputChannelDescriptor | undefined {
193
		return this.channels.get(id);
E
Erich Gamma 已提交
194
	}
195 196

	public removeChannel(id: string): void {
197
		this.channels.delete(id);
S
Sandeep Somavarapu 已提交
198
		this._onDidRemoveChannel.fire(id);
199
	}
E
Erich Gamma 已提交
200 201
}

202
Registry.add(Extensions.OutputChannels, new OutputChannelRegistry());