Skip to content

CellPatternSearcher

Namespace: Hex1b.Automation

Assembly: Hex1b.dll

A fluent builder for describing patterns of terminal cells. Patterns can match based on character content, cell attributes, colors, and spatial relationships. The searcher is immutable - all methods return new instances, making patterns safe to reuse and compose.

csharp
public sealed class CellPatternSearcher

Inheritance

ObjectCellPatternSearcher

Constructors

CellPatternSearcher()

Creates a new empty pattern searcher.

csharp
public CellPatternSearcher()

Methods

BeginCapture(string)

Begins a named capture. All cells traversed until EndCapture() will be tagged with this capture name.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher BeginCapture(string name)

Down(char)

Moves one cell down and matches if it contains the specified character.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Down(char c)

Down(Func<CellMatchContext, bool>)

Moves one cell down and matches if the predicate returns true.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Down(Func<CellMatchContext, bool> predicate)

Down(int, Func<CellMatchContext, bool>)

Moves the specified number of cells down, all must match the predicate.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Down(int count, Func<CellMatchContext, bool> predicate)

Down(int)

Moves the specified number of cells down.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Down(int count)

DownToBottom()

Moves down to the bottom of the region.

Returns: CellPatternSearcher

csharp
public CellPatternSearcher DownToBottom()

DownUntil(Func<CellMatchContext, bool>)

Moves down until the predicate returns true (inclusive).

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher DownUntil(Func<CellMatchContext, bool> predicate)

DownUntil(string)

Moves down until the specified text is found (inclusive). Supports graphemes (multi-cell characters) by selecting adjacent cells.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher DownUntil(string text)

DownWhile(Func<CellMatchContext, bool>)

Moves down while the predicate returns true.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher DownWhile(Func<CellMatchContext, bool> predicate)

EndCapture()

Ends the most recently started capture.

Returns: CellPatternSearcher

csharp
public CellPatternSearcher EndCapture()

Find(char)

Starts the pattern by finding all cells containing the specified character.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Find(char c)

Find(Func<CellMatchContext, bool>)

Starts the pattern by finding all cells matching the predicate. Each matching cell becomes a potential starting point for the pattern.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Find(Func<CellMatchContext, bool> predicate)

Find(string, FindOptions)

Starts the pattern by finding all occurrences of the specified text. Supports graphemes (multi-cell characters).

Parameters:

  • text (String): The exact text to find.
  • options (FindOptions): Options controlling cursor position and match inclusion.

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Find(string text, FindOptions options = default)

FindMultilinePattern(Regex, FindOptions, bool, string?)

Starts the pattern by finding all matches of a compiled regex that can span multiple lines.

Parameters:

  • regex (Regex): The compiled regex to search for.
  • options (FindOptions): Options controlling cursor position and match inclusion.
  • trimLines (Boolean): Whether to trim whitespace from lines before matching.
  • lineSeparator (String): The line separator to use when concatenating lines.

Returns: CellPatternSearcher

csharp
public CellPatternSearcher FindMultilinePattern(Regex regex, FindOptions options = default, bool trimLines = false, string? lineSeparator = "\n")

FindMultilinePattern(string, RegexOptions, FindOptions, bool, string?)

Starts the pattern by finding all matches of a regex pattern that can span multiple lines. Uses the existing FindMultiLinePattern infrastructure.

Parameters:

  • pattern (String): The regex pattern to search for.
  • regexOptions (RegexOptions): Regular expression options.
  • findOptions (FindOptions): Options controlling cursor position and match inclusion.
  • trimLines (Boolean): Whether to trim whitespace from lines before matching.
  • lineSeparator (String): The line separator to use when concatenating lines.

Returns: CellPatternSearcher

csharp
public CellPatternSearcher FindMultilinePattern(string pattern, RegexOptions regexOptions = RegexOptions.None, FindOptions findOptions = default, bool trimLines = false, string? lineSeparator = "\n")

FindPattern(Regex, FindOptions)

Starts the pattern by finding all matches of a compiled regex (single-line).

Parameters:

  • regex (Regex): The compiled regex to search for.
  • options (FindOptions): Options controlling cursor position and match inclusion.

Returns: CellPatternSearcher

csharp
public CellPatternSearcher FindPattern(Regex regex, FindOptions options = default)

FindPattern(string, RegexOptions, FindOptions)

Starts the pattern by finding all matches of a regex pattern (single-line). Uses the existing FindPattern infrastructure for efficiency.

Parameters:

  • pattern (String): The regex pattern to search for.
  • regexOptions (RegexOptions): Regular expression options.
  • findOptions (FindOptions): Options controlling cursor position and match inclusion.

Returns: CellPatternSearcher

csharp
public CellPatternSearcher FindPattern(string pattern, RegexOptions regexOptions = RegexOptions.None, FindOptions findOptions = default)

Left(char)

Moves one cell to the left and matches if it contains the specified character.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Left(char c)

Left(Func<CellMatchContext, bool>)

Moves one cell to the left and matches if the predicate returns true.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Left(Func<CellMatchContext, bool> predicate)

Left(int, Func<CellMatchContext, bool>)

Moves the specified number of cells to the left, all must match the predicate.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Left(int count, Func<CellMatchContext, bool> predicate)

Left(int)

Moves the specified number of cells to the left.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Left(int count)

LeftText(string)

Matches a sequence of characters moving to the left.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher LeftText(string text)

LeftToStart()

Moves left to the start of the line.

Returns: CellPatternSearcher

csharp
public CellPatternSearcher LeftToStart()

LeftUntil(char)

Moves left until the specified character is found (inclusive).

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher LeftUntil(char c)

LeftUntil(Func<CellMatchContext, bool>)

Moves left until the predicate returns true (inclusive).

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher LeftUntil(Func<CellMatchContext, bool> predicate)

LeftUntil(string)

Moves left until the specified text is found (inclusive). Supports graphemes (multi-cell characters) by selecting adjacent cells.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher LeftUntil(string text)

LeftWhile(Func<CellMatchContext, bool>)

Moves left while the predicate returns true.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher LeftWhile(Func<CellMatchContext, bool> predicate)

Match(char)

Matches the specified character at the current cursor position.

Parameters:

  • c (Char): The character to match.

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Match(char c)

Match(Func<CellMatchContext, bool>)

Matches if the predicate returns true for the current cell.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Match(Func<CellMatchContext, bool> predicate)

Match(string)

Matches the specified text at the current cursor position. Unlike Find, this does not search the region - it matches exactly where the cursor is. Use this in sub-patterns (ThenEither, ThenOptional, etc.) to continue from the current position.

Parameters:

  • text (String): The exact text to match at the current position.

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Match(string text)

Right(char)

Moves one cell to the right and matches if it contains the specified character.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Right(char c)

Right(Func<CellMatchContext, bool>)

Moves one cell to the right and matches if the predicate returns true.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Right(Func<CellMatchContext, bool> predicate)

Right(int, Func<CellMatchContext, bool>)

Moves the specified number of cells to the right, all must match the predicate.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Right(int count, Func<CellMatchContext, bool> predicate)

Right(int)

Moves the specified number of cells to the right.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Right(int count)

RightText(string)

Matches a sequence of characters moving to the right.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher RightText(string text)

RightToEnd()

Moves right to the end of the line.

Returns: CellPatternSearcher

csharp
public CellPatternSearcher RightToEnd()

RightUntil(char)

Moves right until the specified character is found (inclusive).

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher RightUntil(char c)

RightUntil(Func<CellMatchContext, bool>)

Moves right until the predicate returns true (inclusive). The matching cell is included in the result. Fails if boundary is reached without a match.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher RightUntil(Func<CellMatchContext, bool> predicate)

RightUntil(string)

Moves right until the specified text is found (inclusive). Supports graphemes (multi-cell characters) by selecting adjacent cells.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher RightUntil(string text)

RightWhile(Func<CellMatchContext, bool>)

Moves right while the predicate returns true. Stops when predicate returns false (that cell is not consumed). Zero matches is valid.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher RightWhile(Func<CellMatchContext, bool> predicate)

Search(IHex1bTerminalRegion)

Searches for all occurrences of the pattern in the region.

Parameters:

Returns: CellPatternSearchResult

csharp
public CellPatternSearchResult Search(IHex1bTerminalRegion region)

SearchFirst(IHex1bTerminalRegion)

Searches for the first occurrence of the pattern in the region.

Parameters:

Returns: CellPatternMatch

csharp
public CellPatternMatch? SearchFirst(IHex1bTerminalRegion region)

Then(CellPatternSearcher)

Embeds another pattern's steps at this point.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Then(CellPatternSearcher subPattern)

Then(Func<CellPatternSearcher, CellPatternSearcher>)

Builds and embeds a sub-pattern at this point. The function receives a new searcher and should return the built pattern.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Then(Func<CellPatternSearcher, CellPatternSearcher> buildPattern)

ThenEither(Func<CellPatternSearcher, CellPatternSearcher>, Func<CellPatternSearcher, CellPatternSearcher>)

Tries the first pattern, falls back to the second if the first fails. The functions receive a new searcher to build continuation patterns. Use Match() instead of Find() in sub-patterns to match at the current position.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher ThenEither(Func<CellPatternSearcher, CellPatternSearcher> first, Func<CellPatternSearcher, CellPatternSearcher> second)

ThenOptional(CellPatternSearcher)

Optionally matches a sub-pattern. If it fails, continues from current position.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher ThenOptional(CellPatternSearcher subPattern)

ThenOptional(Func<CellPatternSearcher, CellPatternSearcher>)

Optionally matches a sub-pattern built by the provided function. If it fails, continues from current position.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher ThenOptional(Func<CellPatternSearcher, CellPatternSearcher> buildPattern)

ThenRepeat(CellPatternSearcher)

Repeats a pattern while it continues to match.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher ThenRepeat(CellPatternSearcher repeatedPattern)

ThenRepeat(Func<CellPatternSearcher, CellPatternSearcher>)

Repeats a pattern built by the provided function while it continues to match.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher ThenRepeat(Func<CellPatternSearcher, CellPatternSearcher> buildPattern)

ThenRepeat(int, CellPatternSearcher)

Repeats a pattern exactly N times.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher ThenRepeat(int count, CellPatternSearcher repeatedPattern)

ThenRepeat(int, Func<CellPatternSearcher, CellPatternSearcher>)

Repeats a pattern built by the provided function exactly N times.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher ThenRepeat(int count, Func<CellPatternSearcher, CellPatternSearcher> buildPattern)

Up(char)

Moves one cell up and matches if it contains the specified character.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Up(char c)

Up(Func<CellMatchContext, bool>)

Moves one cell up and matches if the predicate returns true.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Up(Func<CellMatchContext, bool> predicate)

Up(int, Func<CellMatchContext, bool>)

Moves the specified number of cells up, all must match the predicate.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Up(int count, Func<CellMatchContext, bool> predicate)

Up(int)

Moves the specified number of cells up.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher Up(int count)

UpToTop()

Moves up to the top of the region.

Returns: CellPatternSearcher

csharp
public CellPatternSearcher UpToTop()

UpUntil(Func<CellMatchContext, bool>)

Moves up until the predicate returns true (inclusive).

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher UpUntil(Func<CellMatchContext, bool> predicate)

UpUntil(string)

Moves up until the specified text is found (inclusive). Supports graphemes (multi-cell characters) by selecting adjacent cells.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher UpUntil(string text)

UpWhile(Func<CellMatchContext, bool>)

Moves up while the predicate returns true.

Parameters:

Returns: CellPatternSearcher

csharp
public CellPatternSearcher UpWhile(Func<CellMatchContext, bool> predicate)

Released under the MIT License.