create_progress_bar

Function create_progress_bar 

Source
pub fn create_progress_bar(total: u64) -> ProgressBar
Expand description

Create a progress bar with consistent styling and configuration.

Creates a progress bar with customized styling that respects user configuration preferences. The progress bar can be hidden based on the enable_progress_bar configuration setting, allowing users to disable progress indicators if desired.

§Configuration Integration

The progress bar visibility is controlled by the configuration setting:

[general]
enable_progress_bar = true  # Show progress bars
# or
enable_progress_bar = false # Hide progress bars

§Progress Bar Features

  • Animated spinner: Indicates ongoing activity
  • Elapsed time: Shows time since operation started
  • Progress bar: Visual representation of completion percentage
  • ETA estimation: Estimated time to completion
  • Current/total counts: Numeric progress indicator

§Template Format

⠋ [00:01:23] [████████████████████████████████████████] 75/100 (00:00:17)

§Arguments

  • total - The total number of items to be processed

§Returns

A configured ProgressBar instance ready for use

§Examples

use subx_cli::cli::ui::create_progress_bar;

// Create progress bar for 100 items
let progress = create_progress_bar(100);

for i in 0..100 {
    // ... process item ...
    progress.inc(1);
     
    if i % 10 == 0 {
        progress.set_message(format!("Processing item {}", i));
    }
}

progress.finish_with_message("✓ All items processed successfully");

§Error Handling

If configuration loading fails, the progress bar will default to visible. This ensures that progress indication is available even when configuration is problematic.