Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.CommandLine.Rendering.Terminal.Render(this ITerminal terminal, FormattableString value) reduces to string #2520

Closed
cpiber opened this issue Feb 14, 2025 · 2 comments

Comments

@cpiber
Copy link

cpiber commented Feb 14, 2025

The extension method incorrectly formats to a plain string before rendering, removing all styling. Instead, it should use the proper overload of RenderToRegion as shown in the samples:

consoleRenderer.RenderToRegion(
$"Call me {StyleSpan.BoldOn()}{StyleSpan.UnderlinedOn()}Ishmael{StyleSpan.UnderlinedOff()}{StyleSpan.BoldOff()}. Some years ago -- never mind how long precisely -- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen and regulating the circulation. Whenever I find myself growing grim about the mouth; whenever it is a damp, drizzly November in my soul; whenever I find myself involuntarily pausing before coffin warehouses, and bringing up the rear of every funeral I meet; and especially whenever my hypos get such an upper hand of me, that it requires a strong moral principle to prevent me from deliberately stepping into the street, and {ForegroundColorSpan.Rgb(60, 0, 0)}methodically{ForegroundColorSpan.Reset()} {ForegroundColorSpan.Rgb(90, 0, 0)}knocking{ForegroundColorSpan.Reset()} {ForegroundColorSpan.Rgb(120, 0, 0)}people's{ForegroundColorSpan.Reset()} {ForegroundColorSpan.Rgb(160, 0, 0)}hats{ForegroundColorSpan.Reset()} {ForegroundColorSpan.Rgb(220, 0, 0)}off{ForegroundColorSpan.Reset()} then, I account it high time to get to sea as soon as I can. This is my substitute for pistol and ball. With a philosophical flourish Cato throws himself upon his sword; I quietly take to the ship. There is nothing surprising in this. If they but knew it, almost all men in their degree, some time or other, cherish very nearly the same feelings towards the ocean with me.",
region);

with the current setup, the following code produces plain text:

var terminal = Console.GetTerminal();
terminal.Render($"Call me {StyleSpan.BoldOn()}{StyleSpan.UnderlinedOn()}Ishmael{StyleSpan.UnderlinedOff()}{StyleSpan.BoldOff()}.");

Currently I work around this via the following, which is based on the given extension method (but not using IRenderable since it's internal):

if (terminal is TerminalBase baseT)
{
  var renderer = new ConsoleRenderer(terminal, baseT.OutputMode);
  renderer.RenderToRegion(message, baseT.GetRegion());
}
@KalleOlaviNiemitalo
Copy link

System.CommandLine.Rendering is deprecated according to #1537 (comment) and dotnet/sdk#46209 (comment). I doubt this will be fixed.

@cpiber
Copy link
Author

cpiber commented Feb 14, 2025

Interesting, thanks for the info. I was using it since DragonFruit still depends on it, so it was already there

@cpiber cpiber closed this as not planned Won't fix, can't repro, duplicate, stale Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants