spectre.console
spectre.console copied to clipboard
Iterate an list with an Progress bar
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
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.
Hi @patriksvensson Can I pick up this issue if nobody is working on it?
Hi. Any updates?
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.
Figured might as well just do it: https://github.com/spectreconsole/spectre.console/discussions/1903
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.