Skip to main content

ConsoleInput

A class in Root.Township, WindowsConsole.

Line editor for the Windows server console: keeps a typed line at the bottom while log lines print above it, with cursor keys, word jumps and history. Runs on the console thread.

Constructors​

MemberWhat it is
ConsoleInput()Creates a ConsoleInput with default values.

Fields​

5 private and internal fields
MemberWhat it is
private int currentCursorPositionBacking field for CurrentCursorPosition.
private int currentHistoryIndexPosition in the history list for the up and down arrows.
private int currentLineConsole row the input line is on.
private List<string> inputHistoryLines entered so far.
private string inputStringBacking field for InputString.

Properties​

MemberWhat it is
int CurrentCursorPosition { get; }Cursor position within the typed text.
string InputString { get; }The text typed so far.

Events​

MemberWhat it is
event Action<string> OnInputTextRaised with each line the user enters.

Methods​

MemberWhat it is
void ClearCurrentLine()Empties the typed text and blanks the input line.
void RedrawInputLine()Redraws the typed text in green and puts the cursor back.
void Update()Reads one key if available, handles editing keys or inserts the character, then redraws.
void WriteLine(string message)Prints a message above the input line and redraws the typed text under it.
14 private and internal methods
MemberWhat it is
private void AddTextToHistory(string enteredText)Adds a non-empty entered line to history unless it repeats the last one.
private void ClearInputLine()Blanks the console's input line on screen without touching the text.
private int GetNextWordStart(int indexToCheckFrom)Index where the next word starts after the given index, or the end of the text.
private int GetWordStart(int indexToCheckFrom)Index where the word at or before the given index starts.
private void OnBackspace(ConsoleKeyInfo key)Deletes the character before the cursor, or the whole word with Ctrl.
private void OnDelete(ConsoleKeyInfo key)Deletes the character after the cursor, the next word with Ctrl, or the whole line with Shift.
private void OnDownArrow()Steps forward in history.
private void OnEnd()Moves the cursor to the end of the text.
private void OnEnter()Echoes the line with a > prefix, raises OnInputText with it and adds it to history.
private void OnEscape()Clears the typed text.
private void OnHome()Moves the cursor to the start of the text.
private void OnLeftArrow(ConsoleKeyInfo key)Moves the cursor left one character, or to the word start with Ctrl.
private void OnRightArrow(ConsoleKeyInfo key)Moves the cursor right one character, or to the next word with Ctrl.
private void OnUpArrow()Steps back in history.

Used in​

Members of other types that take, return or hold a ConsoleInput: