### Installation Source: https://context7.com/mpdreamz/shellprogressbar/llms.txt Install the ShellProgressBar library using the .NET CLI. ```APIDOC ## Installation Install ShellProgressBar via NuGet package manager. ```bash dotnet add package ShellProgressBar ``` ``` -------------------------------- ### Integrate with IProgress Interface in C# Source: https://context7.com/mpdreamz/shellprogressbar/llms.txt Shows how to use the AsProgress() method to get an IProgress instance for seamless integration with .NET async patterns. Supports custom message formatting and percentage calculation based on the reported value type. ```csharp using ShellProgressBar; using System.IO; // Example 1: Progress with FileInfo - custom message from value var files = new List { new FileInfo("file1.txt"), new FileInfo("file2.txt"), new FileInfo("file3.txt") }; using (var pbar = new ProgressBar(files.Count, "Processing files")) { // Create IProgress with custom message formatter IProgress progress = pbar.AsProgress( message: file => $"Processed {file.Name}" ); foreach (var file in files) { // Simulate work Thread.Sleep(500); progress.Report(file); // Advances tick and updates message } } // Example 2: Progress with float percentage (0.0 to 1.0) using (var pbar = new ProgressBar(100, "Downloading...")) { IProgress progress = pbar.AsProgress(); for (int i = 0; i <= 100; i += 10) { Thread.Sleep(200); progress.Report(i / 100f); // Report as 0.0 to 1.0 } } // Output: Progress bar at 100% showing "Downloading..." ``` -------------------------------- ### Install ShellProgressBar via NuGet Source: https://context7.com/mpdreamz/shellprogressbar/llms.txt This command installs the ShellProgressBar NuGet package into your .NET project, enabling you to use its features for creating console progress bars. ```bash dotnet add package ShellProgressBar ``` -------------------------------- ### C# Deeply Nested Progress Bars Source: https://context7.com/mpdreamz/shellprogressbar/llms.txt Demonstrates creating and managing deeply nested progress bars using ShellProgressBar. Each level can have independent styling and collapse behavior, inheriting from its parent. This example shows a three-level hierarchy with custom options for each level. ```csharp using ShellProgressBar; var rootOptions = new ProgressBarOptions { ForegroundColor = ConsoleColor.White, CollapseWhenFinished = false }; var level1Options = new ProgressBarOptions { ForegroundColor = ConsoleColor.Yellow, CollapseWhenFinished = true }; var level2Options = new ProgressBarOptions { ForegroundColor = ConsoleColor.Green, CollapseWhenFinished = true }; using (var root = new ProgressBar(3, "Root: Processing batches", rootOptions)) { for (int batch = 0; batch < 3; batch++) { using (var level1 = root.Spawn(4, $ ``` -------------------------------- ### Initialize and Update Basic Progress Bar Source: https://github.com/mpdreamz/shellprogressbar/blob/master/README.md Demonstrates how to instantiate a ProgressBar with custom options and manually advance it using the Tick method. ```csharp const int totalTicks = 10; var options = new ProgressBarOptions { ProgressCharacter = '─', ProgressBarOnBottom = true }; using (var pbar = new ProgressBar(totalTicks, "Initial message", options)) { pbar.Tick(); pbar.Tick("Step 2 of 10"); } ``` -------------------------------- ### Create a Basic Console Progress Bar in C# Source: https://context7.com/mpdreamz/shellprogressbar/llms.txt Demonstrates how to create and use a basic progress bar using the ProgressBar class. It initializes a progress bar with a total tick count, a message, and custom options, then advances it using the Tick() method within a using statement. ```csharp using ShellProgressBar; const int totalTicks = 100; var options = new ProgressBarOptions { ProgressCharacter = '─', ProgressBarOnBottom = true }; using (var pbar = new ProgressBar(totalTicks, "Processing items...", options)) { for (int i = 0; i < totalTicks; i++) { // Do work here Thread.Sleep(50); // Advance progress by 1 tick pbar.Tick(); } } // Output: Progress bar showing "Processing items..." with elapsed time ``` -------------------------------- ### Report Progress via IProgress Interface Source: https://github.com/mpdreamz/shellprogressbar/blob/master/README.md Shows how to integrate ShellProgressBar with the standard IProgress interface for reporting completion percentages. ```csharp using ProgressBar progressBar = new ProgressBar(10000, "My Progress Message"); IProgress progress = progressBar.AsProgress(); progress.Report(0.25f); ``` -------------------------------- ### Creating a Basic Progress Bar Source: https://context7.com/mpdreamz/shellprogressbar/llms.txt Demonstrates how to create and use a basic progress bar with a specified maximum tick count and message. The progress bar is managed within a `using` statement for proper disposal. ```APIDOC ## Creating a Basic Progress Bar The `ProgressBar` class is the main entry point for displaying progress. It implements `IDisposable` and should be used within a `using` statement. The constructor takes a maximum tick count, a message, and optional configuration options. ```csharp using ShellProgressBar; const int totalTicks = 100; var options = new ProgressBarOptions { ProgressCharacter = '─', ProgressBarOnBottom = true }; using (var pbar = new ProgressBar(totalTicks, "Processing items...", options)) { for (int i = 0; i < totalTicks; i++) { // Do work here Thread.Sleep(50); // Advance progress by 1 tick pbar.Tick(); } } // Output: Progress bar showing "Processing items..." with elapsed time ``` ``` -------------------------------- ### ProgressBar Initialization Source: https://github.com/mpdreamz/shellprogressbar/blob/master/README.md Initializes a new progress bar instance with a specified number of ticks and configuration options. ```APIDOC ## Constructor: ProgressBar(int totalTicks, string message, ProgressBarOptions options) ### Description Creates a new progress bar instance to track long-running tasks in the console. ### Parameters #### Path Parameters - **totalTicks** (int) - Required - The total number of steps to complete. - **message** (string) - Required - Initial text displayed next to the progress bar. - **options** (ProgressBarOptions) - Optional - Configuration object for styling and behavior. ### Request Example ```csharp var options = new ProgressBarOptions { ProgressCharacter = '─', ProgressBarOnBottom = true }; using (var pbar = new ProgressBar(10, "Initial message", options)) { ... } ``` ``` -------------------------------- ### Apply Custom Styling Source: https://github.com/mpdreamz/shellprogressbar/blob/master/README.md Shows how to customize the visual appearance of the progress bar, including foreground and background colors and characters. ```csharp const int totalTicks = 10; var options = new ProgressBarOptions { ForegroundColor = ConsoleColor.Yellow, ForegroundColorDone = ConsoleColor.DarkGreen, BackgroundColor = ConsoleColor.DarkGray, BackgroundCharacter = '\u2593' }; using (var pbar = new ProgressBar(totalTicks, "showing off styling", options)) { TickToCompletion(pbar, totalTicks, sleep: 500); } ``` -------------------------------- ### Create Nested Child Progress Bars with Spawn() in C# Source: https://context7.com/mpdreamz/shellprogressbar/llms.txt Demonstrates how to create hierarchical progress bars using the Spawn() method. Child bars can inherit options from the parent and be configured to collapse upon completion, useful for visualizing concurrent or dependent tasks. ```csharp using ShellProgressBar; const int totalTicks = 5; var parentOptions = new ProgressBarOptions { ForegroundColor = ConsoleColor.Yellow, BackgroundColor = ConsoleColor.DarkGray, ProgressCharacter = '─' }; var childOptions = new ProgressBarOptions { ForegroundColor = ConsoleColor.Green, BackgroundColor = ConsoleColor.DarkGray, ProgressCharacter = '─', CollapseWhenFinished = true // Remove when done (default: false) }; using (var pbar = new ProgressBar(totalTicks, "Main task", parentOptions)) { for (int i = 0; i < totalTicks; i++) { // Spawn a child progress bar for each subtask using (var child = pbar.Spawn(10, $ ``` -------------------------------- ### Create nested progress bars in C# Source: https://github.com/mpdreamz/shellprogressbar/blob/master/README.md Demonstrates how to spawn child progress bars from a parent progress bar. Each progress bar can have custom styling options and manage its own lifecycle. ```csharp const int totalTicks = 10; var options = new ProgressBarOptions { ForegroundColor = ConsoleColor.Yellow, BackgroundColor = ConsoleColor.DarkYellow, ProgressCharacter = '─' }; var childOptions = new ProgressBarOptions { ForegroundColor = ConsoleColor.Green, BackgroundColor = ConsoleColor.DarkGreen, ProgressCharacter = '─' }; using (var pbar = new ProgressBar(totalTicks, "main progressbar", options)) { TickToCompletion(pbar, totalTicks, sleep: 10, childAction: () => { using (var child = pbar.Spawn(totalTicks, "child actions", childOptions)) { TickToCompletion(child, totalTicks, sleep: 100); } }); } ``` -------------------------------- ### Configure ProgressBarOptions for Customization in C# Source: https://context7.com/mpdreamz/shellprogressbar/llms.txt Shows how to customize the appearance and behavior of a progress bar using the ProgressBarOptions class. This includes setting colors, characters, layout, timing, and specific behaviors like collapsing when finished or enabling taskbar progress. ```csharp using ShellProgressBar; var options = new ProgressBarOptions { // Colors ForegroundColor = ConsoleColor.Yellow, ForegroundColorDone = ConsoleColor.DarkGreen, ForegroundColorError = ConsoleColor.Red, BackgroundColor = ConsoleColor.DarkGray, // Characters ProgressCharacter = '─', BackgroundCharacter = '\u2593', // Layout ProgressBarOnBottom = true, // Swap bar and message position DenseProgressBar = false, // Single line compact mode // Timing DisplayTimeInRealTime = true, // Auto-update every 500ms (default: true) ShowEstimatedDuration = true, // Display estimated time remaining // Behavior CollapseWhenFinished = false, // Keep visible after completion DisableBottomPercentage = false, // Hide percentage display PercentageFormat = "{0:N2}% ", // Custom percentage format // Windows-specific EnableTaskBarProgress = true // Show progress in Windows taskbar }; using (var pbar = new ProgressBar(100, "Styled progress bar", options)) { pbar.EstimatedDuration = TimeSpan.FromSeconds(10); for (int i = 0; i < 100; i++) { Thread.Sleep(100); pbar.Tick($"Processing item {i + 1} of 100"); } } ``` -------------------------------- ### Configure Progress Bar Position Source: https://github.com/mpdreamz/shellprogressbar/blob/master/README.md Demonstrates how to move the progress bar to the bottom of the console output using ProgressBarOptions. ```csharp const int totalTicks = 10; var options = new ProgressBarOptions { ProgressCharacter = '─', ProgressBarOnBottom = true }; using (var pbar = new ProgressBar(totalTicks, "progress bar is on the bottom now", options)) { TickToCompletion(pbar, totalTicks, sleep: 500); } ``` -------------------------------- ### Creating Descendant Progress Bars Source: https://github.com/mpdreamz/shellprogressbar/blob/master/README.md Explains how to spawn child progress bars from a parent progress bar to visualize concurrent tasks. ```APIDOC ## Spawning Child Progress Bars ### Description Allows a parent progress bar to spawn child progress bars, each with independent styling options, to visualize concurrent tasks. ### Method N/A (Library Method) ### Endpoint ProgressBar.Spawn(int totalTicks, string message, ProgressBarOptions options) ### Parameters #### Path Parameters - **totalTicks** (int) - Required - The total number of ticks for the child bar. - **message** (string) - Required - The label for the child bar. - **options** (ProgressBarOptions) - Required - Styling configuration for the child bar. ### Request Example ```csharp using (var child = pbar.Spawn(10, "child actions", childOptions)) { child.Tick(); } ``` ### Response #### Success Response (Object) - **child** (ProgressBar) - The spawned child progress bar instance. ``` -------------------------------- ### Configuring ProgressBarOptions Source: https://context7.com/mpdreamz/shellprogressbar/llms.txt Details the `ProgressBarOptions` class for customizing the appearance and behavior of progress bars, including colors, characters, timing, and layout. ```APIDOC ## Configuring ProgressBarOptions `ProgressBarOptions` controls the appearance and behavior of progress bars including colors, characters, timing, and layout. Configure foreground/background colors, completion colors, error colors, progress characters, and display preferences. ```csharp using ShellProgressBar; var options = new ProgressBarOptions { // Colors ForegroundColor = ConsoleColor.Yellow, ForegroundColorDone = ConsoleColor.DarkGreen, ForegroundColorError = ConsoleColor.Red, BackgroundColor = ConsoleColor.DarkGray, // Characters ProgressCharacter = '─', BackgroundCharacter = '\u2593', // Layout ProgressBarOnBottom = true, // Swap bar and message position DenseProgressBar = false, // Single line compact mode // Timing DisplayTimeInRealTime = true, // Auto-update every 500ms (default: true) ShowEstimatedDuration = true, // Display estimated time remaining // Behavior CollapseWhenFinished = false, // Keep visible after completion DisableBottomPercentage = false, // Hide percentage display PercentageFormat = "{0:N2}% ", // Custom percentage format // Windows-specific EnableTaskBarProgress = true // Show progress in Windows taskbar }; using (var pbar = new ProgressBar(100, "Styled progress bar", options)) { pbar.EstimatedDuration = TimeSpan.FromSeconds(10); for (int i = 0; i < 100; i++) { Thread.Sleep(100); pbar.Tick($"Processing item {i + 1} of 100"); } } ``` ``` -------------------------------- ### Configure child progress bar persistence Source: https://github.com/mpdreamz/shellprogressbar/blob/master/README.md Shows how to prevent child progress bars from collapsing automatically upon completion by setting the CollapseWhenFinished property to false. ```csharp var childOptions = new ProgressBarOptions { ForegroundColor = ConsoleColor.Green, BackgroundColor = ConsoleColor.DarkGreen, ProgressCharacter = '─', CollapseWhenFinished = false }; ``` -------------------------------- ### Advancing Progress with Tick() Source: https://context7.com/mpdreamz/shellprogressbar/llms.txt Explains the different overloads of the `Tick()` method for advancing the progress bar, including incrementing by one, setting to a specific count, updating the message, and setting estimated duration. All overloads are thread-safe. ```APIDOC ## Advancing Progress with Tick() The `Tick()` method advances the progress bar. It supports multiple overloads: increment by one, set to a specific tick count, update the message, and set estimated duration. All overloads are thread-safe. ```csharp using ShellProgressBar; const int totalTicks = 10; using (var pbar = new ProgressBar(totalTicks, "Starting...")) { // Tick with no arguments - increments by 1 pbar.Tick(); // Tick with message update pbar.Tick("Processing step 2 of 10"); // Tick to specific count with message pbar.Tick(5, "Jumped to step 5"); // Tick with estimated duration pbar.Tick(TimeSpan.FromSeconds(30), "Step 6 - 30 seconds remaining"); // Tick with specific count and estimated duration pbar.Tick(8, TimeSpan.FromSeconds(10), "Almost done..."); // Complete remaining ticks pbar.Tick(10, "Completed!"); } ``` ``` -------------------------------- ### FixedDurationBar Usage Source: https://github.com/mpdreamz/shellprogressbar/blob/master/README.md Documentation for the FixedDurationBar subclass used for tasks with a known runtime. ```APIDOC ## FixedDurationBar ### Description A subclass of ProgressBar designed for tasks with a known fixed duration. It automatically handles ticking based on real-time updates. ### Method N/A (Class Initialization) ### Endpoint new FixedDurationBar(int totalTicks, string message, ProgressBarOptions options) ### Parameters #### Request Body - **totalTicks** (int) - Required - Total ticks for the duration. - **message** (string) - Required - Display message. - **options** (ProgressBarOptions) - Required - Configuration options. ### Response #### Success Response - **IsCompleted** (bool) - Returns true if the fixed duration has elapsed. - **CompletedHandle** (object) - Handle for the completion state. ``` -------------------------------- ### Advance Progress Bar with Tick() Overloads in C# Source: https://context7.com/mpdreamz/shellprogressbar/llms.txt Illustrates the various overloads of the Tick() method for advancing the progress bar. This includes incrementing by one, updating the message, setting to a specific tick count, and specifying estimated durations, all of which are thread-safe. ```csharp using ShellProgressBar; const int totalTicks = 10; using (var pbar = new ProgressBar(totalTicks, "Starting...")) { // Tick with no arguments - increments by 1 pbar.Tick(); // Tick with message update pbar.Tick("Processing step 2 of 10"); // Tick to specific count with message pbar.Tick(5, "Jumped to step 5"); // Tick with estimated duration pbar.Tick(TimeSpan.FromSeconds(30), "Step 6 - 30 seconds remaining"); // Tick with specific count and estimated duration pbar.Tick(8, TimeSpan.FromSeconds(10), "Almost done..."); // Complete remaining ticks pbar.Tick(10, "Completed!"); } ``` -------------------------------- ### Write messages above progress bar in C# Source: https://context7.com/mpdreamz/shellprogressbar/llms.txt Demonstrates using WriteLine and WriteErrorLine to output messages above the progress bar. WriteErrorLine also triggers error color styling by setting the ObservedError flag. ```csharp using ShellProgressBar; var options = new ProgressBarOptions { ForegroundColor = ConsoleColor.Green, ForegroundColorError = ConsoleColor.Red }; using (var pbar = new ProgressBar(100, "Processing with logging", options)) { for (int i = 0; i < 100; i++) { Thread.Sleep(50); if (i % 20 == 0) { pbar.WriteLine($"Checkpoint: Completed {i}% of processing"); } if (i == 75) { pbar.WriteErrorLine("Warning: Encountered non-critical error at step 75"); } pbar.Tick(); } } ``` -------------------------------- ### Use FixedDurationBar for Time-Based Progress in C# Source: https://context7.com/mpdreamz/shellprogressbar/llms.txt Illustrates the use of FixedDurationBar for tasks with a known duration. The bar automatically ticks based on elapsed time and provides IsCompleted property and CompletedHandle wait handle for coordination with long-running operations. ```csharp using ShellProgressBar; var options = new ProgressBarOptions { ForegroundColor = ConsoleColor.Yellow, ForegroundColorDone = ConsoleColor.DarkGreen, BackgroundColor = ConsoleColor.DarkGray, BackgroundCharacter = '\u2593' }; var duration = TimeSpan.FromSeconds(5); using (var pbar = new FixedDurationBar(duration, "Time-based operation", options)) { // Start background work in separate thread var worker = new Thread(() => { int eventCount = 0; while (!pbar.IsCompleted) { eventCount++; pbar.Message = $"Processed {eventCount} events"; Thread.Sleep(10); } }); worker.Start(); // Wait for duration to complete if (!pbar.CompletedHandle.WaitOne(duration.Add(TimeSpan.FromSeconds(1)))) { Console.Error.WriteLine("Progress bar did not complete in expected time"); } worker.Join(); } // Output: Progress bar that auto-advances over 5 seconds ``` -------------------------------- ### Progress Reporting Source: https://github.com/mpdreamz/shellprogressbar/blob/master/README.md Methods to update the progress bar state, either manually via Tick() or via IProgress interface. ```APIDOC ## Method: Tick() ### Description Advances the progress bar by one step or updates the current status message. ### Parameters - **message** (string) - Optional - New status message to display. --- ## Method: AsProgress() ### Description Returns an IProgress instance to integrate with standard .NET asynchronous patterns. ### Parameters - **T** (float) - Required - A value between 0.0 and 1.0 representing completion percentage. ### Request Example ```csharp IProgress progress = progressBar.AsProgress(); progress.Report(0.25); // Advances to 25% ``` ``` -------------------------------- ### Use IndeterminateProgressBar for Unknown Duration in C# Source: https://context7.com/mpdreamz/shellprogressbar/llms.txt Explains how to use IndeterminateProgressBar for operations where the duration is unknown. The bar displays a continuously cycling animation until the Finished() method is called to signal completion. ```csharp using ShellProgressBar; var options = new ProgressBarOptions { ForegroundColor = ConsoleColor.Cyan, BackgroundColor = ConsoleColor.DarkGray, ProgressCharacter = '─' }; using (var pbar = new IndeterminateProgressBar("Loading data...", options)) { // Simulate unknown-duration operation Thread.Sleep(3000); pbar.Message = "Almost done..."; Thread.Sleep(1000); // Signal completion pbar.Finished(); } // Output: Animated cycling progress bar until Finished() is called ``` -------------------------------- ### Customize message formatting with WriteQueuedMessage in C# Source: https://context7.com/mpdreamz/shellprogressbar/llms.txt Uses the WriteQueuedMessage option to intercept and format messages written above the progress bar. The delegate allows for custom logic like adding timestamps or color-coding based on error status. ```csharp using ShellProgressBar; var options = new ProgressBarOptions { ForegroundColor = ConsoleColor.Yellow, WriteQueuedMessage = line => { var writer = line.Error ? Console.Error : Console.Out; var color = line.Error ? ConsoleColor.DarkRed : ConsoleColor.Blue; Console.ForegroundColor = ConsoleColor.Gray; writer.Write($"[{DateTime.Now:HH:mm:ss}] "); Console.ForegroundColor = color; writer.WriteLine(line.Line); return 1; } }; using (var pbar = new ProgressBar(50, "Custom message formatting", options)) { for (int i = 0; i < 50; i++) { Thread.Sleep(100); if (i % 10 == 0) { pbar.WriteLine($"Progress milestone: {i * 2}%"); } pbar.Tick(); } } ``` -------------------------------- ### Update MaxTicks and Message dynamically in C# Source: https://context7.com/mpdreamz/shellprogressbar/llms.txt Shows how to modify the MaxTicks and Message properties of a running progress bar. This is useful when the total scope of work changes during execution. ```csharp using ShellProgressBar; using (var pbar = new ProgressBar(10, "Initial work", new ProgressBarOptions { ForegroundColor = ConsoleColor.Cyan })) { for (int i = 0; i < 5; i++) { Thread.Sleep(200); pbar.Tick($"Step {i + 1} of {pbar.MaxTicks}"); } pbar.MaxTicks = 20; pbar.Message = "Found additional items to process"; for (int i = 5; i < 20; i++) { Thread.Sleep(100); pbar.Tick($"Step {i + 1} of {pbar.MaxTicks}"); } } ``` -------------------------------- ### Show estimated duration in C# Source: https://context7.com/mpdreamz/shellprogressbar/llms.txt Configures the progress bar to display estimated time remaining. The estimate is managed via the EstimatedDuration property or passed directly into the Tick method. ```csharp using ShellProgressBar; const int totalTicks = 20; var estimatedTimePerTick = TimeSpan.FromMilliseconds(250); var options = new ProgressBarOptions { ProgressCharacter = '─', ShowEstimatedDuration = true }; using (var pbar = new ProgressBar(totalTicks, "Task with time estimate", options)) { pbar.EstimatedDuration = TimeSpan.FromMilliseconds(totalTicks * 250); for (int i = 0; i < totalTicks; i++) { Thread.Sleep(250); var remaining = (totalTicks - i - 1) * estimatedTimePerTick; pbar.Tick(remaining, $"Processing step {i + 1}"); } } ``` -------------------------------- ### Disable Real-Time Updates Source: https://github.com/mpdreamz/shellprogressbar/blob/master/README.md Configures the progress bar to update only when the Tick method is called, rather than using an automatic timer. ```csharp const int totalTicks = 5; var options = new ProgressBarOptions { DisplayTimeInRealTime = false }; using (var pbar = new ProgressBar(totalTicks, "only draw progress on tick", options)) { TickToCompletion(pbar, totalTicks, sleep: 1750); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.