Skip to content

Hex1bTerminalRegionExtensions

Namespace: Hex1b.Automation

Assembly: Hex1b.dll

Extension methods for providing common text operations.

csharp
public static class Hex1bTerminalRegionExtensions

Inheritance

ObjectHex1bTerminalRegionExtensions

Methods

ContainsMultiLinePattern(IHex1bTerminalRegion, Regex, bool, string?)

Checks if the region contains text matching the specified compiled regular expression across multiple lines.

Parameters:

  • region (IHex1bTerminalRegion): The terminal region to search.
  • regex (Regex): The compiled regular expression to search for.
  • trimLines (Boolean): If true, trailing whitespace is removed from each line before matching. Default is false to preserve exact screen content.
  • lineSeparator (String): The string to insert between lines. Default is "\n". Pass null or empty to concatenate lines directly.

Returns: Boolean

True if a match is found, false otherwise.

csharp
public static bool ContainsMultiLinePattern(this IHex1bTerminalRegion region, Regex regex, bool trimLines = false, string? lineSeparator = "\n")

ContainsMultiLinePattern(IHex1bTerminalRegion, string, RegexOptions, bool, string?)

Checks if the region contains text matching the specified regular expression pattern across multiple lines.

Parameters:

  • region (IHex1bTerminalRegion): The terminal region to search.
  • pattern (String): The regular expression pattern to search for.
  • options (RegexOptions): Regular expression options (default is None). Singleline option treats the entire text as one line, allowing . to match newlines.
  • trimLines (Boolean): If true, trailing whitespace is removed from each line before matching. Default is false to preserve exact screen content.
  • lineSeparator (String): The string to insert between lines. Default is "\n". Pass null or empty to concatenate lines directly.

Returns: Boolean

True if a match is found, false otherwise.

csharp
public static bool ContainsMultiLinePattern(this IHex1bTerminalRegion region, string pattern, RegexOptions options = RegexOptions.None, bool trimLines = false, string? lineSeparator = "\n")

ContainsPattern(IHex1bTerminalRegion, Regex)

Checks if the region contains text matching the specified compiled regular expression.

Parameters:

Returns: Boolean

True if a match is found, false otherwise.

csharp
public static bool ContainsPattern(this IHex1bTerminalRegion region, Regex regex)

ContainsPattern(IHex1bTerminalRegion, string, RegexOptions)

Checks if the region contains text matching the specified regular expression pattern.

Parameters:

  • region (IHex1bTerminalRegion): The terminal region to search.
  • pattern (String): The regular expression pattern to search for.
  • options (RegexOptions): Regular expression options (default is None).

Returns: Boolean

True if a match is found, false otherwise.

csharp
public static bool ContainsPattern(this IHex1bTerminalRegion region, string pattern, RegexOptions options = RegexOptions.None)

ContainsText(IHex1bTerminalRegion, string)

Checks if the region contains the specified text anywhere.

Parameters:

Returns: Boolean

csharp
public static bool ContainsText(this IHex1bTerminalRegion region, string text)

ContentEquals(IHex1bTerminalRegion, IHex1bTerminalRegion)

Compares the content of two regions. Returns true if they have the same dimensions and identical cell content.

Parameters:

Returns: Boolean

csharp
public static bool ContentEquals(this IHex1bTerminalRegion region, IHex1bTerminalRegion other)

FindFirstMultiLinePattern(IHex1bTerminalRegion, Regex, bool, string?)

Finds the first occurrence of a compiled regular expression across multiple lines in the region. The entire region text is joined with the specified separator, allowing patterns to match across line boundaries.

Parameters:

  • region (IHex1bTerminalRegion): The terminal region to search.
  • regex (Regex): The compiled regular expression to search for.
  • trimLines (Boolean): If true, trailing whitespace is removed from each line before matching. Default is false to preserve exact screen content.
  • lineSeparator (String): The string to insert between lines. Default is "\n". Pass null or empty to concatenate lines directly.

Returns: Nullable<MultiLineTextMatch>

The first match with its coordinates, or null if not found.

csharp
public static MultiLineTextMatch? FindFirstMultiLinePattern(this IHex1bTerminalRegion region, Regex regex, bool trimLines = false, string? lineSeparator = "\n")

FindFirstMultiLinePattern(IHex1bTerminalRegion, string, RegexOptions, bool, string?)

Finds the first occurrence of a regular expression pattern across multiple lines in the region. The entire region text is joined with the specified separator, allowing patterns to match across line boundaries.

Parameters:

  • region (IHex1bTerminalRegion): The terminal region to search.
  • pattern (String): The regular expression pattern to search for.
  • options (RegexOptions): Regular expression options (default is None). Singleline option treats the entire text as one line, allowing . to match newlines.
  • trimLines (Boolean): If true, trailing whitespace is removed from each line before matching. Default is false to preserve exact screen content.
  • lineSeparator (String): The string to insert between lines. Default is "\n". Pass null or empty to concatenate lines directly.

Returns: Nullable<MultiLineTextMatch>

The first match with its coordinates, or null if not found.

csharp
public static MultiLineTextMatch? FindFirstMultiLinePattern(this IHex1bTerminalRegion region, string pattern, RegexOptions options = RegexOptions.None, bool trimLines = false, string? lineSeparator = "\n")

FindFirstPattern(IHex1bTerminalRegion, Regex)

Finds the first occurrence of a compiled regular expression in the region. Returns the if found, or null if not found.

Parameters:

Returns: Nullable<TextMatch>

The first match with its coordinates and matched text, or null if not found.

csharp
public static TextMatch? FindFirstPattern(this IHex1bTerminalRegion region, Regex regex)

FindFirstPattern(IHex1bTerminalRegion, string, RegexOptions)

Finds the first occurrence of a regular expression pattern in the region. Returns the if found, or null if not found.

Parameters:

  • region (IHex1bTerminalRegion): The terminal region to search.
  • pattern (String): The regular expression pattern to search for.
  • options (RegexOptions): Regular expression options (default is None).

Returns: Nullable<TextMatch>

The first match with its coordinates and matched text, or null if not found.

csharp
public static TextMatch? FindFirstPattern(this IHex1bTerminalRegion region, string pattern, RegexOptions options = RegexOptions.None)

FindMultiLinePattern(IHex1bTerminalRegion, Regex, bool, string?)

Finds all occurrences of a compiled regular expression across multiple lines in the region. The entire region text is joined with the specified separator, allowing patterns to match across line boundaries.

Parameters:

  • region (IHex1bTerminalRegion): The terminal region to search.
  • regex (Regex): The compiled regular expression to search for.
  • trimLines (Boolean): If true, trailing whitespace is removed from each line before matching. Default is false to preserve exact screen content.
  • lineSeparator (String): The string to insert between lines. Default is "\n". Pass null or empty to concatenate lines directly.

Returns: List<MultiLineTextMatch>

A list of matches with their start and end coordinates.

csharp
public static List<MultiLineTextMatch> FindMultiLinePattern(this IHex1bTerminalRegion region, Regex regex, bool trimLines = false, string? lineSeparator = "\n")

FindMultiLinePattern(IHex1bTerminalRegion, string, RegexOptions, bool, string?)

Finds all occurrences of a regular expression pattern across multiple lines in the region. The entire region text is joined with the specified separator, allowing patterns to match across line boundaries.

Parameters:

  • region (IHex1bTerminalRegion): The terminal region to search.
  • pattern (String): The regular expression pattern to search for.
  • options (RegexOptions): Regular expression options (default is None). Singleline option treats the entire text as one line, allowing . to match newlines.
  • trimLines (Boolean): If true, trailing whitespace is removed from each line before matching. Default is false to preserve exact screen content.
  • lineSeparator (String): The string to insert between lines. Default is "\n". Pass null or empty to concatenate lines directly.

Returns: List<MultiLineTextMatch>

A list of matches with their start and end coordinates.

csharp
public static List<MultiLineTextMatch> FindMultiLinePattern(this IHex1bTerminalRegion region, string pattern, RegexOptions options = RegexOptions.None, bool trimLines = false, string? lineSeparator = "\n")

FindPattern(IHex1bTerminalRegion, Regex)

Finds all occurrences of a compiled regular expression in the region. Returns a list of objects with start and end coordinates.

Parameters:

Returns: List<TextMatch>

A list of matches with their coordinates and matched text.

csharp
public static List<TextMatch> FindPattern(this IHex1bTerminalRegion region, Regex regex)

FindPattern(IHex1bTerminalRegion, string, RegexOptions)

Finds all occurrences of a regular expression pattern in the region. Returns a list of objects with start and end coordinates.

Parameters:

  • region (IHex1bTerminalRegion): The terminal region to search.
  • pattern (String): The regular expression pattern to search for.
  • options (RegexOptions): Regular expression options (default is None).

Returns: List<TextMatch>

A list of matches with their coordinates and matched text.

csharp
public static List<TextMatch> FindPattern(this IHex1bTerminalRegion region, string pattern, RegexOptions options = RegexOptions.None)

FindText(IHex1bTerminalRegion, string)

Finds all occurrences of the specified text in the region. Returns a list of (line, column) positions.

Parameters:

Returns: List<Int32, Int32>>

csharp
public static List<(int Line, int Column)> FindText(this IHex1bTerminalRegion region, string text)

GetDisplayText(IHex1bTerminalRegion)

Gets all lines as a single string for display/debugging (non-empty lines only).

Parameters:

Returns: String

csharp
public static string GetDisplayText(this IHex1bTerminalRegion region)

GetLine(IHex1bTerminalRegion, int)

Gets the text content of a line.

Parameters:

Returns: String

csharp
public static string GetLine(this IHex1bTerminalRegion region, int y)

GetLineTrimmed(IHex1bTerminalRegion, int)

Gets the text content of a line with trailing whitespace removed.

Parameters:

Returns: String

csharp
public static string GetLineTrimmed(this IHex1bTerminalRegion region, int y)

GetMultiLineTextAt(IHex1bTerminalRegion, int, int, int, int)

Gets the text content across multiple lines at the specified coordinates.

Parameters:

  • region (IHex1bTerminalRegion): The terminal region.
  • startLine (Int32): The starting line (Y coordinate).
  • startColumn (Int32): The starting column (X coordinate).
  • endLine (Int32): The ending line (Y coordinate).
  • endColumn (Int32): The ending column (X coordinate, exclusive).

Returns: String

The text at the specified coordinates, with lines separated by newlines.

csharp
public static string GetMultiLineTextAt(this IHex1bTerminalRegion region, int startLine, int startColumn, int endLine, int endColumn)

GetMultiLineTextAt(IHex1bTerminalRegion, MultiLineTextMatch)

Gets the text content at the coordinates specified by a .

Parameters:

Returns: String

The text at the match coordinates.

csharp
public static string GetMultiLineTextAt(this IHex1bTerminalRegion region, MultiLineTextMatch match)

GetNonEmptyLines(IHex1bTerminalRegion)

Gets all non-empty lines from the region.

Parameters:

Returns: IEnumerable<String>

csharp
public static IEnumerable<string> GetNonEmptyLines(this IHex1bTerminalRegion region)

GetText(IHex1bTerminalRegion)

Gets all lines as a single string separated by newlines.

Parameters:

Returns: String

csharp
public static string GetText(this IHex1bTerminalRegion region)

GetTextAt(IHex1bTerminalRegion, int, int, int)

Gets the text content at the specified coordinates.

Parameters:

  • region (IHex1bTerminalRegion): The terminal region.
  • line (Int32): The line (Y coordinate) to read from.
  • startColumn (Int32): The starting column (X coordinate).
  • endColumn (Int32): The ending column (X coordinate, exclusive).

Returns: String

The text at the specified coordinates.

csharp
public static string GetTextAt(this IHex1bTerminalRegion region, int line, int startColumn, int endColumn)

GetTextAt(IHex1bTerminalRegion, TextMatch)

Gets the text content at the coordinates specified by a .

Parameters:

Returns: String

The text at the match coordinates.

csharp
public static string GetTextAt(this IHex1bTerminalRegion region, TextMatch match)

HasAttribute(IHex1bTerminalRegion, CellAttributes)

Checks if any cell in the region has the specified attribute.

Parameters:

Returns: Boolean

csharp
public static bool HasAttribute(this IHex1bTerminalRegion region, CellAttributes attribute)

HasBackgroundColor(IHex1bTerminalRegion, Hex1bColor)

Checks if any cell in the region has the specified background color.

Parameters:

Returns: Boolean

csharp
public static bool HasBackgroundColor(this IHex1bTerminalRegion region, Hex1bColor color)

HasBackgroundColor(IHex1bTerminalRegion)

Checks if any cell in the region has a non-null background color.

Parameters:

Returns: Boolean

csharp
public static bool HasBackgroundColor(this IHex1bTerminalRegion region)

HasForegroundColor(IHex1bTerminalRegion, Hex1bColor)

Checks if any cell in the region has the specified foreground color.

Parameters:

Returns: Boolean

csharp
public static bool HasForegroundColor(this IHex1bTerminalRegion region, Hex1bColor color)

HasForegroundColor(IHex1bTerminalRegion)

Checks if any cell in the region has a non-null foreground color.

Parameters:

Returns: Boolean

csharp
public static bool HasForegroundColor(this IHex1bTerminalRegion region)

TextEquals(IHex1bTerminalRegion, IHex1bTerminalRegion)

Compares only the text content of two regions. Ignores colors and other cell attributes.

Parameters:

Returns: Boolean

csharp
public static bool TextEquals(this IHex1bTerminalRegion region, IHex1bTerminalRegion other)

Released under the MIT License.