bimba-cli 0.4.2 → 0.4.4

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 +20 -29
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bimba-cli",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/HeapVoid/bimba.git"
package/serve.js CHANGED
@@ -184,9 +184,9 @@ export function serve(entrypoint, flags) {
184
184
  const sockets = new Set()
185
185
  let importMapTag = null
186
186
 
187
- let _lastLines = 0
188
187
  let _fadeTimers = []
189
188
  let _fadeId = 0
189
+ let _statusSaved = false
190
190
 
191
191
  function cancelFade() {
192
192
  _fadeTimers.forEach(t => clearTimeout(t))
@@ -195,45 +195,36 @@ export function serve(entrypoint, flags) {
195
195
 
196
196
  function printStatus(file, state, errors) {
197
197
  cancelFade()
198
- if (_lastLines > 0) {
199
- process.stdout.write(`\x1b[${_lastLines}A\x1b[J`)
200
- _lastLines = 0
198
+ if (_statusSaved) {
199
+ process.stdout.write('\x1b[u\x1b[J')
200
+ _statusSaved = false
201
201
  }
202
202
  const now = new Date().toLocaleTimeString('ru-RU', { hour: '2-digit', minute: '2-digit', second: '2-digit' })
203
203
  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
204
+ process.stdout.write('\x1b[s')
205
+ _statusSaved = true
206
206
  if (errors?.length) {
207
+ process.stdout.write(` ${theme.folder(now)} ${theme.filename(file)} ${status}\n`)
207
208
  for (const err of errors) {
208
209
  printerr(err)
209
- _lastLines += 5
210
210
  }
211
211
  } else {
212
212
  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) {
213
+ const plainLine = ` ${now} ${file} ok `
214
+ const totalLen = plainLine.length
215
+ const startDelay = 5000
216
+ const charDelay = 22
217
+
218
+ process.stdout.write(` ${theme.folder(now)} ${theme.filename(file)} ${status}`)
219
+
220
+ for (let i = 1; i <= totalLen; i++) {
228
221
  _fadeTimers.push(setTimeout(() => {
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`)
234
- _lastLines = 0
222
+ if (_fadeId !== myId) return
223
+ process.stdout.write('\x1b[1D \x1b[1D')
224
+ if (i === totalLen) {
225
+ _statusSaved = false
235
226
  }
236
- }, delay))
227
+ }, startDelay + i * charDelay))
237
228
  }
238
229
  }
239
230
  }