Table of Contents

Class UnicodeWidth

Namespace
MiniTui
Assembly
MiniTui.dll

Display width of text in terminal columns, by grapheme cluster (UAX #29). Width tables come from Unicode 16.0; see tools/GenWidthTable.cs.

public static class UnicodeWidth
Inheritance
UnicodeWidth
Inherited Members

Methods

Graphemes(string)

Split text into grapheme clusters (StringInfo text elements).

public static IEnumerable<string> Graphemes(string text)

Parameters

text string

Returns

IEnumerable<string>

Of(ReadOnlySpan<char>)

Total display width of text: the sum over its grapheme clusters.

public static int Of(ReadOnlySpan<char> text)

Parameters

text ReadOnlySpan<char>

Returns

int

OfGrapheme(ReadOnlySpan<char>)

Display width of a single grapheme cluster: 0, 1 or 2.

public static int OfGrapheme(ReadOnlySpan<char> grapheme)

Parameters

grapheme ReadOnlySpan<char>

Returns

int

Truncate(string, int, string)

Truncate text to at most maxWidth columns. If it doesn't fit, as many whole grapheme clusters as fit are kept and ellipsis is appended.

public static string Truncate(string text, int maxWidth, string ellipsis = "…")

Parameters

text string
maxWidth int
ellipsis string

Returns

string