pub enum WidthMode {
Wc,
Grapheme,
}Expand description
How grapheme clusters are measured for terminal-cell layout.
This enum does not control segmentation: grapheme_cells always
segments by extended grapheme cluster. It controls only width calculation
for each cluster. The East-Asian Ambiguous policy is orthogonal and is
passed as a separate eaw_wide boolean to char_width and
grapheme_width.
Variants§
Wc
Measure each cluster by the width of its first code point.
This is wcwidth-style and intentionally cluster-blind: variation selectors, zero-width joiners, and emoji presentation overrides in the rest of the cluster do not change the result. Use this when matching older or simpler terminal width behavior is more important than cluster-aware emoji presentation.
Grapheme
Measure the whole grapheme cluster.
This mode accounts for variation selectors, regional indicators, zero-width-joiner sequences, and pictographic presentation when deciding whether a cluster occupies zero, one, or two cells. Use it for modern terminal rendering that treats emoji and joined clusters as a single displayed unit.
Implementations§
Source§impl WidthMode
impl WidthMode
Sourcepub fn grapheme_width(self, g: &str, eaw_wide: bool) -> u8
pub fn grapheme_width(self, g: &str, eaw_wide: bool) -> u8
Measure one extended grapheme cluster under this mode.
In WidthMode::Wc mode, the width is the char_width of g’s
first code point, or 0 for an empty string. In
WidthMode::Grapheme mode, the width is grapheme_width for the
whole cluster.
§Parameters
g— an extended grapheme cluster. Passing a longer string is accepted but only the first code point is considered inWcmode.eaw_wide— East-Asian Ambiguous policy; seechar_width.
§Returns
The cluster width in terminal cells, normally 0, 1, or 2.
§Errors and panics
This method does not fail or intentionally panic.