More Clearing Methods
marss72 opened this issue · 0 comments
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.
- Enum-based solution: Add a specific enum that would be passed when using
AnsiConsole.Clear(enum)
. It could be namedClearingRange
and could have values likeEntireScreen
,CurrentLine
,ToEndOfLine
. - Static class solution: Replace the
Clear
method inAnsiConsole
with aClear
static class that has static methods likeEntireScreen
,CurrentLine
,ToEndOfLine
. However, this syntax doesn't look nice and is too long. - Markup key solution: Add a specific markup key like
[clear line]
or[clear:line]
,[clear:to end of line]
(or possiblyto 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 👍 this issue if you are interested in it.