Table of Contents

Class PromptControl

Namespace
SharpConsoleUI.Controls
Assembly
SharpConsoleUI.dll

A single-line text input control with optional prompt text. Supports text editing, cursor navigation, and horizontal scrolling for overflow text.

public class PromptControl : IInteractiveControl, IFocusableControl, IWindowControl, IDisposable, ILogicalCursorProvider, ICursorShapeProvider, IDOMPaintable
Inheritance
PromptControl
Implements
Inherited Members
Extension Methods

Properties

ActualWidth

Gets the actual rendered width of the control content in characters.

public int? ActualWidth { get; }

Property Value

int?

CanReceiveFocus

Whether this control can receive focus

public bool CanReceiveFocus { get; }

Property Value

bool

Container

Gets or sets the parent container that hosts this control.

public IContainer? Container { get; set; }

Property Value

IContainer

HasFocus

Gets or sets whether this control currently has keyboard focus.

public bool HasFocus { get; set; }

Property Value

bool

HorizontalAlignment

Gets or sets the horizontal alignment of the control within its container.

public HorizontalAlignment HorizontalAlignment { get; set; }

Property Value

HorizontalAlignment

Input

Gets or sets the current input text entered by the user.

public string Input { get; set; }

Property Value

string

InputBackgroundColor

Gets or sets the background color of the input area when not focused.

public Color? InputBackgroundColor { get; set; }

Property Value

Color?

InputFocusedBackgroundColor

Gets or sets the background color of the input area when focused.

public Color? InputFocusedBackgroundColor { get; set; }

Property Value

Color?

InputFocusedForegroundColor

Gets or sets the foreground color of the input text when focused.

public Color? InputFocusedForegroundColor { get; set; }

Property Value

Color?

InputForegroundColor

Gets or sets the foreground color of the input text when not focused.

public Color? InputForegroundColor { get; set; }

Property Value

Color?

InputWidth

Gets or sets the width of the input area in characters. When set, enables horizontal scrolling.

public int? InputWidth { get; set; }

Property Value

int?

IsEnabled

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

public bool IsEnabled { get; set; }

Property Value

bool

Margin

Gets or sets the margin (spacing) around the control.

public Margin Margin { get; set; }

Property Value

Margin

MaskCharacter

Gets or sets a character to display instead of the actual input (for password fields). When null, the actual input is displayed.

public char? MaskCharacter { get; set; }

Property Value

char?

Name

Gets or sets the unique name identifier for this control, used for lookup.

public string? Name { get; set; }

Property Value

string

PreferredCursorShape

Gets the preferred cursor shape - always VerticalBar for text input

public CursorShape? PreferredCursorShape { get; }

Property Value

CursorShape?

Prompt

Gets or sets the prompt text displayed before the input area.

public string? Prompt { get; set; }

Property Value

string

StickyPosition

Gets or sets whether this control should stick to the top or bottom during scrolling.

public StickyPosition StickyPosition { get; set; }

Property Value

StickyPosition

Tag

Gets or sets an arbitrary object value that can be used to store custom data.

public object? Tag { get; set; }

Property Value

object

UnfocusOnEnter

Gets or sets whether the control loses focus when Enter is pressed.

public bool UnfocusOnEnter { get; set; }

Property Value

bool

VerticalAlignment

Gets or sets the vertical alignment of the control within its container.

public VerticalAlignment VerticalAlignment { get; set; }

Property Value

VerticalAlignment

Visible

Gets or sets whether this control is visible.

public bool Visible { get; set; }

Property Value

bool

Width

Gets or sets the explicit width of the control, or null for automatic sizing.

public int? Width { get; set; }

Property Value

int?

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

GetLogicalContentSize()

Gets the logical size of the control's content without rendering.

public Size GetLogicalContentSize()

Returns

Size

The size representing the content's natural dimensions.

GetLogicalCursorPosition()

Gets the logical cursor position within the control's content coordinate system. This should be the raw position without any visual adjustments for margins, scrolling, etc.

public Point? GetLogicalCursorPosition()

Returns

Point?

Logical cursor position or null if no cursor.

Invalidate()

Marks this control as needing to be re-rendered.

public void Invalidate()

MeasureDOM(LayoutConstraints)

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

public LayoutSize MeasureDOM(LayoutConstraints constraints)

Parameters

constraints LayoutConstraints

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

Returns

LayoutSize

The desired size of the control.

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

Paints the control's content directly to a CharacterBuffer.

public void PaintDOM(CharacterBuffer buffer, LayoutRect bounds, LayoutRect clipRect, Color defaultFg, Color defaultBg)

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).

defaultFg Color
defaultBg Color

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.

SetFocus(bool, FocusReason)

Sets focus to this control

public void SetFocus(bool focus, FocusReason reason = FocusReason.Programmatic)

Parameters

focus bool

Whether to give or remove focus

reason FocusReason

The reason for the focus change

SetInput(string?)

Sets the input text and positions the cursor at the end.

public void SetInput(string? input)

Parameters

input string

The text to set as input.

SetLogicalCursorPosition(Point)

Sets the logical cursor position within the control's content coordinate system.

public void SetLogicalCursorPosition(Point position)

Parameters

position Point

Events

Entered

Event fired when Enter is pressed (modern standardized event)

public event EventHandler<string>? Entered

Event Type

EventHandler<string>

GotFocus

Occurs when the control receives focus.

public event EventHandler? GotFocus

Event Type

EventHandler

InputChanged

Event fired when input text changes (modern standardized event)

public event EventHandler<string>? InputChanged

Event Type

EventHandler<string>

LostFocus

Occurs when the control loses focus.

public event EventHandler? LostFocus

Event Type

EventHandler