Skip to content

Modern Tui TuiStringWidth

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Terminal TUI Library › Unicode Width › TuiStringWidth

TuiStringWidth

Counts the columns a string takes on screen, wide characters as two.

Syntax

TuiStringWidth( byref s as ustring ) as int32

Description

Columns for a whole string. Use this and never LEN when deciding whether text fits -- LEN counts UTF-16 code units, which is neither characters nor columns. WHAT THIS DOES NOT DO: there is no UAX-29 clustering, so an emoji ZWJ sequence measures as the sum of its parts and will overrun a box.

Example

#import "std/tui"
using tui

print TuiStringWidth( "hello" )                    '' 5
print TuiStringWidth( wchr( &h4E2D ) & "x" )       '' 3 -- 2 + 1
print TuiStringWidth( "e" & wchr( &h0301 ) )       '' 1 -- the mark is free

See also

TuiCharWidth · TuiTruncate · TuiWrap · TuiSetAmbiguousWide · TuiAmbiguousWide


Library: Terminal TUI Library
Category: Terminal TUI Library
Documented under: Unicode Width
Working examples: hello.tiko · form.tiko · dashboard.tiko


Home · Keyword Index

Clone this wiki locally