Table of Contents

Class Link

Namespace
Terminal.Gui.Views
Assembly
Terminal.Gui.dll

Displays a clickable hyperlink with optional display text and a target URL.

public class Link : View, IDisposable, ISupportInitializeNotification, ISupportInitialize, IDesignable
Inheritance
Link
Implements
Inherited Members
Extension Methods

Link has three independent text-related properties:

  • Text — The display text shown to the user. When empty, Url is displayed instead.
  • Title — Controls the HotKey. Set this to include an underscore prefix (e.g., "_Link") to define a keyboard shortcut.
  • Url — The hyperlink target. When the link is accepted (clicked or Accept is invoked), this URL is opened in the default browser via OpenUrl(string).

The link renders using OSC 8 hyperlink escape sequences when the terminal supports them, enabling clickable URLs in modern terminal emulators. If Url is not a well-formed absolute URI, the link renders with the Disabled style and OSC 8 sequences are suppressed.

Url changes follow the Cancellable Workflow Pattern (CWP): the UrlChanging event fires before the change (and can cancel it by setting Handled to true), and the UrlChanged event fires after.

When CanFocus is false and the link has a valid HotKey, pressing the HotKey passes focus to the next peer View in the SuperView's SubView list. This enables Link to act as a label-like hotkey proxy (similar to Label).

Both Width and Height default to Text, so the link auto-sizes to fit whichever text is displayed (Text or Url).

Default mouse bindings:

Mouse EventAction
ClickAccepts the link, opening the URL (Accept).

Constructors

Link()

Initializes a new instance of View.

Fields

DEFAULT_URL

The default value for Url — an empty string indicating no URL is associated with the link.

Properties

Url

Gets or sets the URL (hyperlink target) associated with this Link.

Methods

Copy()

Copies the current Url to the system clipboard.

OnAccepted(ICommandContext?)

Called when the link is accepted (e.g., clicked or Accept is invoked). Opens Url in the default browser via OpenUrl(string).

OnActivating(CommandEventArgs)

Handles activation. If CanFocus is false, delegates to the HotKey command (which passes focus to the next peer view). Otherwise, uses the default activation behavior.

OnDrawingText(DrawContext?)

Draws the link text with OSC 8 hyperlink sequences when the URL is valid.

OnUrlChanged(ValueChangedEventArgs<string>)

Called after Url has changed. Override in subclasses to react to URL changes.

OnUrlChanging(ValueChangingEventArgs<string>)

Called before Url changes. Override in subclasses to implement validation or cancel the change.

OpenUrl(string)

Opens the specified URL in the default web browser using a platform-specific mechanism.

UpdateTextFormatterText()

Updates the text displayed by the TextFormatter based on the current values of Text and Url.

Events

UrlChanged

Raised after Url has changed. The OldValue and NewValue properties contain the previous and current values.

UrlChanging

Raised when Url is about to change. Set Handled to true to cancel the change and keep the current value.