hasUncertainWidth function

bool hasUncertainWidth(
  1. String grapheme
)

Whether a terminal's rendered width for grapheme is genuinely likely to disagree with the width model — i.e. whether getting this glyph wrong is a live risk rather than a theoretical one.

True for the emoji-capable clusters, where terminals and fonts really do differ: an explicit presentation selector or ZWJ, the emoji planes, and the Misc-Symbols/Dingbats block (where ✓ ✗ ☀ live — the block whose misclassification desynced whole frames). False for ASCII and CJK, where every implementation agrees, and false for box drawing, blocks, geometric shapes and arrows: those are UAX #11 Ambiguous, answered by the startup probe, and they appear in long runs where pinning would cost real bytes.

The renderer uses this to decide whether to pin each following cell to an absolute column. That containment is what keeps a width disagreement a local cosmetic artifact instead of shifting every subsequent cell on the row — the difference between a smudged glyph and a garbled frame.

Implementation

bool hasUncertainWidth(String grapheme) {
  if (grapheme.isEmpty) return false;
  // Single-code-unit fast path, allocation-free: this is called per dirty
  // non-ASCII cell, and box-drawing runs would otherwise pay a runes iterator
  // per cell to be told what a range check answers. Only true clusters
  // (surrogate pairs, ZWJ sequences, selectors) need the walk below.
  if (grapheme.length == 1) {
    final c = grapheme.codeUnitAt(0);
    if (c >= 0x20 && c <= 0x7E) return false; // ASCII is certain
    return c >= 0x2600 && c <= 0x27BF; // misc symbols & dingbats
  }
  final iterator = grapheme.runes.iterator;
  if (!iterator.moveNext()) return false;
  final base = iterator.current;
  // A cluster that opens with a zero-width code point (a prepended
  // concatenation mark, or a mark with no base) has no agreed width: wcwidth
  // gives the concatenation marks a cell of their own, the width model does not.
  if (widthRangesContain(zeroWidthRanges, base)) return true;
  if (base >= 0x2600 && base <= 0x27BF) return true; // misc symbols, dingbats
  if (base >= 0x1F000 && base <= 0x1FAFF) return true; // emoji planes
  if (base >= 0x1F1E6 && base <= 0x1F1FF) return true; // regional indicators
  while (iterator.moveNext()) {
    final r = iterator.current;
    // A presentation selector or ZWJ means the cluster's rendering is
    // font-negotiated, which is exactly where implementations diverge.
    if (r == 0xFE0E || r == 0xFE0F || r == 0x200D) return true;
  }
  return false;
}