diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-13 17:55:24 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-13 17:55:24 +0000 |
| commit | 727010b2a97c5c1a96f9e5be6faa9af8a719be9c (patch) | |
| tree | 708b722aabf7aaa55560e20d51ad5c773afbcdae /src/lib/client.rs | |
| parent | 3d08ddfdbe26d259545e67f658bee462f4ad6f9c (diff) | |
fix: pre-add heading bar so it renders in expanded view
The heading bar was being inserted into the MultiProgress after the
draw target switch, but by then all relay bars were already finished
so indicatif did not re-render the layout. Pre-add the heading bar
at creation time (position 0, before relay bars) and only call
finish_with_message on it after the draw target switches to stderr.
Diffstat (limited to 'src/lib/client.rs')
| -rw-r--r-- | src/lib/client.rs | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/src/lib/client.rs b/src/lib/client.rs index 0c76fb1..e08b62b 100644 --- a/src/lib/client.rs +++ b/src/lib/client.rs | |||
| @@ -451,6 +451,20 @@ impl Connect for Client { | |||
| 451 | MultiProgress::with_draw_target(ProgressDrawTarget::hidden()) | 451 | MultiProgress::with_draw_target(ProgressDrawTarget::hidden()) |
| 452 | }; | 452 | }; |
| 453 | 453 | ||
| 454 | // Pre-add a heading bar at position 0 so it has a reserved slot | ||
| 455 | // before any relay bars are added. It stays hidden (draw target is | ||
| 456 | // hidden) until the timer reveals it. | ||
| 457 | let heading_bar = if !verbose && !is_test { | ||
| 458 | let bar = progress_reporter.add( | ||
| 459 | ProgressBar::new(0).with_style( | ||
| 460 | ProgressStyle::with_template("{msg}").unwrap(), | ||
| 461 | ), | ||
| 462 | ); | ||
| 463 | Some(bar) | ||
| 464 | } else { | ||
| 465 | None | ||
| 466 | }; | ||
| 467 | |||
| 454 | // Track whether the detail view has been revealed. Bars that finish | 468 | // Track whether the detail view has been revealed. Bars that finish |
| 455 | // before reveal have their finish_with_message deferred so they render | 469 | // before reveal have their finish_with_message deferred so they render |
| 456 | // correctly once the draw target switches from hidden to stderr. | 470 | // correctly once the draw target switches from hidden to stderr. |
| @@ -467,6 +481,7 @@ impl Connect for Client { | |||
| 467 | let detail_multi_for_timer = progress_reporter.clone(); | 481 | let detail_multi_for_timer = progress_reporter.clone(); |
| 468 | let spinner_for_timer = spinner_multi.as_ref().map(|(_, s)| s.clone()); | 482 | let spinner_for_timer = spinner_multi.as_ref().map(|(_, s)| s.clone()); |
| 469 | let reveal_state_for_timer = reveal_state.clone(); | 483 | let reveal_state_for_timer = reveal_state.clone(); |
| 484 | let heading_bar_for_timer = heading_bar.clone(); | ||
| 470 | let timer_handle = if !verbose && !is_test { | 485 | let timer_handle = if !verbose && !is_test { |
| 471 | let handle = tokio::spawn(async move { | 486 | let handle = tokio::spawn(async move { |
| 472 | tokio::time::sleep(Duration::from_millis(SPINNER_EXPAND_DELAY_MS)).await; | 487 | tokio::time::sleep(Duration::from_millis(SPINNER_EXPAND_DELAY_MS)).await; |
| @@ -477,17 +492,11 @@ impl Connect for Client { | |||
| 477 | // Switch draw target to make bars visible | 492 | // Switch draw target to make bars visible |
| 478 | detail_multi_for_timer | 493 | detail_multi_for_timer |
| 479 | .set_draw_target(ProgressDrawTarget::stderr()); | 494 | .set_draw_target(ProgressDrawTarget::stderr()); |
| 480 | // Add heading as a finished progress bar so it gets cleared | 495 | // Finish the pre-added heading bar now that the draw target |
| 481 | // along with the other bars by progress_reporter.clear(). | 496 | // is visible so indicatif actually renders it. |
| 482 | // Must be inserted after the draw target switch so that | 497 | if let Some(heading) = heading_bar_for_timer { |
| 483 | // finish_with_message renders it. | 498 | heading.finish_with_message("fetching updates..."); |
| 484 | let heading = detail_multi_for_timer.insert( | 499 | } |
| 485 | 0, | ||
| 486 | ProgressBar::new(0).with_style( | ||
| 487 | ProgressStyle::with_template("{msg}").unwrap(), | ||
| 488 | ), | ||
| 489 | ); | ||
| 490 | heading.finish_with_message("fetching updates..."); | ||
| 491 | // Mark as revealed and flush all bars that finished while | 500 | // Mark as revealed and flush all bars that finished while |
| 492 | // the draw target was hidden. Hold the lock across the flag | 501 | // the draw target was hidden. Hold the lock across the flag |
| 493 | // update and drain so no bar can slip through unseen (see | 502 | // update and drain so no bar can slip through unseen (see |