shellprogressbar icon indicating copy to clipboard operation
shellprogressbar copied to clipboard

ProgressBar.WriteLine doesn't show recent messages

Open gqqnbig opened this issue 4 years ago • 4 comments

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 avatar Feb 06 '21 03:02 gqqnbig

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

gqqnbig avatar Feb 06 '21 05:02 gqqnbig

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

TweakBox avatar Feb 10 '22 16:02 TweakBox

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

Mpdreamz avatar Jun 07 '22 18:06 Mpdreamz

(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

EddyToo avatar Dec 06 '22 20:12 EddyToo