spectreconsole / spectre.console

A .NET library that makes it easier to create beautiful console applications.
https://spectreconsole.net
MIT License
8.9k stars 454 forks source link

More Clearing Methods #1570

Open marss72 opened 2 weeks ago

marss72 commented 2 weeks ago

Is your feature request related to a problem? Please describe. Currently, no, but I realized this could become an issue while planning future projects.

What I need: More clearing options, such as clearing the entire line, the whole screen, the end of the screen, and the beginning of the screen.

Describe the solution you'd like There are three possible ways to implement this. I prefer the third one as it seems cleaner and more implementable.

  1. Enum-based solution: Add a specific enum that would be passed when using AnsiConsole.Clear(enum). It could be named ClearingRange and could have values like EntireScreen, CurrentLine, ToEndOfLine.
  2. Static class solution: Replace the Clear method in AnsiConsole with a Clear static class that has static methods like EntireScreen, CurrentLine, ToEndOfLine. However, this syntax doesn't look nice and is too long.
  3. Markup key solution: Add a specific markup key like [clear line] or [clear:line], [clear:to end of line] (or possibly to eol).

Alternatively, a simpler solution would be to implement a method like AnsiSequences() in AnsiConsole that returns a single read-only instance for a specific console with as many ANSI codes as possible, possibly grouped into subclasses or more methods. It could work like this:

AnsiConsole.AnsiSequences().Clear().Line
// would return `ESC[2K` only if the current terminal supports it, otherwise an empty string

I think the markup solution is the best and clearest. However, it might not make sense to use [clear:line] Some very short line as it could be confusing.

Describe alternatives you've considered Using ANSI codes as they are, but this might break functionality when not supported. Check AnsiConsole.Profile.Capabilities every time or just once and then, if true, printing the code is too messy and long. It works, but there are much cleaner solutions.

Additional context This feature might not seem useful, but it would be especially helpful when rendering more complex lines that need to be updated often, without flickering.


Please upvote :+1: this issue if you are interested in it.