API Reference
RichText
Multicolour text: a sequence of spans, each literal text (never interpreted as markup) or markup, with a RichStyle. Rich text is accepted wherever text appears (table cells and headers, card and record fields, tree labels, titles, lane names, log lines, chart labels) and is itself a widget, so it can be written or placed in a layout directly. Colours and theme roles are resolved per colour tier when rendered; without colour the text stays readable.
Inheritance
- Object
- RichText
Remarks
Literal spans are safe for data: brackets and control characters are never interpreted. Build rich text with RichTextBuilder, RichText.FromMarkup, RichText.FromPieces (Write-Color style parallel arrays) or RichText.Gradient. RichText.ToString returns the plain text.
Usage
Explore 55 API references to this type
This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.
Returned or exposed by 28
- Property Choice.Badge
- Property Choice.RichTitle
- Property MenuItem.BadgeSource
- Property MenuItem.CurrentBadge
- Method ConsoleTextLayout.Parts
- Extension method RichText.WithAlignment
- Extension method RichText.WithOverflow
- Method RichText.Append
- Method RichText.AppendMarkup
- Method RichText.Concat
- Method RichText.From
- Method RichText.FromMarkup
- Method RichText.FromPieces
- Method RichText.Gradient
- Method RichText.Plain
- Method RichText.Split
- Method RichText.WithBaseStyle
- Property RichText.Empty
- Method RichTextBuilder.Build
- Method RichTextFluent.WithAlignment
- Method RichTextFluent.WithOverflow
- Property ChartItem.LabelText
- Property ChartSeries.NameText
- Property Lane.DetailText
- Property Lane.LabelText
- Property LogEntry.RichText
- Property ProgressRow.DetailText
- Property ProgressRow.LabelText
Accepted by parameters 27
- Method MenuItem.Badge
- Constructor Panel.Panel
- Extension method ITerminalTarget.WriteRich
- Method StatusContext.Update
- Method StatusLine.Compose
- Method StatusLine.Show
- Method TerminalTargetExtensions.WriteRich
- Method Terminal.WriteRich
- Method ConsoleTextLayout.Lines
- Method ConsoleTextLayout.Parts
- Extension method RichText.WithAlignment
- Extension method RichText.WithOverflow
- Method RichText.Concat
- Method RichTextBuilder.Append
- Method RichTextFluent.WithAlignment
- Method RichTextFluent.WithOverflow
- Method BarChart.Add
- Method Lanes.Add
- Method LineChart.AddSeries
- Constructor LogEntry.LogEntry
- Method LogRegion.Write
- Constructor Rule.Rule
- Method StackedBar.Add
- Method StatusList.Add
- Constructor TableColumn.TableColumn
- Method Tree.Add
- Method TreeNode.Add
Constructors
public RichText(IEnumerable<RichSegment> segments) #Creates rich text from segments.
Parameters
- segments System.Collections.Generic.IEnumerable<ConsoleMonster.Text.RichSegment>
- The segments, in order.
Methods
public RichText Append(String? text, RichStyle style = default) #RichTextReturns a copy with literal text appended.
Parameters
- text System.String?
- The text.
- style ConsoleMonster.Styling.RichStyle = default
- Its style.
Returns
The new rich text.
public RichText AppendMarkup(String? markup) #RichTextReturns a copy with markup appended.
Parameters
- markup System.String?
- The markup.
Returns
The new rich text.
public static RichText Concat(params RichText?[] parts) #RichTextJoins rich texts.
Parameters
- parts ConsoleMonster.Text.RichText?[]
- The parts.
Returns
The joined text.
public static RichText From(Object? value) #RichTextConverts a value: rich text passes through, anything else becomes literal text (its string form), so data is never interpreted as markup.
Parameters
- value System.Object?
- The value.
Returns
The rich text.
public static RichText FromMarkup(String? markup, RichStyle style = default) #RichTextRich text from Spectre-compatible markup ([bold lime]Ready[/] in [muted]3s[/]).
Parameters
- markup System.String?
- The markup.
- style ConsoleMonster.Styling.RichStyle = default
- A style around the whole markup.
Returns
The rich text.
Exceptions
ArgumentException– The markup is not valid.
public static RichText FromPieces(IReadOnlyList<String?> texts, IReadOnlyList<RichColor>? colors = null, IReadOnlyList<RichColor>? backgrounds = null, RichStyle style = default) #RichTextRich text from parallel arrays, as Write-Color takes them: piece i gets colour i and background i; pieces beyond the colours get the first colour (and the first background), as Write-Color does.
Parameters
- texts System.Collections.Generic.IReadOnlyList<System.String?>
- The pieces (literal).
- colors System.Collections.Generic.IReadOnlyList<ConsoleMonster.Styling.RichColor>? = null
- Foreground colours, or null.
- backgrounds System.Collections.Generic.IReadOnlyList<ConsoleMonster.Styling.RichColor>? = null
- Background colours, or null.
- style ConsoleMonster.Styling.RichStyle = default
- Decorations and a link applied to every piece.
Returns
The rich text.
public static RichText FromPieces(IReadOnlyList<Object?> pieces, IReadOnlyList<RichColor>? colors, IReadOnlyList<RichColor>? backgrounds, RichStyle style) #RichTextRich text from pieces as Write-ConsoleText takes them: strings (literal) or rich text (whose own colours win over the piece colours); piece i gets colour i and background i, and pieces beyond the colours get the first ones.
Parameters
- pieces System.Collections.Generic.IReadOnlyList<System.Object?>
- The pieces: strings, rich text, or values shown with their invariant text.
- colors System.Collections.Generic.IReadOnlyList<ConsoleMonster.Styling.RichColor>?
- Foreground colours, or null.
- backgrounds System.Collections.Generic.IReadOnlyList<ConsoleMonster.Styling.RichColor>?
- Background colours, or null.
- style ConsoleMonster.Styling.RichStyle
- Decorations, a link and the fallback colour applied to every piece.
Returns
The rich text.
public static RichText Gradient(String? text, RichColor from, RichColor to, RichStyle style = default, ITheme? theme = null) #RichTextLiteral text coloured as a gradient from one colour to another, per grapheme. Colours are 24-bit and are down-mapped per colour tier (on 16 colours the gradient becomes steps).
Parameters
- text System.String?
- The text.
- from ConsoleMonster.Styling.RichColor
- The first colour.
- to ConsoleMonster.Styling.RichColor
- The last colour.
- style ConsoleMonster.Styling.RichStyle = default
- Decorations, background and link for every grapheme.
- theme ConsoleMonster.Styling.ITheme? = null
- The theme that resolves role colours, or null for the dark theme.
Returns
The rich text.
public Size Measure(Constraints constraints, RenderContext context) #SizeReturns the size the widget wants within the constraints.
Parameters
- constraints ConsoleMonster.Layout.Constraints
- The space offered.
- context ConsoleMonster.Canvas.RenderContext
- Profile, theme and glyphs.
Returns
The desired size, never larger than the constraints.
public static RichText Plain(String? text, RichStyle style = default) #RichTextLiteral text with one style.
Parameters
- text System.String?
- The text (shown as written).
- style ConsoleMonster.Styling.RichStyle = default
- The style.
Returns
The rich text.
public Void Render(Region region, RenderContext context) #VoidRenders into a region. The region may be smaller or larger than the measured size.
Parameters
- region ConsoleMonster.Canvas.Region
- The target region.
- context ConsoleMonster.Canvas.RenderContext
- Profile, theme and glyphs.
public List<RichText> Split(String separator) #List<RichText>Splits the text at a separator, keeping each piece's styles. Markup segments are split on their text only when they contain no tags.
Parameters
- separator System.String
- The separator.
Returns
The parts (one when the separator does not occur).
public String ToMarkup() #StringThe text as Spectre-compatible markup: literal spans escaped, styled spans wrapped in tags, tabs expanded to the next multiple of eight cells. Pass it to any API that takes markup.
Returns
The markup.
public StyledText ToStyledText(RenderContext context) #StyledTextThe styled lines for a render context (theme and colour tier applied).
Parameters
- context ConsoleMonster.Canvas.RenderContext
- The render context.
Returns
The styled text.
public RichText WithBaseStyle(RichStyle style) #RichTextReturns a copy with a style layered under every span (span colours and decorations win).
Parameters
- style ConsoleMonster.Styling.RichStyle
- The style.
Returns
The new rich text.
Inherited Methods
Properties
Extension Methods
public static RichText WithAlignment(RichText richText, HorizontalAlignment value) #RichTextSets RichText.Alignment: Alignment when written as a widget (default left).
Parameters
- richText ConsoleMonster.Text.RichText
- The instance.
- value ConsoleMonster.Layout.HorizontalAlignment
- The value.
Returns
The same instance.
public static RichText WithOverflow(RichText richText, TextOverflow value) #RichTextSets RichText.Overflow: How the text fits when written as a widget (default wrap, keeping styles across lines).
Parameters
- richText ConsoleMonster.Text.RichText
- The instance.
- value ConsoleMonster.Widgets.TextOverflow
- The value.
Returns
The same instance.