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 : BaseControl, IDOMPaintable, INotifyPropertyChanged, IInteractiveControl, IFocusableControl, IMouseAwareControl, IWindowControl, IDisposable, ILogicalCursorProvider, ICursorShapeProvider
- Inheritance
-
PromptControl
- Implements
- Inherited Members
- Extension Methods
Properties
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
ContentWidth
Gets the actual rendered width of the control content in characters.
public override int? ContentWidth { get; }
Property Value
- int?
HasFocus
public bool HasFocus { get; }
Property Value
HasSelection
Gets whether there is an active text selection.
public bool HasSelection { get; }
Property Value
HistoryEnabled
Gets or sets whether command history is enabled (Up/Down arrow recall).
public bool HistoryEnabled { get; set; }
Property Value
Input
Gets or sets the current input text entered by the user.
public string Input { get; set; }
Property Value
InputBackgroundColor
Gets or sets the background color of the input area when not focused.
public Color? InputBackgroundColor { get; set; }
Property Value
InputFocusedBackgroundColor
Gets or sets the background color of the input area when focused.
public Color? InputFocusedBackgroundColor { get; set; }
Property Value
InputFocusedForegroundColor
Gets or sets the foreground color of the input text when focused.
public Color? InputFocusedForegroundColor { get; set; }
Property Value
InputForegroundColor
Gets or sets the foreground color of the input text when not focused.
public Color? InputForegroundColor { get; set; }
Property Value
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
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?
PreferredCursorShape
Gets the preferred cursor shape - always VerticalBar for text input
public CursorShape? PreferredCursorShape { get; }
Property Value
Prompt
Gets or sets the prompt text displayed before the input area.
public string? Prompt { get; set; }
Property Value
SelectedText
Gets the selected text, or null if no selection.
public string? SelectedText { get; }
Property Value
TabCompleter
Gets or sets the tab completion delegate. When set, Tab key triggers completion. The delegate receives (input, cursorPosition) and returns completion candidates. When no completions match, Tab passes through to focus traversal.
public Func<string, int, IEnumerable<string>?>? TabCompleter { get; set; }
Property Value
- Func<string, int, IEnumerable<string>>
UnfocusOnEnter
Gets or sets whether the control loses focus when Enter is pressed.
public bool UnfocusOnEnter { get; set; }
Property Value
WantsMouseEvents
Whether this control wants to receive mouse events
public bool WantsMouseEvents { get; }
Property Value
WantsTabKey
Whether this control wants Tab key events (for tab completion).
public bool WantsTabKey { get; }
Property Value
Methods
ClearHistory()
Clears the command history.
public void ClearHistory()
GetLogicalContentSize()
Gets the logical size of the control's content without rendering.
public override 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.
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 defaultFg, Color defaultBg)
Parameters
bufferCharacterBufferThe buffer to paint to.
boundsLayoutRectThe absolute bounds where the control should paint.
clipRectLayoutRectThe clipping rectangle (visible area).
defaultFgColordefaultBgColor
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
SetInput(string?)
Sets the input text and positions the cursor at the end.
public void SetInput(string? input)
Parameters
inputstringThe 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
positionPoint
Events
Entered
Event fired when Enter is pressed (modern standardized event)
public event EventHandler<string>? Entered
Event Type
InputChanged
Event fired when input text changes (modern standardized event)
public event EventHandler<string>? InputChanged
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