Class ReadLineConfig
- Namespace
- InteractiveReadLine
- Assembly
- InteractiveReadLine.dll
The main configuration object for the ReadLineHandler, instances of this class carry all of the objects which customize and control every aspect of the ReadLineHandler's behavior. Many standard behaviors are provided through the CommonFormatters/CommonKeyBehaviors/CommonLexers tools, but custom behaviors can be attached to this object instead.
public class ReadLineConfig
- Inheritance
-
ReadLineConfig
- Inherited Members
- Extension Methods
Properties
AutoCompletion
Gets the auto-completion provider, or null when none is configured. The provider receives a TokenizedLine and returns suggestions for the token under the cursor. It can also modify the TokenizedLine.
public Func<TokenizedLine, string[]>? AutoCompletion { get; }
Property Value
- Func<TokenizedLine, string[]>
Basic
Gets a configuration that has the standard key behaviors added to it
public static ReadLineConfig Basic { get; }
Property Value
CanAutoComplete
Gets whether the configuration is capable of auto-completion, which requires both a Lexer and an auto-completion handler.
public bool CanAutoComplete { get; }
Property Value
DefaultKeyBehavior
Gets the default key behavior applied when KeyBehaviors contains no behavior for the pressed key. The value is null when no default behavior is configured.
public Action<IKeyBehaviorTarget>? DefaultKeyBehavior { get; }
Property Value
Empty
Gets an empty configuration with absolutely nothing set
public static ReadLineConfig Empty { get; }
Property Value
FormatterFromLine
Gets the formatter that processes the raw LineState, or null when no line-based formatter is configured.
public Func<LineState, LineDisplayState>? FormatterFromLine { get; }
Property Value
FormatterFromTokens
Gets the formatter that processes a tokenized line before display, or null when no token-based formatter is configured. The formatter requires a Lexer.
public Func<TokenizedLine, LineDisplayState>? FormatterFromTokens { get; }
Property Value
History
Gets the history of entered text, or null when no history source is configured.
public IReadOnlyList<string>? History { get; }
Property Value
KeyBehaviors
Gets a dictionary which maps key press information to key behavior methods
public Dictionary<KeyId, Action<IKeyBehaviorTarget>> KeyBehaviors { get; }
Property Value
Lexer
Gets the lexer that tokenizes a LineState, or null when no lexer is configured. A lexer is required for auto-completion and certain token-based key behaviors.
public Func<LineState, TokenizedLine>? Lexer { get; }
Property Value
UpdateHistory
Gets an Action that is invoked with the finalized line when a ReadLine operation completes. The action is responsible for recording the line in the history. SetUpdatingHistorySource configures this action automatically, or callers can configure it directly with SetHistoryUpdateAction. It is null when history updates are disabled, in which case no line is recorded.
public Action<string>? UpdateHistory { get; }
Property Value
Methods
SetAutoCompletion(Func<TokenizedLine, string[]>)
Sets the auto-completion handler for the configuration
public ReadLineConfig SetAutoCompletion(Func<TokenizedLine, string[]> handler)
Parameters
handlerFunc<TokenizedLine, string[]>
Returns
SetDefaultKeyBehavior(Action<IKeyBehaviorTarget>)
Set the default KeyBehavior which is called when no other special action for a key has been registered in the configuration. Typically this will be used to insert the key character into the input line.
public ReadLineConfig SetDefaultKeyBehavior(Action<IKeyBehaviorTarget> defaultBehavior)
Parameters
defaultBehaviorAction<IKeyBehaviorTarget>
Returns
SetFormatter(Func<LineState, LineDisplayState>)
Sets the formatter for the configuration using a formatter which only needs a simple LineState.
public ReadLineConfig SetFormatter(Func<LineState, LineDisplayState> formatter)
Parameters
formatterFunc<LineState, LineDisplayState>
Returns
SetFormatter(Func<TokenizedLine, LineDisplayState>)
Sets the formatter for the configuration using a formatter based on a tokenized line. This will require that a lexer be provided for the configuration.
public ReadLineConfig SetFormatter(Func<TokenizedLine, LineDisplayState> formatter)
Parameters
formatterFunc<TokenizedLine, LineDisplayState>
Returns
SetHistorySource(IReadOnlyList<string>)
Sets the collection of previously entered lines to be used as the command history. Use this setter if you do not want the history to be automatically updated. Also, make sure to set some key behavior which will make use of the history.
public ReadLineConfig SetHistorySource(IReadOnlyList<string> history)
Parameters
historyIReadOnlyList<string>
Returns
SetHistoryUpdateAction(Action<string>)
Sets the action delegate which will get call when the readline is finalized and the history would otherwise update itself. Use this to provide a custom update action.
public ReadLineConfig SetHistoryUpdateAction(Action<string> action)
Parameters
Returns
SetLexer(Func<LineState, TokenizedLine>)
Sets the lexer for the configuration
public ReadLineConfig SetLexer(Func<LineState, TokenizedLine> lexer)
Parameters
lexerFunc<LineState, TokenizedLine>
Returns
SetUpdatingHistorySource(List<string>)
Sets the collection of previously entered lines to be used as the command history. This setter will cause the history list to be automatically updated. Also, make sure to set some key behavior which will make use of the history.
public ReadLineConfig SetUpdatingHistorySource(List<string> history)
Parameters
Returns
Remarks
The update action created here skips lines that are empty or contain only whitespace. It also skips a line that is identical to the most recent entry. These entries therefore do not crowd out useful history. To record every finalized line, provide your own action through SetHistoryUpdateAction.