Skip to content

ClassicConsoleKeyboardHandler Class

A classic console/terminal prompt keyboard handler.

C#
public class ClassicConsoleKeyboardHandler : KeyboardConsoleComponent, IComponent

Inheritance objectKeyboardConsoleComponent

Implements IComponent

Creates the handler with the specified prompt.

C#
public ClassicConsoleKeyboardHandler(string prompt = "> ")

prompt string
The prompt to display to the user.

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.

C#
public Action<ClassicConsoleKeyboardHandler, Cursor, string> EnterPressedAction

A flag that when set to true prints a new line and the prompt.

C#
public bool IsReady { get; set; }

The prompt to display to the user.

C#
public string Prompt { get; set; }

The glyph to print when erasing a character, such as when the backspace key is pressed to erase a character.

C#
public char EraseGlyph { get; set; }

The glyph used to replace the empty characters that may be in the string sent to EnterPressedAction.

C#
public char ReplaceEmptyGlyph { get; set; }

This holds the row that the virtual cursor is starting from when someone is typing.

C#
public int CursorLastY { get; set; }

Called when this component is added to an object with a cursor; caches reference to the cursor.

C#
public override void OnAdded(IScreenObject host)

host IScreenObject
The host object for the component.

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.

Prints the prompt and locks the cursor to the column that ends at the prompt.

C#
public void PrintPrompt()

ProcessKeyboard(IScreenObject, Keyboard, out bool)

Section titled “ProcessKeyboard(IScreenObject, Keyboard, out bool)”

Called by a host when the keyboard is being processed.

C#
public override void ProcessKeyboard(IScreenObject consoleObject, Keyboard info, out bool handled)

consoleObject IScreenObject

info Keyboard

handled bool
When set to true informs the host caller that we handled the mouse and to stop others from handling.