bimba-cli 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/serve.js +22 -23
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bimba-cli",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/HeapVoid/bimba.git"
package/serve.js CHANGED
@@ -187,6 +187,7 @@ export function serve(entrypoint, flags) {
187
187
  let _lastLines = 0
188
188
  let _fadeTimers = []
189
189
  let _fadeId = 0
190
+ let _cursorOnLine = false
190
191
 
191
192
  function cancelFade() {
192
193
  _fadeTimers.forEach(t => clearTimeout(t))
@@ -195,45 +196,43 @@ export function serve(entrypoint, flags) {
195
196
 
196
197
  function printStatus(file, state, errors) {
197
198
  cancelFade()
198
- if (_lastLines > 0) {
199
+ if (_cursorOnLine) {
200
+ process.stdout.write('\x1b[1G\x1b[J')
201
+ _lastLines = 0
202
+ _cursorOnLine = false
203
+ } else if (_lastLines > 0) {
199
204
  process.stdout.write(`\x1b[${_lastLines}A\x1b[J`)
200
205
  _lastLines = 0
201
206
  }
202
207
  const now = new Date().toLocaleTimeString('ru-RU', { hour: '2-digit', minute: '2-digit', second: '2-digit' })
203
208
  const status = state === 'ok' ? theme.success(' ok ') : theme.failure(' fail ')
204
- process.stdout.write(` ${theme.folder(now)} ${theme.filename(file)} ${status}\n`)
205
- _lastLines = 1
206
209
  if (errors?.length) {
210
+ process.stdout.write(` ${theme.folder(now)} ${theme.filename(file)} ${status}\n`)
211
+ _lastLines = 1
207
212
  for (const err of errors) {
208
213
  printerr(err)
209
214
  _lastLines += 5
210
215
  }
211
216
  } else {
212
217
  const myId = ++_fadeId
213
- const c = (text, col) => `\x1b[2;38;5;${col}m${text}\x1b[0m`
214
- const steps = [
215
- [5000, 255],
216
- [5500, 253],
217
- [6000, 251],
218
- [6500, 249],
219
- [7000, 246],
220
- [7500, 244],
221
- [8000, 242],
222
- [9000, null],
223
- ].map(([delay, col]) => [delay, col !== null
224
- ? ` ${c(now, col)} ${c(file, col)} ${c('ok', col)}`
225
- : null
226
- ])
227
- for (const [delay, line] of steps) {
218
+ const plainLine = ` ${now} ${file} ok `
219
+ const totalLen = plainLine.length
220
+ const startDelay = 5000
221
+ const charDelay = 22
222
+
223
+ process.stdout.write(` ${theme.folder(now)} ${theme.filename(file)} ${status}`)
224
+ _lastLines = 1
225
+ _cursorOnLine = true
226
+
227
+ for (let i = 1; i <= totalLen; i++) {
228
228
  _fadeTimers.push(setTimeout(() => {
229
229
  if (_fadeId !== myId || _lastLines !== 1) return
230
- if (line !== null) {
231
- process.stdout.write(`\x1b[1A\x1b[2K${line}\n`)
232
- } else {
233
- process.stdout.write(`\x1b[1A\x1b[2K`)
230
+ process.stdout.write('\x1b[1D\x1b[K')
231
+ if (i === totalLen) {
234
232
  _lastLines = 0
233
+ _cursorOnLine = false
235
234
  }
236
- }, delay))
235
+ }, startDelay + i * charDelay))
237
236
  }
238
237
  }
239
238
  }