Table of Contents

Class MarkupBuilder

Namespace
SharpConsoleUI.Builders
Assembly
SharpConsoleUI.dll

Fluent builder for markup controls

public sealed class MarkupBuilder : IControlBuilder<MarkupControl>
Inheritance
MarkupBuilder
Implements
Inherited Members
Extension Methods

Methods

AddEmptyLine()

Adds an empty line

public MarkupBuilder AddEmptyLine()

Returns

MarkupBuilder

The builder for chaining

AddLine(string)

Adds a line of markup text

public MarkupBuilder AddLine(string markup)

Parameters

markup string

The markup text

Returns

MarkupBuilder

The builder for chaining

AddLines(params string[])

Adds multiple lines of markup text

public MarkupBuilder AddLines(params string[] markupLines)

Parameters

markupLines string[]

The markup lines

Returns

MarkupBuilder

The builder for chaining

AddMarkdown(string)

Appends a Markdown block, wrapped in a [markdown] region.

public MarkupBuilder AddMarkdown(string markdown)

Parameters

markdown string

The Markdown content.

Returns

MarkupBuilder

This builder for chaining.

AddText(string)

Alias for Append(string), retained for compatibility. Prefer Append(string) (matches the .NET StringBuilder.Append / Console.Write convention).

public MarkupBuilder AddText(string markup)

Parameters

markup string

The markup text

Returns

MarkupBuilder

The builder for chaining

AlignBottom()

Aligns content to the bottom

public MarkupBuilder AlignBottom()

Returns

MarkupBuilder

The builder for chaining

AlignTop()

Aligns content to the top

public MarkupBuilder AlignTop()

Returns

MarkupBuilder

The builder for chaining

Append(string)

Appends markup to the current last line without starting a new line, in the style of Append(string) / Console.Write: the first segment is joined onto the line added so far, and a new line begins only at each embedded \n. Use AddLine(string) when you want each call to start on its own line.

public MarkupBuilder Append(string markup)

Parameters

markup string

The markup text

Returns

MarkupBuilder

The builder for chaining

Build()

Builds the markup control

public MarkupControl Build()

Returns

MarkupControl

The configured markup control

Centered()

Centers the content horizontally

public MarkupBuilder Centered()

Returns

MarkupBuilder

The builder for chaining

Clear()

Clears all lines

public MarkupBuilder Clear()

Returns

MarkupBuilder

The builder for chaining

FillVertical()

Makes the content fill vertically

public MarkupBuilder FillVertical()

Returns

MarkupBuilder

The builder for chaining

NoBorder()

Shortcut to remove the border.

public MarkupBuilder NoBorder()

Returns

MarkupBuilder

The builder for chaining.

OnLinkClicked(EventHandler<LinkClickedEventArgs>)

Sets the handler raised when a rendered link is clicked.

public MarkupBuilder OnLinkClicked(EventHandler<LinkClickedEventArgs> handler)

Parameters

handler EventHandler<LinkClickedEventArgs>

The LinkClicked event handler.

Returns

MarkupBuilder

The builder for chaining.

Outline(bool)

Renders the role accent in outline style.

public MarkupBuilder Outline(bool outline = true)

Parameters

outline bool

Whether to use outline style.

Returns

MarkupBuilder

The builder for chaining.

Rounded()

Shortcut for a rounded border.

public MarkupBuilder Rounded()

Returns

MarkupBuilder

The builder for chaining.

StickyBottom()

Makes the control stick to the bottom of the window

public MarkupBuilder StickyBottom()

Returns

MarkupBuilder

The builder for chaining

StickyTop()

Makes the control stick to the top of the window

public MarkupBuilder StickyTop()

Returns

MarkupBuilder

The builder for chaining

UseSafeBorder(bool)

Uses ASCII-safe border glyphs for terminals that render box-drawing characters poorly.

public MarkupBuilder UseSafeBorder(bool useSafe = true)

Parameters

useSafe bool

Whether to use safe border glyphs. Defaults to true.

Returns

MarkupBuilder

The builder for chaining.

VerticallyCentered()

Centers the content vertically

public MarkupBuilder VerticallyCentered()

Returns

MarkupBuilder

The builder for chaining

Visible(bool)

Sets the visibility

public MarkupBuilder Visible(bool visible = true)

Parameters

visible bool

Whether the control is visible

Returns

MarkupBuilder

The builder for chaining

WithAlignment(HorizontalAlignment)

Sets the alignment

public MarkupBuilder WithAlignment(HorizontalAlignment alignment)

Parameters

alignment HorizontalAlignment

The alignment

Returns

MarkupBuilder

The builder for chaining

WithBackgroundColor(Color)

Sets the background color for the control

public MarkupBuilder WithBackgroundColor(Color color)

Parameters

color Color

The background color

Returns

MarkupBuilder

The builder for chaining

WithBorder(BorderStyle)

Sets the border style drawn around the control.

public MarkupBuilder WithBorder(BorderStyle style)

Parameters

style BorderStyle

The border style.

Returns

MarkupBuilder

The builder for chaining.

WithBorderColor(Color)

Sets the border color.

public MarkupBuilder WithBorderColor(Color color)

Parameters

color Color

The border color.

Returns

MarkupBuilder

The builder for chaining.

WithColorRole(ColorRole, ThemeMode?)

Sets the control's semantic colour role (drives the default text colour; inline [color] tags still override it).

public MarkupBuilder WithColorRole(ColorRole role, ThemeMode? mode = null)

Parameters

role ColorRole

The semantic role determining the default text colour.

mode ThemeMode?

Optional ThemeMode override for dark/light role-colour derivation. When null, the active theme's mode is used.

Returns

MarkupBuilder

The builder for chaining.

WithColors(Color, Color)

Sets both foreground and background colors for the control

public MarkupBuilder WithColors(Color foreground, Color background)

Parameters

foreground Color

The foreground (text) color

background Color

The background color

Returns

MarkupBuilder

The builder for chaining

WithCopyEnabled(bool)

Enables or disables the keyboard copy shortcut. Programmatic copy is unaffected.

public MarkupBuilder WithCopyEnabled(bool enabled = true)

Parameters

enabled bool

Whether the copy shortcut is enabled. Defaults to true.

Returns

MarkupBuilder

The builder for chaining

WithCopyKey(ConsoleKey, ConsoleModifiers)

Sets the keyboard copy shortcut for selected text. Implies WithSelectionEnabled(bool).

public MarkupBuilder WithCopyKey(ConsoleKey key, ConsoleModifiers modifiers = ConsoleModifiers.Control)

Parameters

key ConsoleKey

The key that triggers a copy (default C).

modifiers ConsoleModifiers

The required modifier keys (default Control).

Returns

MarkupBuilder

The builder for chaining

WithFocusedLinkColors(Color, Color)

Sets the colors used to highlight the keyboard-focused link.

public MarkupBuilder WithFocusedLinkColors(Color foreground, Color background)

Parameters

foreground Color

The focused-link foreground color

background Color

The focused-link background color

Returns

MarkupBuilder

The builder for chaining

WithForegroundColor(Color)

Sets the foreground (text) color for the control

public MarkupBuilder WithForegroundColor(Color color)

Parameters

color Color

The foreground color

Returns

MarkupBuilder

The builder for chaining

WithHeader(string)

Sets the header text embedded in the top border.

public MarkupBuilder WithHeader(string header)

Parameters

header string

The header text.

Returns

MarkupBuilder

The builder for chaining.

WithHeaderAlignment(TextJustification)

Sets the header text alignment within the top border.

public MarkupBuilder WithHeaderAlignment(TextJustification alignment)

Parameters

alignment TextJustification

The header alignment.

Returns

MarkupBuilder

The builder for chaining.

WithMargin(int)

Sets uniform margin

public MarkupBuilder WithMargin(int margin)

Parameters

margin int

The margin value for all sides

Returns

MarkupBuilder

The builder for chaining

WithMargin(int, int, int, int)

Sets the margin

public MarkupBuilder WithMargin(int left, int top, int right, int bottom)

Parameters

left int

Left margin

top int

Top margin

right int

Right margin

bottom int

Bottom margin

Returns

MarkupBuilder

The builder for chaining

WithMarkdown(string)

Alias for AddMarkdown(string), for fluent readability.

public MarkupBuilder WithMarkdown(string markdown)

Parameters

markdown string

The Markdown content.

Returns

MarkupBuilder

This builder for chaining.

WithMarkdownStyle(Func<MarkdownStyle, MarkdownStyle>)

Sets a per-control Markdown style override applied on build.

public MarkupBuilder WithMarkdownStyle(Func<MarkdownStyle, MarkdownStyle> configure)

Parameters

configure Func<MarkdownStyle, MarkdownStyle>

Receives the current default style; return a modified copy.

Returns

MarkupBuilder

This builder for chaining.

WithName(string)

Sets the control name for lookup

public MarkupBuilder WithName(string name)

Parameters

name string

The control name

Returns

MarkupBuilder

The builder for chaining

WithPadding(int, int, int, int)

Sets the inner padding between the border and the content.

public MarkupBuilder WithPadding(int left, int top, int right, int bottom)

Parameters

left int

Left padding.

top int

Top padding.

right int

Right padding.

bottom int

Bottom padding.

Returns

MarkupBuilder

The builder for chaining.

WithSelectionColors(Color, Color)

Sets the colors used to highlight selected text. Implies WithSelectionEnabled(bool).

public MarkupBuilder WithSelectionColors(Color foreground, Color background)

Parameters

foreground Color

The selected-text foreground color

background Color

The selected-text background color

Returns

MarkupBuilder

The builder for chaining

WithSelectionEnabled(bool)

Enables (or disables) mouse text selection and window-level Ctrl+C copy for the control. Selection is opt-in; when disabled (the default) the control is display-only.

public MarkupBuilder WithSelectionEnabled(bool enabled = true)

Parameters

enabled bool

Whether selection should be enabled. Defaults to true.

Returns

MarkupBuilder

The builder for chaining

WithStickyPosition(StickyPosition)

Sets the sticky position

public MarkupBuilder WithStickyPosition(StickyPosition position)

Parameters

position StickyPosition

The sticky position

Returns

MarkupBuilder

The builder for chaining

WithTag(object)

Sets a tag object

public MarkupBuilder WithTag(object tag)

Parameters

tag object

The tag object

Returns

MarkupBuilder

The builder for chaining

WithVerticalAlignment(VerticalAlignment)

Sets the vertical alignment

public MarkupBuilder WithVerticalAlignment(VerticalAlignment alignment)

Parameters

alignment VerticalAlignment

The vertical alignment

Returns

MarkupBuilder

The builder for chaining

WithWidth(int)

Sets the width

public MarkupBuilder WithWidth(int width)

Parameters

width int

The control width

Returns

MarkupBuilder

The builder for chaining

Operators

implicit operator MarkupControl(MarkupBuilder)

Implicit conversion to MarkupControl

public static implicit operator MarkupControl(MarkupBuilder builder)

Parameters

builder MarkupBuilder

The builder

Returns

MarkupControl

The built markup control