stringWidth function
Returns the total display width of text in terminal columns.
Implementation
int stringWidth(String text) {
int width = 0;
for (int i = 0; i < text.length; i++) {
final int cp = text.codeUnitAt(i);
if (cp < 32) continue;
if (cp < 127) {
width++;
continue;
}
width += charWidth(cp);
}
return width;
}