Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progress not staying on one line #91

Open
joshcomley opened this issue Sep 13, 2021 · 1 comment
Open

Progress not staying on one line #91

joshcomley opened this issue Sep 13, 2021 · 1 comment

Comments

@joshcomley
Copy link

joshcomley commented Sep 13, 2021

Edit: I'm using .NET 5.

If I have this code (from examples just with an async delay):

public class Program
{
    public static async Task Main(string[] args)
    {
        const int totalTicks = 10;
        var options = new ProgressBarOptions
        {
            ProgressCharacter = '─',
            ProgressBarOnBottom = true
        };
        using (var pbar = new ProgressBar(totalTicks, "Initial message", options))
        {
            for (var i = 0; i < totalTicks; i++)
            {
                pbar.Tick(); //will advance pbar to 1 out of 10.
                await Task.Delay(1000);
            }
        }
    }
}

Then my output looks like this:

image

If I run it non-async with Thread.Sleep(x) as follows:

public class Program
{
    public static void Main(string[] args)
    {
        const int totalTicks = 10;
        var options = new ProgressBarOptions
        {
            ProgressCharacter = '─',
            ProgressBarOnBottom = true
        };
        var pbar = new ProgressBar(totalTicks, "Initial message", options);
        for (var i = 0; i < totalTicks; i++)
        {
            pbar.Tick(); //will advance pbar to 1 out of 10.
            Thread.Sleep(1000);
        }
    }
}

My output looks like this:

image

What am I doing wrong? My understanding is it should appear on one line and continuously update that line.

Many thanks!

@TweakBox
Copy link

I also noticed that the ProgressBar would slowly clear the lines above it and replace the line as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants