Table of Contents

Class HtmlControl

Namespace
SharpConsoleUI.Controls
Assembly
SharpConsoleUI.dll

A control that renders HTML content in the terminal with scrolling, link interaction, and keyboard navigation.

public class HtmlControl : BaseControl, IDOMPaintable, INotifyPropertyChanged, IInteractiveControl, IFocusableControl, IMouseAwareControl, IWindowControl, IDisposable
Inheritance
HtmlControl
Implements
Inherited Members
Extension Methods

Properties

BackgroundColor

Gets or sets the background color of the control.

public Color BackgroundColor { get; set; }

Property Value

Color

BlockSpacing

Gets or sets the spacing between block elements.

public int BlockSpacing { get; set; }

Property Value

int

CanFocusWithMouse

Whether this control can receive focus via mouse clicks

public bool CanFocusWithMouse { get; }

Property Value

bool

CanReceiveFocus

Whether this control can receive focus

public bool CanReceiveFocus { get; }

Property Value

bool

ContentHeight

Gets the total content height in lines.

public int ContentHeight { get; }

Property Value

int

ContentWidth

Gets the minimum width needed to display the control's content, including margins. Returns null if width cannot be determined. This is calculated based on content (text length, child controls, etc.) and represents the natural/intrinsic size.

public override int? ContentWidth { get; }

Property Value

int?

CurrentUrl

Gets the URL of the currently loaded content, if any.

public string? CurrentUrl { get; }

Property Value

string

ForegroundColor

Gets or sets the foreground color of the control.

public Color ForegroundColor { get; set; }

Property Value

Color

HasFocus

Gets whether this control has focus.

public bool HasFocus { get; }

Property Value

bool

IsEnabled

Gets or sets whether this control is enabled and can receive input.

public bool IsEnabled { get; set; }

Property Value

bool

IsLoading

Gets whether content is currently being loaded.

public bool IsLoading { get; }

Property Value

bool

LinkColor

Gets or sets the color used for unvisited links.

public Color LinkColor { get; set; }

Property Value

Color

LoadingStatus

Gets a human-readable loading status (e.g., "Loading images: 3/12"). Null when not loading.

public string? LoadingStatus { get; }

Property Value

string

LoadingText

Gets or sets the text displayed while content is loading.

public string LoadingText { get; set; }

Property Value

string

MouseWheelScrollSpeed

Gets or sets the number of lines to scroll per mouse wheel tick.

public int MouseWheelScrollSpeed { get; set; }

Property Value

int

RawHtml

Gets the raw HTML content.

public string? RawHtml { get; }

Property Value

string

ScrollOffset

Gets or sets the scroll offset (number of lines scrolled from the top).

public int ScrollOffset { get; set; }

Property Value

int

ScrollbarVisibility

Gets or sets the scrollbar visibility mode.

public ScrollbarVisibility ScrollbarVisibility { get; set; }

Property Value

ScrollbarVisibility

ShowBulletPoints

Gets or sets whether bullet points are rendered for lists.

public bool ShowBulletPoints { get; set; }

Property Value

bool

ShowImages

Gets or sets whether images are rendered inline using half-block characters. When false, images display alt text placeholders instead.

public bool ShowImages { get; set; }

Property Value

bool

TabSize

Gets or sets the tab size in spaces.

public int TabSize { get; set; }

Property Value

int

VisitedLinkColor

Gets or sets the color used for visited links.

public Color VisitedLinkColor { get; set; }

Property Value

Color

WantsMouseEvents

Whether this control wants to receive mouse events

public bool WantsMouseEvents { get; }

Property Value

bool

WantsTabKey

Whether this control wants to consume Tab key events (for link navigation).

public bool WantsTabKey { get; }

Property Value

bool

Methods

Create()

Creates a new HtmlControl instance (for builder pattern start).

public static HtmlControl Create()

Returns

HtmlControl

LoadUrlAsync(string)

Loads HTML content from a URL asynchronously.

public Task LoadUrlAsync(string url)

Parameters

url string

The URL to load content from.

Returns

Task

LoadUrlAsync(string, CancellationToken)

Loads HTML content from a URL asynchronously with cancellation support.

public Task LoadUrlAsync(string url, CancellationToken ct)

Parameters

url string

The URL to load content from.

ct CancellationToken

External cancellation token.

Returns

Task

MeasureDOM(LayoutConstraints)

Measures the control's desired size given the available constraints.

public override LayoutSize MeasureDOM(LayoutConstraints constraints)

Parameters

constraints LayoutConstraints

The layout constraints (min/max width/height).

Returns

LayoutSize

The desired size of the control.

OnDisposing()

Called during Dispose() before Container is set to null. Override to perform control-specific cleanup (null events, close portals, clear data, etc.).

protected override void OnDisposing()

PaintDOM(CharacterBuffer, LayoutRect, LayoutRect, Color, Color)

Paints the control's content directly to a CharacterBuffer.

public override void PaintDOM(CharacterBuffer buffer, LayoutRect bounds, LayoutRect clipRect, Color defaultForeground, Color defaultBackground)

Parameters

buffer CharacterBuffer

The buffer to paint to.

bounds LayoutRect

The absolute bounds where the control should paint.

clipRect LayoutRect

The clipping rectangle (visible area).

defaultForeground Color

The default foreground color from the container.

defaultBackground Color

The default background color from the container.

ProcessKey(ConsoleKeyInfo)

Processes a keyboard input event.

public bool ProcessKey(ConsoleKeyInfo key)

Parameters

key ConsoleKeyInfo

The key information for the pressed key.

Returns

bool

True if the key was handled by this control; otherwise, false.

ProcessMouseEvent(MouseEventArgs)

Processes a mouse event for this control

public bool ProcessMouseEvent(MouseEventArgs args)

Parameters

args MouseEventArgs

Mouse event arguments with control-relative coordinates

Returns

bool

True if the event was handled and should not propagate further

SetContent(string)

Sets the HTML content to display.

public void SetContent(string html)

Parameters

html string

The HTML string to render.

SetContent(string, string)

Sets the HTML content to display with a base URL for resolving relative links.

public void SetContent(string html, string baseUrl)

Parameters

html string

The HTML string to render.

baseUrl string

The base URL for resolving relative links.

Events

ContentLoaded

Raised when the text layout of a fetched page has been committed and is usable. For pages with images, this fires BEFORE images are loaded — subscribe to LoadingCompleted if you want to wait for images too.

public event EventHandler? ContentLoaded

Event Type

EventHandler

LinkClicked

Raised when a link is clicked.

public event EventHandler<LinkClickedEventArgs>? LinkClicked

Event Type

EventHandler<LinkClickedEventArgs>

LinkHover

Raised when a link is hovered or unhovered.

public event EventHandler<LinkHoverEventArgs>? LinkHover

Event Type

EventHandler<LinkHoverEventArgs>

LoadError

Raised when an error occurs during content loading.

public event EventHandler<LoadErrorEventArgs>? LoadError

Event Type

EventHandler<LoadErrorEventArgs>

LoadingCompleted

Raised when every phase of loading has finished, including progressive image loading. Fires exactly once per LoadUrlAsync(string) call (on success, cancellation, or error). At the moment this event fires, IsLoading is false and LoadingStatus is null.

public event EventHandler? LoadingCompleted

Event Type

EventHandler

MouseClick

Event fired when the control is clicked

public event EventHandler<MouseEventArgs>? MouseClick

Event Type

EventHandler<MouseEventArgs>

MouseDoubleClick

Event fired when the control is double-clicked

public event EventHandler<MouseEventArgs>? MouseDoubleClick

Event Type

EventHandler<MouseEventArgs>

MouseEnter

Event fired when the mouse enters the control area

public event EventHandler<MouseEventArgs>? MouseEnter

Event Type

EventHandler<MouseEventArgs>

MouseLeave

Event fired when the mouse leaves the control area

public event EventHandler<MouseEventArgs>? MouseLeave

Event Type

EventHandler<MouseEventArgs>

MouseMove

Event fired when the mouse moves over the control

public event EventHandler<MouseEventArgs>? MouseMove

Event Type

EventHandler<MouseEventArgs>

MouseRightClick

Event fired when the control is right-clicked (Button3)

public event EventHandler<MouseEventArgs>? MouseRightClick

Event Type

EventHandler<MouseEventArgs>