Tyrrrz / CliFx

Class-first framework for building command-line interfaces
MIT License
1.5k stars 61 forks source link

Add cursor position control to IConsole interface #25

Closed thorhj closed 4 years ago

thorhj commented 5 years ago

Description

Sometimes you wish to overwrite previously entered output, e.g. when creating a loading bar or a spinner. This is not possible through the recommended IConsole instance, as it does not define contracts for controlling the cursor position.

Suggested solution

Add the following signatures to IConsole:

CursorLeft { get; set; }
CursorTop { get; set; }
CursorVisible { get; set; }
CursorSize { get; set; }
SetCursorPosition(int, int)

I suspect these have been left out of the interface because of the VirtualConsole implementation. Alternatively, a spinner class could be added to the framework similar to ProgressReporter.

Tyrrrz commented 4 years ago

Although not the same, overwriting is currently possible via \b control character. Here's an example: https://github.com/Tyrrrz/CliFx/blob/3883c831e9b69005a15f3f54517baa70a972fa7e/CliFx/Utilities/ProgressTicker.cs#L22-L26

I'm a bit wary of adding these methods to IConsole because I'm not entirely sure how they should be represented in VirtualConsole.