spectre.console icon indicating copy to clipboard operation
spectre.console copied to clipboard

Iterate an list with an Progress bar

Open Ardumine opened this issue 6 months ago • 2 comments

Is your feature request related to a problem? Please describe. I have this code that I use to show the progress of a task and I want to makeit use the progress bar of Spectre: public static IEnumerable<T> ProgressBar<T>(IEnumerable<T> values) { int i = 0; foreach (var item in values) { yield return item; Console.Write($"{i++}/{values.Count()}"); } Console.WriteLine(" Done"); }

EXAMPLE:

var list = new List(){1,2,3,4,5,6,7,8}; foreach(var item in ProgressBar(list)){ ... }

Describe the solution you'd like I want to be able to iterate trough a list/IEnumerable and get progress of that iteration.

Describe alternatives you've considered Tried to use the AnsiConsole.Progress().Start but it creates an Func, making the yeld return not possible.

Please upvote :+1: this issue if you are interested in it.

Ardumine avatar May 21 '25 13:05 Ardumine

Hi @patriksvensson Can I pick up this issue if nobody is working on it?

Elementttto avatar Jun 02 '25 12:06 Elementttto

Hi. Any updates?

Ardumine avatar Jun 12 '25 13:06 Ardumine

Smart and seemingly straightforward addition. Would recommend ctx.TaskFromIEnumerable<TSource>(IEnumerable<TSource>, .. normal AddTask args), could make the description optional as well and just use the variable name of the list by default. Try casting to ICollection<TSource> if so you can get the length if not probably should default to indeterminate.

mitchcapper avatar Sep 18 '25 09:09 mitchcapper

Figured might as well just do it: https://github.com/spectreconsole/spectre.console/discussions/1903

mitchcapper avatar Sep 18 '25 19:09 mitchcapper

Hi, thanks for the answers, but im no longer actively working with this lib. As much as I like this library, I stopped using it because simple features are missing and also im not working for the project that used this lib.

I'm not saying that this lib is bad, im saying it is not compatible with the way I work. I must admit, the project makes beautiful TUI's in C#.

Thanks for the help from everyone. Great project.

Ardumine avatar Sep 19 '25 09:09 Ardumine