Skip to content

SurfaceComparer

Namespace: Hex1b.Surfaces

Assembly: Hex1b.dll

Provides methods for comparing surfaces and generating output.

csharp
public static class SurfaceComparer

Inheritance

ObjectSurfaceComparer

Methods

Compare(Surface, Surface)

Compares two surfaces and returns the differences.

Parameters:

  • previous (Surface): The previous surface state.
  • current (Surface): The current surface state.

Returns: SurfaceDiff

A containing all changed cells.

csharp
public static SurfaceDiff Compare(Surface previous, Surface current)

CompareToEmpty(Surface)

Compares a surface against an empty (default) state.

Parameters:

  • surface (Surface): The surface to compare against empty.

Returns: SurfaceDiff

A containing all non-empty cells.

csharp
public static SurfaceDiff CompareToEmpty(Surface surface)

CompositeToAnsiString(CompositeSurface, Surface?)

Generates an ANSI string for a composite surface including cells and sixels.

Parameters:

  • composite (CompositeSurface): The composite surface to render.
  • previous (Surface): Optional previous surface state for diff-based rendering.

Returns: String

An ANSI escape sequence string that will render the surface.

csharp
public static string CompositeToAnsiString(CompositeSurface composite, Surface? previous = null)

CompositeToTokens(CompositeSurface, Surface?)

Generates tokens for a composite surface including both cells and sixels.

Parameters:

  • composite (CompositeSurface): The composite surface to render.
  • previous (Surface): Optional previous surface state for diff-based rendering.

Returns: IReadOnlyList<AnsiToken>

A list of ANSI tokens that will render the surface.

csharp
public static IReadOnlyList<AnsiToken> CompositeToTokens(CompositeSurface composite, Surface? previous = null)

CreateFullDiff(Surface)

Creates a full-surface diff that treats the entire surface as changed.

Parameters:

  • surface (Surface): The surface to create a full diff for.

Returns: SurfaceDiff

A containing all cells.

csharp
public static SurfaceDiff CreateFullDiff(Surface surface)

SixelFragmentsToTokens(CompositeSurface)

Generates tokens for sixel fragments from a composite surface.

Parameters:

Returns: IReadOnlyList<AnsiToken>

A list of ANSI tokens that will render the sixel fragments.

csharp
public static IReadOnlyList<AnsiToken> SixelFragmentsToTokens(CompositeSurface composite)

ToAnsiString(SurfaceDiff, Surface?)

Generates an ANSI string to render the diff, with sixel awareness.

Parameters:

  • diff (SurfaceDiff): The surface diff to render.
  • currentSurface (Surface): The current surface, used to find sixels that need re-rendering.

Returns: String

An ANSI escape sequence string that will render the changes.

csharp
public static string ToAnsiString(SurfaceDiff diff, Surface? currentSurface)

ToAnsiString(SurfaceDiff)

Generates an ANSI string to render the diff.

Parameters:

Returns: String

An ANSI escape sequence string that will render the changes.

csharp
public static string ToAnsiString(SurfaceDiff diff)

ToTokens(SurfaceDiff, Surface?, Surface?, bool)

Generates a list of ANSI tokens to render the diff, with sixel and KGP awareness. When a previous surface is provided, KGP images that have moved or been removed will emit delete commands so the terminal cleans up stale placements.

Parameters:

  • diff (SurfaceDiff): The surface diff to render.
  • currentSurface (Surface): The current surface, used to find images that need re-rendering when their region is dirty.
  • previousSurface (Surface): The previous surface, used to detect KGP images that need to be deleted.
  • skipKgpEmission (Boolean): When true, KGP region detection is still performed (for text skipping) but no KGP delete/transmit/placement tokens are emitted. Use this when a handles KGP lifecycle externally.

Returns: IReadOnlyList<AnsiToken>

A list of ANSI tokens that will render the changes.

csharp
public static IReadOnlyList<AnsiToken> ToTokens(SurfaceDiff diff, Surface? currentSurface, Surface? previousSurface, bool skipKgpEmission = false)

ToTokens(SurfaceDiff, Surface?)

Generates a list of ANSI tokens to render the diff, with sixel awareness.

Parameters:

  • diff (SurfaceDiff): The surface diff to render.
  • currentSurface (Surface): The current surface, used to find sixels that need re-rendering when their region is dirty.

Returns: IReadOnlyList<AnsiToken>

A list of ANSI tokens that will render the changes.

csharp
public static IReadOnlyList<AnsiToken> ToTokens(SurfaceDiff diff, Surface? currentSurface)

ToTokens(SurfaceDiff)

Generates an optimized list of ANSI tokens to render the diff.

Parameters:

Returns: IReadOnlyList<AnsiToken>

A list of ANSI tokens that will render the changes.

csharp
public static IReadOnlyList<AnsiToken> ToTokens(SurfaceDiff diff)

Released under the MIT License.