Skip to content

Commit

Permalink
[output] add severity/color to append API
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 11, 2020
1 parent cb3db2a commit ce9e03a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
14 changes: 10 additions & 4 deletions packages/output/src/browser/output-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { inject, injectable, postConstruct } from 'inversify';
import { Message } from '@theia/core/lib/browser';
import { OutputChannelManager, OutputChannel } from '../common/output-channel';
import { OutputChannel, OutputChannelManager, OutputChannelSeverity } from '../common/output-channel';
import { ReactWidget } from '@theia/core/lib/browser/widgets/react-widget';
import * as React from 'react';

Expand Down Expand Up @@ -117,10 +117,16 @@ export class OutputWidget extends ReactWidget {
};

if (this.outputChannelManager.selectedChannel) {
for (const text of this.outputChannelManager.selectedChannel.getLines()) {
const lines = text.split(/[\n\r]+/);
for (const outputChannelLine of this.outputChannelManager.selectedChannel.getLines()) {
const lines = outputChannelLine.text.split(/[\n\r]+/);
let className;
if (outputChannelLine.severity === OutputChannelSeverity.Error) {
className = 'theia-console-error';
} else if (outputChannelLine.severity === OutputChannelSeverity.Warning) {
className = 'theia-console-warning';
}
for (const line of lines) {
result.push(<div style={style} key={id++}>{line}</div>);
result.push(<div style={style} className={className} key={id++}>{line}</div>);
}
}
}
Expand Down
27 changes: 18 additions & 9 deletions packages/output/src/common/output-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,34 +105,43 @@ export class OutputChannelManager implements Disposable {
}
}

export enum OutputChannelSeverity {
info, Warning, Error
}
export interface OutputChannelLine {
text: string;
severity: OutputChannelSeverity;
}

export class OutputChannel {

private readonly visibilityChangeEmitter = new Emitter<{ visible: boolean }>();
private readonly contentChangeEmitter = new Emitter<OutputChannel>();
private lines: string[] = [];
private currentLine: string | undefined;
private lines: OutputChannelLine[] = [];
private currentLine: OutputChannelLine | undefined;
private visible: boolean = true;

readonly onVisibilityChange: Event<{ visible: boolean }> = this.visibilityChangeEmitter.event;
readonly onContentChange: Event<OutputChannel> = this.contentChangeEmitter.event;

constructor(readonly name: string, readonly preferences: OutputPreferences) { }

append(value: string): void {
append(value: string, severity = OutputChannelSeverity.info): void {
if (this.currentLine === undefined) {
this.currentLine = value;
this.currentLine = { text: value, severity };
} else {
this.currentLine += value;
this.currentLine.text += value;
}
this.contentChangeEmitter.fire(this);
}

appendLine(line: string): void {
appendLine(line: string, severity = OutputChannelSeverity.info): void {
if (this.currentLine !== undefined) {
this.lines.push(this.currentLine + line);
this.currentLine.text = this.currentLine.text + line;
this.lines.push(this.currentLine);
this.currentLine = undefined;
} else {
this.lines.push(line);
this.lines.push({ text: line, severity });
}
const maxChannelHistory = this.preferences['output.maxChannelHistory'];
if (this.lines.length > maxChannelHistory) {
Expand All @@ -152,7 +161,7 @@ export class OutputChannel {
this.visibilityChangeEmitter.fire({ visible });
}

getLines(): string[] {
getLines(): OutputChannelLine[] {
if (this.currentLine !== undefined) {
return [...this.lines, this.currentLine];
} else {
Expand Down

0 comments on commit ce9e03a

Please sign in to comment.