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
markupstringThe markup text
Returns
- MarkupBuilder
The builder for chaining
AddLines(params string[])
Adds multiple lines of markup text
public MarkupBuilder AddLines(params string[] markupLines)
Parameters
markupLinesstring[]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
markdownstringThe 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
markupstringThe 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
markupstringThe 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
handlerEventHandler<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
outlineboolWhether 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
useSafeboolWhether 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
visibleboolWhether the control is visible
Returns
- MarkupBuilder
The builder for chaining
WithAlignment(HorizontalAlignment)
Sets the alignment
public MarkupBuilder WithAlignment(HorizontalAlignment alignment)
Parameters
alignmentHorizontalAlignmentThe alignment
Returns
- MarkupBuilder
The builder for chaining
WithBackgroundColor(Color)
Sets the background color for the control
public MarkupBuilder WithBackgroundColor(Color color)
Parameters
colorColorThe background color
Returns
- MarkupBuilder
The builder for chaining
WithBorder(BorderStyle)
Sets the border style drawn around the control.
public MarkupBuilder WithBorder(BorderStyle style)
Parameters
styleBorderStyleThe border style.
Returns
- MarkupBuilder
The builder for chaining.
WithBorderColor(Color)
Sets the border color.
public MarkupBuilder WithBorderColor(Color color)
Parameters
colorColorThe 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
roleColorRoleThe semantic role determining the default text colour.
modeThemeMode?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
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
enabledboolWhether 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
keyConsoleKeyThe key that triggers a copy (default C).
modifiersConsoleModifiersThe 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
foregroundColorThe focused-link foreground color
backgroundColorThe 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
colorColorThe 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
headerstringThe 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
alignmentTextJustificationThe header alignment.
Returns
- MarkupBuilder
The builder for chaining.
WithMargin(int)
Sets uniform margin
public MarkupBuilder WithMargin(int margin)
Parameters
marginintThe 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
Returns
- MarkupBuilder
The builder for chaining
WithMarkdown(string)
Alias for AddMarkdown(string), for fluent readability.
public MarkupBuilder WithMarkdown(string markdown)
Parameters
markdownstringThe 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
configureFunc<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
namestringThe 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
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
foregroundColorThe selected-text foreground color
backgroundColorThe 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
enabledboolWhether 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
positionStickyPositionThe sticky position
Returns
- MarkupBuilder
The builder for chaining
WithTag(object)
Sets a tag object
public MarkupBuilder WithTag(object tag)
Parameters
tagobjectThe tag object
Returns
- MarkupBuilder
The builder for chaining
WithVerticalAlignment(VerticalAlignment)
Sets the vertical alignment
public MarkupBuilder WithVerticalAlignment(VerticalAlignment alignment)
Parameters
alignmentVerticalAlignmentThe vertical alignment
Returns
- MarkupBuilder
The builder for chaining
WithWidth(int)
Sets the width
public MarkupBuilder WithWidth(int width)
Parameters
widthintThe 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
builderMarkupBuilderThe builder
Returns
- MarkupControl
The built markup control