dotnet / command-line-api

Command line parsing, invocation, and rendering of terminal output.
https://github.com/dotnet/command-line-api/wiki
MIT License
3.37k stars 378 forks source link

Incorrect ANSI escape codes #970

Open JayJeckel opened 4 years ago

JayJeckel commented 4 years ago

While moving a bunch of in-house console apps to dotnet core using System.CommandLine, I've come across a few bugs in the System.CommandLine.Rendering.Ansi class.

According to the ms docs Console Virtual Terminal Sequences and the wikipedia ANSI escape code article, the following also need correcting.

hackf5 commented 3 years ago

What you say may be correct, however the current implementation works, apart from Ansi.Cursor.Move.NextLine(), which is indeed broken.

I've added a new sample to the RenderingPlayground that demonstrates this. If you get this branch https://github.com/hackf5/command-line-api/tree/bug-970-ansi-escape-codes and run the RenderingPlayground sample it will load the new Cursor sample by default. This sample demonstrates that the cursor currently works as expected (I've fixed NextLine()) on Windows at least.

I would be happy to tidy this up and add some unit tests in order to close this bug.

hackf5 commented 3 years ago

I've reread the spec and

are fine; see here.

However, to be explicit I think that scroll up and down are better represented as:

since this exactly matches the spec.

I've updated the sample.

I will update the test cases later and submit a PR.