Table of Contents

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

ReadLineConfig

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

bool

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

Action<IKeyBehaviorTarget>

Empty

Gets an empty configuration with absolutely nothing set

public static ReadLineConfig Empty { get; }

Property Value

ReadLineConfig

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

Func<LineState, LineDisplayState>

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

Func<TokenizedLine, LineDisplayState>

History

Gets the history of entered text, or null when no history source is configured.

public IReadOnlyList<string>? History { get; }

Property Value

IReadOnlyList<string>

KeyBehaviors

Gets a dictionary which maps key press information to key behavior methods

public Dictionary<KeyId, Action<IKeyBehaviorTarget>> KeyBehaviors { get; }

Property Value

Dictionary<KeyId, Action<IKeyBehaviorTarget>>

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

Func<LineState, TokenizedLine>

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

Action<string>

Methods

SetAutoCompletion(Func<TokenizedLine, string[]>)

Sets the auto-completion handler for the configuration

public ReadLineConfig SetAutoCompletion(Func<TokenizedLine, string[]> handler)

Parameters

handler Func<TokenizedLine, string[]>

Returns

ReadLineConfig

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

defaultBehavior Action<IKeyBehaviorTarget>

Returns

ReadLineConfig

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

formatter Func<LineState, LineDisplayState>

Returns

ReadLineConfig

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

formatter Func<TokenizedLine, LineDisplayState>

Returns

ReadLineConfig

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

history IReadOnlyList<string>

Returns

ReadLineConfig

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

action Action<string>

Returns

ReadLineConfig

SetLexer(Func<LineState, TokenizedLine>)

Sets the lexer for the configuration

public ReadLineConfig SetLexer(Func<LineState, TokenizedLine> lexer)

Parameters

lexer Func<LineState, TokenizedLine>

Returns

ReadLineConfig

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

history List<string>

Returns

ReadLineConfig

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.