Skip to content

Commit

Permalink
[output] add severity/color to appendLine method
Browse files Browse the repository at this point in the history
Signed-off-by: Amiram Wingarten <amiram.wingarten@sap.com>
  • Loading branch information
amiramw committed Apr 17, 2020
1 parent 2ce5e63 commit a567ee7
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
3 changes: 2 additions & 1 deletion examples/api-samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Original file line number Diff line number Diff line change
@@ -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();
};
8 changes: 5 additions & 3 deletions packages/output/src/common/output-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit a567ee7

Please sign in to comment.