A way to to use System.Console.WindowWidth for redirected TextWriters.
See original GitHub issueIs your feature request related to a problem? Please describe.
In the current implementation if one uses a custom TextWriter/Output Stream the Tty
property returns true and this automatically leads to a situation where GetHeight()
and GetWidth()
return some default constants that can’t be controlled.
A user of the library can’t even prevent that because Profile and Capabilities are both sealed.
I currently use a custom TextWriter that later down the line ultimately writes to the real console out TextWriter, but the way Tty is implemented breaks the width and height detection an causes the output to wrap after 80 characters.
Describe the solution you’d like
I’m pretty open to ideas. The end result should be a situation where I can use a custom TextWriter and can somehow hook GetWidth and GetHeight. Manually setting width and height is not a good option because for a real console (like in my case) there are no good options to get a resize event so I would have to constantly poll System.Console.WindowWidth
and set the width for the profile.
Things I would try/consider:
- A way to overwrite the Tty flag (introduce a setter with a nullable backing field, like width and height in
Profile
) Probably the simplest solution? - Unseal
Capabilities
so users can change the tty behaviour - Unseal
Profile
so it can be derived from - Introduce an
IProfile
interface soIAnsiConsole
implementations can provide a different profile implementation
Describe alternatives you’ve considered
Polling System.Console.WindowWidth
and set the width for the profile (nothing I would seriously consider) or somehow fix it in a custom fork. Another possibility is to set Profile.Width = int.MaxValue;
and let the terminal do the line breaks, but this of course breaks almost all widgets.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
@Frassle Yes, that would work for
Paragraph
i.e.Write/WriteLine/Markup/MarkupLine
, but not for other kinds of widgets. For example, a table/grid/progress, etc would always need to pad with line breaks.To help match against some current logging behavior. The current code just writes out to console and lets the console do the wrapping which with a decent console means it will reflow word wrap as the terminal is resized. If we switch to writing out with spectre then we get hard breaks at whatever the console width is when we run.
I think it would also help with writing to things that really don’t really have a width like files. If you writing to a file your probably happy for your tables to just width expand to however much they need, but right justification doesn’t really make sense. Passing null instead of some large number would let the layout engines do something sensible there.
It would end up pretty much the same as soft_wrap in rich.