Table of Contents

Class UnicodeWidth

Namespace
SharpConsoleUI.Helpers
Assembly
SharpConsoleUI.dll

Provides display width information for Unicode characters. Delegates to the Wcwidth library for accurate width calculation including zero-width characters (combining marks, variation selectors, ZWJ). Spacing Combining Marks (Unicode category Mc) are corrected to width 1, as they occupy visual space in terminals despite Wcwidth marking them zero-width. Adapts to terminal capabilities: uses Unicode 15.0 width tables unless the terminal is detected to support Unicode 16.0 widths (probed at startup).

public static class UnicodeWidth
Inheritance
UnicodeWidth
Inherited Members

Methods

GetCharWidth(char)

Returns the display width of a character in terminal columns (0, 1, or 2). Spacing Combining Marks (Mc) are corrected to width 1.

public static int GetCharWidth(char c)

Parameters

c char

Returns

int

GetRuneWidth(Rune)

Returns the display width of a Rune in terminal columns (0, 1, or 2). Spacing Combining Marks (Mc) are corrected to width 1.

public static int GetRuneWidth(Rune r)

Parameters

r Rune

Returns

int

GetStringWidth(string)

Returns the total display width of a string, summing per-Rune widths. Zero-width characters contribute 0 to the total. VS16 (U+FE0F) after a widenable emoji adds 1 column (widening from 1 to 2).

public static int GetStringWidth(string s)

Parameters

s string

Returns

int

IsVS16(Rune)

Returns true if the rune is Variation Selector 16 (U+FE0F), which widens certain emoji from 1 to 2 terminal columns.

public static bool IsVS16(Rune r)

Parameters

r Rune

Returns

bool

IsVs16Widened(Rune)

Returns true if VS16 (U+FE0F) after this rune widens it from 1 to 2 columns. Uses the Wcwidth library's Vs16Table for accurate lookup. Returns false if the terminal does not support VS16 widening (detected at startup via TerminalCapabilities.Probe).

public static bool IsVs16Widened(Rune baseRune)

Parameters

baseRune Rune

Returns

bool

IsWide(char)

Returns true if the character occupies 2 terminal columns.

public static bool IsWide(char c)

Parameters

c char

Returns

bool

IsWideRune(Rune)

Returns true if the Rune occupies 2 terminal columns.

public static bool IsWideRune(Rune r)

Parameters

r Rune

Returns

bool

IsZeroWidth(Rune)

Returns true if the Rune occupies 0 terminal columns (combining mark, etc.).

public static bool IsZeroWidth(Rune r)

Parameters

r Rune

Returns

bool