Tyrrrz / CliFx

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

Add console dimensions to `IConsole` #90

Closed thegreatco closed 2 years ago

thegreatco commented 3 years ago

Can we add some way of determining the height/width of the output for IConsole. Similar to Console.WindowHeight and Console.WindowWidth? I've got a console app that needs to know how wide the window is that it is writing to.

Since this is abstracted, maybe we can either return null or NotImplementedException for implementations that don't support it? I don't have particularly strong feelings either way, but null could make for a better user experience, IConsole.Width.GetValueOrDefault(80) is nicer than trying to catch an exception.

Ideally I think we'd also wan to add SupportedOSPlatform and UnsupportedOSPlatform attributes where appropriate.

Tyrrrz commented 3 years ago

Should be fine to add. Nullable property makes the most sense.

Tyrrrz commented 3 years ago

On the other hand, I think returning default instead of null makes more sense for consistency reasons, because we already have IConsole.CursorLeft/IConsole.CursorTop that are not nullable and also depend on the presence of a terminal window.

thegreatco commented 2 years ago

Thanks @Tyrrrz!