(msg = '')
| 130 | const hasGuide = opts.withGuide ?? settings.withGuide; |
| 131 | |
| 132 | const start = (msg = ''): void => { |
| 133 | isSpinnerActive = true; |
| 134 | unblock = block({ output }); |
| 135 | _message = removeTrailingDots(msg); |
| 136 | _origin = performance.now(); |
| 137 | if (hasGuide) { |
| 138 | output.write(`${styleText('gray', S_BAR)}\n`); |
| 139 | } |
| 140 | let frameIndex = 0; |
| 141 | let indicatorTimer = 0; |
| 142 | registerHooks(); |
| 143 | loop = setInterval(() => { |
| 144 | if (isCI && _message === _prevMessage) { |
| 145 | return; |
| 146 | } |
| 147 | clearPrevMessage(); |
| 148 | _prevMessage = _message; |
| 149 | const frame = styleFn(frames[frameIndex]); |
| 150 | let outputMessage: string; |
| 151 | |
| 152 | if (isCI) { |
| 153 | outputMessage = `${frame} ${_message}...`; |
| 154 | } else if (indicator === 'timer') { |
| 155 | outputMessage = `${frame} ${_message} ${formatTimer(_origin)}`; |
| 156 | } else { |
| 157 | const loadingDots = '.'.repeat(Math.floor(indicatorTimer)).slice(0, 3); |
| 158 | outputMessage = `${frame} ${_message}${loadingDots}`; |
| 159 | } |
| 160 | |
| 161 | const wrapped = wrapAnsi(outputMessage, columns, { |
| 162 | hard: true, |
| 163 | trim: false, |
| 164 | }); |
| 165 | output.write(wrapped); |
| 166 | |
| 167 | frameIndex = frameIndex + 1 < frames.length ? frameIndex + 1 : 0; |
| 168 | // indicator increase by 1 every 8 frames |
| 169 | indicatorTimer = indicatorTimer < 4 ? indicatorTimer + 0.125 : 0; |
| 170 | }, delay); |
| 171 | }; |
| 172 | |
| 173 | const _stop = (msg = '', code = 0, silent: boolean = false): void => { |
| 174 | if (!isSpinnerActive) return; |
nothing calls this directly
no test coverage detected