forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleTerminalProvider.ts
More file actions
76 lines (66 loc) · 1.83 KB
/
ConsoleTerminalProvider.ts
File metadata and controls
76 lines (66 loc) · 1.83 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import { EOL } from 'os';
import { enabled as supportsColor } from 'colors/safe';
import { ITerminalProvider, TerminalProviderSeverity } from './ITerminalProvider';
/**
* Options to be provided to a {@link ConsoleTerminalProvider}
*
* @beta
*/
export interface IConsoleTerminalProviderOptions {
/**
* If true, print verbose logging messages
*/
verboseEnabled: boolean;
}
/**
* Terminal provider that prints to STDOUT (for log- and verbose-level messages) and
* STDERR (for warning- and error-level messsages).
*
* @beta
*/
export class ConsoleTerminalProvider implements ITerminalProvider {
/**
* If true, verbose-level messages should be written to the console.
*/
public verboseEnabled: boolean = false;
public constructor(options: Partial<IConsoleTerminalProviderOptions> = {}) {
this.verboseEnabled = !!options.verboseEnabled;
}
/**
* {@inheritDoc ITerminalProvider.write}
*/
public write(data: string, severity: TerminalProviderSeverity): void {
switch (severity) {
case TerminalProviderSeverity.warning:
case TerminalProviderSeverity.error: {
process.stderr.write(data);
break;
}
case TerminalProviderSeverity.verbose: {
if (this.verboseEnabled) {
process.stdout.write(data);
}
break;
}
case TerminalProviderSeverity.log:
default: {
process.stdout.write(data);
break;
}
}
}
/**
* {@inheritDoc ITerminalProvider.eolCharacter}
*/
public get eolCharacter(): string {
return EOL;
}
/**
* {@inheritDoc ITerminalProvider.supportsColor}
*/
public get supportsColor(): boolean {
return supportsColor;
}
}