Mpdreamz / shellprogressbar

ShellProgressBar - display progress in your console application
MIT License
1.44k stars 134 forks source link

ProgressBar.WriteLine doesn't show recent messages #79

Open gqqnbig opened 3 years ago

gqqnbig commented 3 years ago

I will use a built-in test case as an example. I expect the built-in test case to work out of box.

Steps to reproduce:

clone this project and checkout c28355ff87d9ef277261a22cdfa91be2789a7fd0

apply this patch

--- src/ShellProgressBar.Example/Examples/PersistMessageExample.cs: c28355ff    2021-02-06 11:26:24.000000000 +0800
+++ src/ShellProgressBar.Example/Examples/PersistMessageExample.cs:     2021-02-06 11:22:24.000000000 +0800
@@ -46,12 +46,12 @@
        private static void LongRunningTask(FixedDurationBar bar)
        {
            for (var i = 0; i < 1_000_000; i++)
            {
                bar.Message = $"{i} events";
                if (bar.IsCompleted) break;
-               if (i % 500 == 0) bar.WriteLine($"Report {i} to console above the progressbar");
+               if (i % 5 == 0) bar.WriteLine($"Report {i} to console above the progressbar");
                Thread.Sleep(1);
            }
        }
    }
 }

Expected:

I expect to see Report 15 to console above the progressbar up to Report 1000 to console above the progressbar ,etc. while the progrss bar is running.

Actual

Latest messages don't show. See the screenshot. progress

gqqnbig commented 3 years ago

I tried to make a fix but ProgressBar.cs has way few comments that I can't figure out the purpose of variables.

TweakBox commented 2 years ago

I noticed that as time would go on, the progress bar would slowly "eat" up the spaces above it and it would overwrite anything that's above it

Mpdreamz commented 2 years ago

I can't replicate this on Linux, won't be able to test this on Windows for a while.

EddyToo commented 1 year ago

(Replaces previous comment)

This problem occurs (only) on windows because the windows console allows a BufferHeight > WindowHeight (causing a vertical scrollbar to appear). This also means that Console.WindowsTop will change when scrolling starts and that Console.CursorTop will be between Console.WindowTop and Console.WindowTop+Console.WindowHeight

On other platforms setting the Bufferheight will throw an exception. Getting it will return WindowHeight