-
-
Notifications
You must be signed in to change notification settings - Fork 435
/
Copy pathresponse-service-impl.ts
45 lines (38 loc) · 1.42 KB
/
response-service-impl.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { inject, injectable } from '@theia/core/shared/inversify';
import { Emitter } from '@theia/core/lib/common/event';
import {
OutputChannelManager,
OutputChannelSeverity,
} from '@theia/output/lib/browser/output-channel';
import {
OutputMessage,
ProgressMessage,
ResponseServiceClient,
} from '../common/protocol/response-service';
@injectable()
export class ResponseServiceImpl implements ResponseServiceClient {
@inject(OutputChannelManager)
private readonly outputChannelManager: OutputChannelManager;
private readonly progressDidChangeEmitter = new Emitter<ProgressMessage>();
readonly onProgressDidChange = this.progressDidChangeEmitter.event;
clearOutput(): void {
this.outputChannelManager.getChannel('Arduino').clear();
}
appendToOutput(message: OutputMessage): void {
const { chunk, severity } = message;
const channel = this.outputChannelManager.getChannel('Arduino');
channel.show({ preserveFocus: true });
channel.append(chunk, mapSeverity(severity));
}
reportProgress(progress: ProgressMessage): void {
this.progressDidChangeEmitter.fire(progress);
}
}
function mapSeverity(severity?: OutputMessage.Severity): OutputChannelSeverity {
if (severity === OutputMessage.Severity.Error) {
return OutputChannelSeverity.Error;
} else if (severity === OutputMessage.Severity.Warning) {
return OutputChannelSeverity.Warning;
}
return OutputChannelSeverity.Info;
}