-
Notifications
You must be signed in to change notification settings - Fork 1
/
outputFormatterStyle.js
67 lines (48 loc) · 1.78 KB
/
outputFormatterStyle.js
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
const Color = require('./color')
class OutputFormatterStyle {
$color;
$foreground;
$background;
$options;
$href = null;
$handlesHrefGracefully = null;
constructor($foreground = null, $background = null, $options = []) {
this.$foreground = $foreground || '';
this.$background = $background || '';
this.$color = new Color(this.$foreground, this.$background, this.$options = $options);
}
setForeground($color = null) {
this.$color = new Color(this.$foreground = $color || '', this.$background, this.$options);
}
setBackground($color = null) {
this.$color = new Color(this.$foreground, this.$background = $color || '', this.$options);
}
setHref($url) {
this.$href = $url;
}
setOption($option) {
this.$options.push($option);
this.$color = new Color(this.$foreground, this.$background, this.$options);
}
unsetOption($option) {
let $pos = this.$options.indexOf($option);
if (false !== $pos) {
unset(this.$options[$pos]);
}
this.$color = new Color(this.$foreground, this.$background, this.$options);
}
setOptions($options) {
this.$color = new Color(this.$foreground, this.$background, this.$options = $options);
}
apply($text) {
if (null === this.$handlesHrefGracefully) {
this.$handlesHrefGracefully = 'JetBrains-JediTerm' !== env('TERMINAL_EMULATOR') &&
(!env('KONSOLE_VERSION') || env('KONSOLE_VERSION') > 201100);
}
if (null !== this.$href && this.$handlesHrefGracefully) {
$text = `\0o33]8;;${this.$href}\0o33\\${$text}\0o33]8;;\0o33\\`;
}
return this.$color.apply($text);
}
}
module.exports = OutputFormatterStyle