From a567ee761295a02ef0d51e21981451f33704cac7 Mon Sep 17 00:00:00 2001 From: Amiram Wingarten Date: Sat, 11 Apr 2020 23:39:42 +0300 Subject: [PATCH] [output] add severity/color to appendLine method Signed-off-by: Amiram Wingarten --- examples/api-samples/package.json | 3 +- .../browser/api-samples-frontend-module.ts | 2 + .../sample-output-channel-with-severity.ts | 37 +++++++++++++++++++ packages/output/src/common/output-channel.ts | 8 ++-- 4 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 examples/api-samples/src/browser/output/sample-output-channel-with-severity.ts diff --git a/examples/api-samples/package.json b/examples/api-samples/package.json index b147fde9f3ffe..58e3ab0d9a7c2 100644 --- a/examples/api-samples/package.json +++ b/examples/api-samples/package.json @@ -4,7 +4,8 @@ "version": "1.0.0", "description": "Theia - Example code to demonstrate Theia API", "dependencies": { - "@theia/core": "^1.0.0" + "@theia/core": "^1.0.0", + "@theia/output": "^1.0.0" }, "theiaExtensions": [ { diff --git a/examples/api-samples/src/browser/api-samples-frontend-module.ts b/examples/api-samples/src/browser/api-samples-frontend-module.ts index afacf29ff68b5..2fac6d83ffaeb 100644 --- a/examples/api-samples/src/browser/api-samples-frontend-module.ts +++ b/examples/api-samples/src/browser/api-samples-frontend-module.ts @@ -17,8 +17,10 @@ import { ContainerModule } from 'inversify'; import { bindDynamicLabelProvider } from './label/sample-dynamic-label-provider-command-contribution'; import { bindSampleUnclosableView } from './view/sample-unclosable-view-contribution'; +import { bindSampleOutputChannelWithSeverity } from './output/sample-output-channel-with-severity'; export default new ContainerModule(bind => { bindDynamicLabelProvider(bind); bindSampleUnclosableView(bind); + bindSampleOutputChannelWithSeverity(bind); }); diff --git a/examples/api-samples/src/browser/output/sample-output-channel-with-severity.ts b/examples/api-samples/src/browser/output/sample-output-channel-with-severity.ts new file mode 100644 index 0000000000000..e8e72101199d9 --- /dev/null +++ b/examples/api-samples/src/browser/output/sample-output-channel-with-severity.ts @@ -0,0 +1,37 @@ +/******************************************************************************** + * Copyright (c) 2020 SAP SE or an SAP affiliate company and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ +import { FrontendApplicationContribution } from '@theia/core/lib/browser'; +import { inject, injectable, interfaces } from 'inversify'; +import { OutputChannelManager, OutputChannelSeverity } from '@theia/output/lib/common/output-channel'; + +@injectable() +export class SampleOutputChannelWithSeverity + implements FrontendApplicationContribution { + @inject(OutputChannelManager) + protected readonly outputChannelManager: OutputChannelManager; + public onStart(): void { + const channel = this.outputChannelManager.getChannel('my test channel'); + channel.appendLine('hello info1'); // showed without color + channel.appendLine('hello info2', OutputChannelSeverity.Info); + channel.appendLine('hello error', OutputChannelSeverity.Error); + channel.appendLine('hello warning', OutputChannelSeverity.Warning); + } +} +export const bindSampleOutputChannelWithSeverity = (bind: interfaces.Bind) => { + bind(FrontendApplicationContribution) + .to(SampleOutputChannelWithSeverity) + .inSingletonScope(); +}; diff --git a/packages/output/src/common/output-channel.ts b/packages/output/src/common/output-channel.ts index 33e007faf1525..73100a8ddea99 100644 --- a/packages/output/src/common/output-channel.ts +++ b/packages/output/src/common/output-channel.ts @@ -106,7 +106,9 @@ export class OutputChannelManager implements Disposable { } export enum OutputChannelSeverity { - info, Warning, Error + Error = 1, + Warning = 2, + Info = 3 } export interface OutputChannelLine { text: string; @@ -128,14 +130,14 @@ export class OutputChannel { append(value: string): void { if (this.currentLine === undefined) { - this.currentLine = { text: value, severity: OutputChannelSeverity.info }; + this.currentLine = { text: value, severity: OutputChannelSeverity.Info }; } else { this.currentLine.text += value; } this.contentChangeEmitter.fire(this); } - appendLine(line: string, severity = OutputChannelSeverity.info): void { + appendLine(line: string, severity = OutputChannelSeverity.Info): void { if (this.currentLine !== undefined) { this.currentLine.text = this.currentLine.text + line; this.lines.push(this.currentLine);