-
Notifications
You must be signed in to change notification settings - Fork 0
/
design.ts
186 lines (181 loc) · 4.51 KB
/
design.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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import {type SpinnerName} from 'cli-spinners'
import figures from 'figures'
import {IconProps} from './components/icon.js'
export type Design = {
icons?: {
/**
* Icon to display for a completed stage. Defaults to green '✔'
*/
completed?: IconProps
/**
* Icon to display for the current stage in CI environments. Defaults to '▶'
*
* Non-CI environments will display the spinner instead.
*/
current?: IconProps
/**
* Icon to display for a failed stage. Defaults to red '✘'
*/
failed?: IconProps
/**
* Icon to display for a pending stage. Defaults to dim '◼'
*/
pending?: IconProps
/**
* Icon to display for a skipped stage. Defaults to dim '◯'
*/
skipped?: IconProps
/**
* Icon to display for stage specific information. Defaults to '▸'
*/
info?: IconProps
/**
* Icon to display for a aborted stage. Defaults to red '◼'
*/
aborted?: IconProps
/**
* Icon to display for a paused stage. Defaults to magenta '●'
*/
paused?: IconProps
/**
* Icon to display for an async stage. Defaults to magenta '▶'
*/
async?: IconProps
/**
* Icon to display for a warning. Defaults to yellow '⚠'
*/
warning?: IconProps
}
title?: {
/**
* Character to use as a divider for the title. Defaults to '─'
*/
dividerChar?: string
/**
* Color of the divider. Defaults to 'dim'
*/
dividerColor?: string
/**
* Padding to add above and below the title. Defaults to 1
*/
padding?: number
/**
* Color of the title
*/
textColor?: string
/**
* Padding to add to the left and right of the title. Defaults to 1
*/
textPadding?: number
/**
* Width of the title. Defaults to 50
*
* The `full` value will use the terminal width minus the title padding.
*/
width?: number | 'full'
}
spinners?: {
/**
* Spinner to display for dynamic info blocks. Defaults to 'line' on Windows and 'arc' on other platforms
*/
info?: SpinnerName
/**
* Spinner to display for stages. Defaults to 'line' on Windows and 'dots2' on other platforms
*/
stage?: SpinnerName
}
}
type RecursiveRequired<T> = Required<{
[P in keyof T]: T[P] extends object | undefined ? RecursiveRequired<Required<T[P]>> : T[P]
}>
export type RequiredDesign = RecursiveRequired<Design>
export function constructDesignParams(design?: Design): RequiredDesign {
return {
icons: {
aborted: {
color: 'red',
figure: figures.squareSmallFilled,
paddingLeft: 0,
paddingRight: 0,
...design?.icons?.current,
},
async: {
color: 'magenta',
figure: figures.play,
paddingLeft: 0,
paddingRight: 0,
...design?.icons?.current,
},
completed: {
color: 'green',
figure: figures.tick,
paddingLeft: 0,
paddingRight: 0,
...design?.icons?.completed,
},
current: {
color: 'yellow',
figure: figures.play,
paddingLeft: 0,
paddingRight: 0,
...design?.icons?.current,
},
failed: {
color: 'red',
figure: figures.cross,
paddingLeft: 0,
paddingRight: 0,
...design?.icons?.failed,
},
info: {
color: false,
figure: figures.triangleRightSmall,
paddingLeft: 2,
paddingRight: 1,
...design?.icons?.info,
},
paused: {
color: 'magenta',
figure: figures.bullet,
paddingLeft: 0,
paddingRight: 1,
...design?.icons?.current,
},
pending: {
color: 'dim',
figure: figures.squareSmallFilled,
paddingLeft: 0,
paddingRight: 0,
...design?.icons?.pending,
},
skipped: {
color: 'dim',
figure: figures.circle,
paddingLeft: 0,
paddingRight: 1,
...design?.icons?.skipped,
},
warning: {
color: 'yellow',
figure: figures.warning,
paddingLeft: 0,
paddingRight: 0,
...design?.icons?.warning,
},
},
spinners: {
info: process.platform === 'win32' ? 'line' : 'arc',
stage: process.platform === 'win32' ? 'line' : 'dots2',
...design?.spinners,
},
title: {
dividerChar: '─',
dividerColor: 'dim',
padding: 1,
textColor: 'reset',
textPadding: 1,
width: 50,
...design?.title,
},
}
}