Class CommonKeyBehaviors
- Namespace
- InteractiveReadLine.KeyBehaviors
- Assembly
- InteractiveReadLine.dll
These are common "behaviors" which are invoked by keys being pressed, and can be added to the handler either as the default behavior or to be invoked when a special key or character is pressed. They are given to the handler in the form of Action delegates which receive an IKeyBehaviorTarget, which they can operate on in order to affect some change on the line of text being written.
The behaviors provided in this static class are all simple ones, they can be used directly or they can be composed together or wrapped in other methods which allow access to external state, or any other use case that can be imagined.
public static class CommonKeyBehaviors
- Inheritance
-
CommonKeyBehaviors
- Inherited Members
Methods
AutoCompleteNext(IKeyBehaviorTarget)
Invokes the target's auto-complete next behavior, which substitutes in the next suggestion at the token where the cursor is currently residing
public static void AutoCompleteNext(IKeyBehaviorTarget target)
Parameters
targetIKeyBehaviorTarget
AutoCompletePrevious(IKeyBehaviorTarget)
Invokes the target's auto-complete previous behavior, which substitutes in the previous suggestion at the token where the cursor is currently residing
public static void AutoCompletePrevious(IKeyBehaviorTarget target)
Parameters
targetIKeyBehaviorTarget
Backspace(IKeyBehaviorTarget)
Deletes the character before the cursor
public static void Backspace(IKeyBehaviorTarget target)
Parameters
targetIKeyBehaviorTarget
Cancel(IKeyBehaviorTarget)
Abandons the ReadLine input and discards the entered text. This behavior is conventionally bound to Ctrl+C.
public static void Cancel(IKeyBehaviorTarget target)
Parameters
targetIKeyBehaviorTarget
ClearAll(IKeyBehaviorTarget)
Clears the entire contents of the text buffer
public static void ClearAll(IKeyBehaviorTarget target)
Parameters
targetIKeyBehaviorTarget
CutPreviousWord(IKeyBehaviorTarget)
Using a basic split on whitespace strategy, this removes all of the text between the cursor and the end of the previous word
public static void CutPreviousWord(IKeyBehaviorTarget target)
Parameters
targetIKeyBehaviorTarget
CutToEnd(IKeyBehaviorTarget)
Removes all of the text between the cursor and the end of the line
public static void CutToEnd(IKeyBehaviorTarget target)
Parameters
targetIKeyBehaviorTarget
CutToStart(IKeyBehaviorTarget)
Removes all of the text between the cursor and the start of the line
public static void CutToStart(IKeyBehaviorTarget target)
Parameters
targetIKeyBehaviorTarget
Delete(IKeyBehaviorTarget)
Deletes the character after the cursor
public static void Delete(IKeyBehaviorTarget target)
Parameters
targetIKeyBehaviorTarget
DeleteOrEndOfInput(IKeyBehaviorTarget)
Deletes the character under the cursor, or signals the end of input if the line is empty. This matches shell behavior for Ctrl+D: it deletes forward when a character is available and otherwise ends the session.
public static void DeleteOrEndOfInput(IKeyBehaviorTarget target)
Parameters
targetIKeyBehaviorTarget
EndOfInput(IKeyBehaviorTarget)
Signals that the user has no more input and discards the entered text. This behavior is conventionally behavior conventionally bound to Ctrl+D on an empty line.
public static void EndOfInput(IKeyBehaviorTarget target)
Parameters
targetIKeyBehaviorTarget
Finish(IKeyBehaviorTarget)
Finishes the ReadLine input, instructing the handler to return the text as it is
public static void Finish(IKeyBehaviorTarget target)
Parameters
targetIKeyBehaviorTarget
HistoryNext(IKeyBehaviorTarget)
Invokes the target's next history behavior, which replaces the line with the next element in the history collection. Will do nothing if no history has been provided, or replace the line with the last entered line state if the end of the history has been reached.
public static void HistoryNext(IKeyBehaviorTarget target)
Parameters
targetIKeyBehaviorTarget
HistoryPrevious(IKeyBehaviorTarget)
Invokes the target's previous history behavior, which replaces the entire line with the previous element in the history collection. Will do nothing if no history has been provided, or if the oldest element in the collection has been reached.
public static void HistoryPrevious(IKeyBehaviorTarget target)
Parameters
targetIKeyBehaviorTarget
InsertCharacter(IKeyBehaviorTarget)
Inserts the received character at the cursor position if the character is a letter, digit, whitespace, punctuation, or symbol. Advances the cursor by one.
public static void InsertCharacter(IKeyBehaviorTarget target)
Parameters
targetIKeyBehaviorTarget
MoveCursorLeft(IKeyBehaviorTarget)
Moves the cursor left (towards the start) of the line, but will not move it past the first character
public static void MoveCursorLeft(IKeyBehaviorTarget target)
Parameters
targetIKeyBehaviorTarget
MoveCursorRight(IKeyBehaviorTarget)
Moves the cursor right (towards the end) of the line, but will not move it beyond the end of the line
public static void MoveCursorRight(IKeyBehaviorTarget target)
Parameters
targetIKeyBehaviorTarget
MoveCursorToEnd(IKeyBehaviorTarget)
Immediately moves the cursor to the end of the line
public static void MoveCursorToEnd(IKeyBehaviorTarget target)
Parameters
targetIKeyBehaviorTarget
MoveCursorToStart(IKeyBehaviorTarget)
Immediately moves the cursor to the beginning of the line
public static void MoveCursorToStart(IKeyBehaviorTarget target)
Parameters
targetIKeyBehaviorTarget
Paste(IKeyBehaviorTarget)
Inserts the text in the cut buffer at the cursor position and leaves the cursor at the end of the inserted text. Does nothing when nothing has been cut.
public static void Paste(IKeyBehaviorTarget target)
Parameters
targetIKeyBehaviorTarget
Remarks
The buffer is not emptied by pasting, so the same text can be pasted repeatedly.
WriteMessageFromTokens(Func<TokenizedLine?, string>)
Uses a function to create a key behavior that uses the provider's "InsertText" method to insert a message to the user. The handler will provide your function with the tokenized version of the current text, which will be null if the configuration doesn't have a tokenizer.
public static Action<IKeyBehaviorTarget> WriteMessageFromTokens(Func<TokenizedLine?, string> message)
Parameters
messageFunc<TokenizedLine, string>A function which receives a Tokens object and uses it to create a string message, this is typically useful for providing help or hints to the user
Returns
- Action<IKeyBehaviorTarget>
A key behavior action which can be registered with the read line configuration