C# Class PowerArgs.Cli.SimpleSyntaxHighlighter

A utility that makes it easy to perform common types of syntax highlighting based on keywords, regular expressions, etc.
Show file Open project: adamabdelhamed/PowerArgs

Private Properties

Property Type Description
EnsureHighlighted bool

Public Methods

Method Description
AddConditionalKeyword ( string keyword, Func conditionEval, ConsoleColor fg = null, ConsoleColor bg = null, System.StringComparison comparison = StringComparison.InvariantCulture ) : void

Registers a keyword with the highlighter that should only be highlighted if some condition is true

AddKeyword ( string keyword, ConsoleColor fg = null, ConsoleColor bg = null, System.StringComparison comparison = StringComparison.InvariantCulture ) : void

Registers a keyword with the highlighter.

AddRegex ( string regex, ConsoleColor fg = null, ConsoleColor bg = null ) : void

Registers a regular expression with the highlighter. Tokens that exactly match the given regex will be highlighted.

AddTokenHighlighter ( ITokenHighlighter highlighter ) : void

Registers a custom token highlighter

SetNumericHighlight ( ConsoleColor fg = null, ConsoleColor bg = null ) : void

Lets you control how numeric values should be highlighted

SetQuotedStringLiteralHighlight ( ConsoleColor fg = null, ConsoleColor bg = null ) : void

Lets you control how quoted string literals should be highlighted

SimpleSyntaxHighlighter ( ) : System

Creates a new SimpleSyntaxHighlighter

TryHighlight ( RichCommandLineContext readerContext ) : bool

The implementation of ISyntaxHighlighter that uses the configuration you've created to perform syntax highlighting.

Private Methods

Method Description
EnsureHighlighted ( Token token, RichCommandLineContext context, ConsoleColor fg, ConsoleColor bg ) : bool

Method Details

AddConditionalKeyword() public method

Registers a keyword with the highlighter that should only be highlighted if some condition is true
public AddConditionalKeyword ( string keyword, Func conditionEval, ConsoleColor fg = null, ConsoleColor bg = null, System.StringComparison comparison = StringComparison.InvariantCulture ) : void
keyword string The keyword that will conditionally be highlighted when found on the command line
conditionEval Func the conditional evaluation function
fg ConsoleColor The foreground highlight color
bg ConsoleColor The background highlight color
comparison System.StringComparison Determines how strings are compared.
return void

AddKeyword() public method

Registers a keyword with the highlighter.
public AddKeyword ( string keyword, ConsoleColor fg = null, ConsoleColor bg = null, System.StringComparison comparison = StringComparison.InvariantCulture ) : void
keyword string The keyword that will be highlighted when found on the command line
fg ConsoleColor The foreground highlight color
bg ConsoleColor The background highlight color
comparison System.StringComparison Determines how strings are compared.
return void

AddRegex() public method

Registers a regular expression with the highlighter. Tokens that exactly match the given regex will be highlighted.
public AddRegex ( string regex, ConsoleColor fg = null, ConsoleColor bg = null ) : void
regex string the regular expression pattern to search for
fg ConsoleColor The foreground highlight color
bg ConsoleColor The background highlight color
return void

AddTokenHighlighter() public method

Registers a custom token highlighter
public AddTokenHighlighter ( ITokenHighlighter highlighter ) : void
highlighter ITokenHighlighter the custom highlighter
return void

SetNumericHighlight() public method

Lets you control how numeric values should be highlighted
public SetNumericHighlight ( ConsoleColor fg = null, ConsoleColor bg = null ) : void
fg ConsoleColor The foreground highlight color
bg ConsoleColor The background highlight color
return void

SetQuotedStringLiteralHighlight() public method

Lets you control how quoted string literals should be highlighted
public SetQuotedStringLiteralHighlight ( ConsoleColor fg = null, ConsoleColor bg = null ) : void
fg ConsoleColor The foreground highlight color
bg ConsoleColor The background highlight color
return void

SimpleSyntaxHighlighter() public method

Creates a new SimpleSyntaxHighlighter
public SimpleSyntaxHighlighter ( ) : System
return System

TryHighlight() public method

The implementation of ISyntaxHighlighter that uses the configuration you've created to perform syntax highlighting.
public TryHighlight ( RichCommandLineContext readerContext ) : bool
readerContext RichCommandLineContext Context that is used internally
return bool