You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- inline this.#render logic. The initial setTimeout is only used during load(), so run it there instead.
- .unref() the progress bar's recurring timeout object
- reuse the progress bar's timeout object with .refresh() instead of making a new one every frame
- consolidate comments into one line and remove stale comments
- skip clearing the line on the first frame when resuming the spinner
- removed the test from $8631 as it was only testing that the very first frame of the spinner didn't clear the line, not any subsequent frames
This is built off of #8631, moving the "skip clearing the line..." logic into a flag that's passed during .resume()
// we get the chalk level based on a null stream meaning chalk will only use what it knows about the environment to get color support since we already determined in our definitions that we want to show colors.
223
+
// We get the chalk level based on a null stream, meaning chalk will only use what it knows about the environment to get color support since we already determined in our definitions that we want to show colors.
// Silent mode and some specific commands always hide run script banners
314
312
break
315
313
}elseif(this.#json){
316
314
// In json mode, change output to stderr since we don't want to break json parsing on stdout if the user is piping to jq or something.
317
-
// XXX: in a future (breaking?) change it might make sense for run-script to always output these banners with proc-log.output.error if we think they align closer with "logging" instead of "output"
315
+
// XXX: in a future (breaking?) change it might make sense for run-script to always output these banners with proc-log.output.error if we think they align closer with "logging" instead of "output".
318
316
level=output.KEYS.error
319
317
}
320
318
}
@@ -339,12 +337,12 @@ class Display {
339
337
break
340
338
341
339
caseinput.KEYS.read: {
342
-
// The convention when calling input.read is to pass in a single fn that returns the promise to await. resolve and reject are provided by proc-log
340
+
// The convention when calling input.read is to pass in a single fn that returns the promise to await. resolve and reject are provided by proc-log.
343
341
const[res,rej,p]=args
344
342
returninput.start(()=>p()
345
343
.then(res)
346
344
.catch(rej)
347
-
// Any call to procLog.input.read will render a prompt to the user, so we always add a single newline of output to stdout to move the cursor to the next line
345
+
// Any call to procLog.input.read will render a prompt to the user, so we always add a single newline of output to stdout to move the cursor to the next line.
// Wait 200 ms so we don't render the spinner for short durations
448
+
this.#timeout =setTimeout(()=>{
449
+
this.#timeout =null
450
+
this.#render()
451
+
},200)
452
+
// Make sure this timeout does not keep the process open
453
+
this.#timeout.unref()
451
454
}
452
455
453
456
off(){
@@ -464,7 +467,7 @@ class Progress {
464
467
}
465
468
466
469
resume(){
467
-
this.#render()
470
+
this.#render(true)
468
471
}
469
472
470
473
// If we are currently rendering the spinner we clear it before writing our line and then re-render the spinner after.
@@ -479,38 +482,31 @@ class Progress {
479
482
}
480
483
}
481
484
482
-
#render (ms){
483
-
if(ms){
484
-
this.#timeout =setTimeout(()=>{
485
-
this.#timeout =null
486
-
this.#renderSpinner()
487
-
},ms)
488
-
// Make sure this timeout does not keep the process open
489
-
this.#timeout.unref()
490
-
}else{
491
-
this.#renderSpinner()
492
-
}
493
-
}
494
-
495
-
#renderSpinner (){
485
+
#render (resuming){
496
486
if(!this.#rendering){
497
487
return
498
488
}
499
489
// We always attempt to render immediately but we only request to move to the next frame if it has been longer than our spinner frame duration since our last update
0 commit comments