ExceptionExtensions.GetRenderable() stretches panels and tables
Opened this issue · 0 comments
Information
- OS: Windows 10 22H2
- Version: 0.50.0
- Terminal: Windows Terminal
Describe the bug
When using ExceptionExtensions.GetRenderable() together with either a Panel or a Table, the Panel/Table gets weirdly padded on the right side, causing it to stretch all the way to the right side of the terminal, even if no part of the exception is anywhere near long enough to require that much space.
To Reproduce
Create a Panel or a Table and feed it the result of ExceptionExtensions.GetRenderable().
In my case, I'm using the following code:
ExceptionExtensions.GetRenderable(Error, ExceptionFormats.ShortenEverything)
Error in this context being a test exception generated via:
throw new AccessViolationException("You do not have permission to do that.")
Expected behavior
What I would like to do is something like this:

(Ignore the padding, I'm adding that since my hacky fix introduces a rogue newline)
Screenshots
Instead what I'm getting is this:

(All padding removed to showcase issue)
As you can see the table is weirdly stretched/padded on the right, when all I'm feeding it is an exception string that takes up less than half the terminal window width, even when not shortened.
Additional context
The issue can sort of be bypassed on tables by using table.Columns[0].Width(), but panels ignore both panel.Width and panel.Collapse() and stretch regardless of what you tell it.
In case anyone is interested and has use of it, my current hacky solution to this is to just drag the exception information and formatting out of the IRenderable and manually feed it to the Panel/Table as a (formatted) string:
IRenderable Ren = ExceptionExtensions.GetRenderable(Error, ExceptionFormats.ShortenEverything);
RenderOptions opt = RenderOptions.Create(AnsiConsole.Console);
StringBuilder sb = new StringBuilder();
foreach (Segment seg in Ren.Render(opt, 100))
{
if (string.IsNullOrEmpty(seg.Style.ToMarkup()))
{
sb.Append(seg.Text.EscapeMarkup());
}
else
{
sb.AppendFormat("[{0}]", seg.Style.ToMarkup());
sb.Append(seg.Text.EscapeMarkup());
sb.Append("[/]");
}
}But this introduces its own issues and overhead, like stray newlines mentioned above. It works, but it's not pretty.
I would much rather use GetRenderable() as intended instead. 😄
Please upvote 👍 this issue if you are interested in it.