Class ClassicConsoleKeyboardHandler
A classic console/terminal prompt keyboard handler.
Implements
Inherited Members
Namespace: SadConsole.Components
Assembly: SadConsole.Extended.dll
Syntax
public class ClassicConsoleKeyboardHandler : KeyboardConsoleComponent, IComponent
Constructors
ClassicConsoleKeyboardHandler(string)
Creates the handler with the specified prompt.
Declaration
public ClassicConsoleKeyboardHandler(string prompt = "> ")
Parameters
Type | Name | Description |
---|---|---|
string | prompt | The prompt to display to the user. |
Fields
EnterPressedAction
This is a callback for the owner of this keyboard handler. The parameters are the component itself, the Cursor used by the handler, and the string input by the user. It's called when the user presses ENTER.
Declaration
public Action<ClassicConsoleKeyboardHandler, Cursor, string> EnterPressedAction
Field Value
Type | Description |
---|---|
Action<ClassicConsoleKeyboardHandler, Cursor, string> |
Properties
CursorLastY
This holds the row that the virtual cursor is starting from when someone is typing.
Declaration
public int CursorLastY { get; set; }
Property Value
Type | Description |
---|---|
int |
EraseGlyph
The glyph to print when erasing a character, such as when the backspace key is pressed to erase a character.
Declaration
public char EraseGlyph { get; set; }
Property Value
Type | Description |
---|---|
char |
IsReady
A flag that when set to true prints a new line and the prompt.
Declaration
public bool IsReady { get; set; }
Property Value
Type | Description |
---|---|
bool |
Prompt
The prompt to display to the user.
Declaration
public string Prompt { get; set; }
Property Value
Type | Description |
---|---|
string |
ReplaceEmptyGlyph
The glyph used to replace the empty characters that may be in the string sent to EnterPressedAction.
Declaration
public char ReplaceEmptyGlyph { get; set; }
Property Value
Type | Description |
---|---|
char |
Methods
OnAdded(IScreenObject)
Called when this component is added to an object with a cursor; caches reference to the cursor.
Declaration
public override void OnAdded(IScreenObject host)
Parameters
Type | Name | Description |
---|---|---|
IScreenObject | host | The host object for the component. |
Overrides
Remarks
Makes the cursor visible, disables word breaks and the string parser, and prints the prompt.
If the host is a Console, it uses the SadConsole.Components.ClassicConsoleKeyboardHandler._attachedCursor property, caching reference to it. You can't change the cursor reference unless you re-add this component. If the host is a IScreenObject, the first instance of a cursor in the SadComponents collection is used. If there is no cursor, an exception is thrown.
PrintPrompt()
Prints the prompt and locks the cursor to the column that ends at the prompt.
Declaration
public void PrintPrompt()
ProcessKeyboard(IScreenObject, Keyboard, out bool)
Called by a host when the keyboard is being processed.
Declaration
public override void ProcessKeyboard(IScreenObject consoleObject, Keyboard info, out bool handled)
Parameters
Type | Name | Description |
---|---|---|
IScreenObject | consoleObject | |
Keyboard | info | |
bool | handled | When set to true informs the host caller that we handled the mouse and to stop others from handling. |