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
BlockSpacing
Gets or sets the spacing between block elements.
public int BlockSpacing { get; set; }
Property Value
CanFocusWithMouse
Whether this control can receive focus via mouse clicks
public bool CanFocusWithMouse { get; }
Property Value
CanReceiveFocus
Whether this control can receive focus
public bool CanReceiveFocus { get; }
Property Value
ContentHeight
Gets the total content height in lines.
public int ContentHeight { get; }
Property Value
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
ForegroundColor
Gets or sets the foreground color of the control.
public Color ForegroundColor { get; set; }
Property Value
HasFocus
Gets whether this control has focus.
public bool HasFocus { get; }
Property Value
IsEnabled
Gets or sets whether this control is enabled and can receive input.
public bool IsEnabled { get; set; }
Property Value
IsLoading
Gets whether content is currently being loaded.
public bool IsLoading { get; }
Property Value
LinkColor
Gets or sets the color used for unvisited links.
public Color LinkColor { get; set; }
Property Value
LoadingStatus
Gets a human-readable loading status (e.g., "Loading images: 3/12"). Null when not loading.
public string? LoadingStatus { get; }
Property Value
LoadingText
Gets or sets the text displayed while content is loading.
public string LoadingText { get; set; }
Property Value
MouseWheelScrollSpeed
Gets or sets the number of lines to scroll per mouse wheel tick.
public int MouseWheelScrollSpeed { get; set; }
Property Value
RawHtml
Gets the raw HTML content.
public string? RawHtml { get; }
Property Value
ScrollOffset
Gets or sets the scroll offset (number of lines scrolled from the top).
public int ScrollOffset { get; set; }
Property Value
ScrollbarVisibility
Gets or sets the scrollbar visibility mode.
public ScrollbarVisibility ScrollbarVisibility { get; set; }
Property Value
ShowBulletPoints
Gets or sets whether bullet points are rendered for lists.
public bool ShowBulletPoints { get; set; }
Property Value
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
TabSize
Gets or sets the tab size in spaces.
public int TabSize { get; set; }
Property Value
VisitedLinkColor
Gets or sets the color used for visited links.
public Color VisitedLinkColor { get; set; }
Property Value
WantsMouseEvents
Whether this control wants to receive mouse events
public bool WantsMouseEvents { get; }
Property Value
WantsTabKey
Whether this control wants to consume Tab key events (for link navigation).
public bool WantsTabKey { get; }
Property Value
Methods
Create()
Creates a new HtmlControl instance (for builder pattern start).
public static HtmlControl Create()
Returns
LoadUrlAsync(string)
Loads HTML content from a URL asynchronously.
public Task LoadUrlAsync(string url)
Parameters
urlstringThe URL to load content from.
Returns
LoadUrlAsync(string, CancellationToken)
Loads HTML content from a URL asynchronously with cancellation support.
public Task LoadUrlAsync(string url, CancellationToken ct)
Parameters
urlstringThe URL to load content from.
ctCancellationTokenExternal cancellation token.
Returns
MeasureDOM(LayoutConstraints)
Measures the control's desired size given the available constraints.
public override LayoutSize MeasureDOM(LayoutConstraints constraints)
Parameters
constraintsLayoutConstraintsThe 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
bufferCharacterBufferThe buffer to paint to.
boundsLayoutRectThe absolute bounds where the control should paint.
clipRectLayoutRectThe clipping rectangle (visible area).
defaultForegroundColorThe default foreground color from the container.
defaultBackgroundColorThe default background color from the container.
ProcessKey(ConsoleKeyInfo)
Processes a keyboard input event.
public bool ProcessKey(ConsoleKeyInfo key)
Parameters
keyConsoleKeyInfoThe 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
argsMouseEventArgsMouse 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
htmlstringThe 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
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
LinkClicked
Raised when a link is clicked.
public event EventHandler<LinkClickedEventArgs>? LinkClicked
Event Type
LinkHover
Raised when a link is hovered or unhovered.
public event EventHandler<LinkHoverEventArgs>? LinkHover
Event Type
LoadError
Raised when an error occurs during content loading.
public event EventHandler<LoadErrorEventArgs>? LoadError
Event Type
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
MouseClick
Event fired when the control is clicked
public event EventHandler<MouseEventArgs>? MouseClick
Event Type
MouseDoubleClick
Event fired when the control is double-clicked
public event EventHandler<MouseEventArgs>? MouseDoubleClick
Event Type
MouseEnter
Event fired when the mouse enters the control area
public event EventHandler<MouseEventArgs>? MouseEnter
Event Type
MouseLeave
Event fired when the mouse leaves the control area
public event EventHandler<MouseEventArgs>? MouseLeave
Event Type
MouseMove
Event fired when the mouse moves over the control
public event EventHandler<MouseEventArgs>? MouseMove
Event Type
MouseRightClick
Event fired when the control is right-clicked (Button3)
public event EventHandler<MouseEventArgs>? MouseRightClick