NConsole icon indicating copy to clipboard operation
NConsole copied to clipboard

Multiline console update

Open amacal opened this issue 8 years ago • 4 comments

I would like to use NConsole to deliver such command line experience like curl or wget are doing.

$ curl -O http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
 28 3762k   28 1085k    0     0  72771      0  0:00:52  0:00:15  0:00:37 54267

In the example above only the last line can be updated. In my feature request I would like to be able to update all previously written lines to simulate multiple downloaded files at the same time.

amacal avatar Oct 11 '17 11:10 amacal

Is this even possible with System.Console? Do we just need a new method on IConsoleHost, eg ReplaceLine(offset, message)? Can you create a PR?

RicoSuter avatar Oct 11 '17 11:10 RicoSuter

Currently without abstraction I use quite often:

Console.SetCursorPosition(0, 5);
Console.WriteLine("...");

which produces the behaviour described by the request. One of the solution could be like you wrote, but I am open for any solution which looks nice and produces desired result.

amacal avatar Oct 11 '17 13:10 amacal

Currently you can just use Console.SetCursorPosition directly (not via IConsoleHost). Isn't this an option?

There are two problems when adding this new method:

  • We are breaking existing users because the interface has changed
  • What to do if SetCursorPosition is not supported for a specific IConsoleHost? Throw an exception? Do we need an additional property to check this? e.g. CanSetCursorPosition on IConsoleHost?

RicoSuter avatar Oct 11 '17 13:10 RicoSuter

Or create a new interface, IConsoleCursorPositionHost, that has a SetCursorPosition method.

JohnTasler avatar Nov 16 '18 20:11 JohnTasler