Table of Contents

Constructor FormattableStringMessageWriter

Namespace
Ploch.CommandLine.Spectre.Output
Assembly
Ploch.CommandLine.Spectre.dll

FormattableStringMessageWriter(IAnsiConsole)

Renders a FormattableString as interpolated markup: the template is parsed as Spectre markup, the string values in the holes are escaped rather than parsed (a value of another type is formatted and its text parsed as markup, as Spectre.Console does), and the holes are formatted with the caller's format provider.

public FormattableStringMessageWriter(IAnsiConsole output)

Parameters

output IAnsiConsole

The console the messages are written to.

Remarks

This is the writer Write<TMessage>(TMessage, IFormatProvider?) selects for a FormattableString, so a consumer that registers its own IMessageWriter<TMessage> for that type through AddMessageWriter<TMessageType, TWriter>(IServiceCollection) replaces it. The holes are deliberately not run through the registered IMessageFormatter instances: the formatters pre-render each argument to a string, which drops a format specifier such as {total:N2}, hides an argument from an ICustomFormatter supplied by the provider, and replaces an exception's ToString() with the formatter's text. A writer that wants that behaviour can call GetMessageText(FormattableString?, string?, IFormatProvider?) itself.