text...idth(3tcl)
π textutil::wcswidth β the manual, but make it make sense π
okay bestie, welcome to textutil::wcswidth, section 3tcl of the Tcllib docs, filed under Text and string utilities, macro processing. no cap, it's a whole vibe. let's get into it π«Ά
β¨ NAME β¨
textutil::wcswidth β Procedures to compute terminal width of strings π
πΈ SYNOPSIS πΈ
package require Tcl 8.5 9
package require textutil::wcswidth ?35.3?
::textutil::wcswidth string
::textutil::wcswidth_char char
::textutil::wcswidth_type char
π¦ DESCRIPTION π¦
so the textutil::wcswidth package hands you commands that figure out character type and width for terminals, plus the length of strings when they get printed in a terminal. it's giving "how many little boxes is this gonna eat up on your screen" energy π
the data behind all of this comes from the Unicode database file, specifically http://www.unicode.org/Public/UCD/latest/ucd/EastAsianWidth.txt. that's the source of truth, periodt.
and here's the complete set of procedures, described below π
::textutil::wcswidthstring β returns how many character cells the string takes up when it gets printed to the terminal. and yes, it counts the double-wide characters from the various Asian and other scripts too, because it's thorough like that β¨::textutil::wcswidth_charchar β returns how many character cells that one char takes up when printed to the terminal.
β οΈ bestie beware: char is specified as a Unicode codepoint.
::textutil::wcswidth_typechar β returns the character type of the character you gave it. it's a single character from the setA,F,H,N,Na, andW, exactly as specified over at http://www.unicode.org/Public/UCD/latest/ucd/EastAsianWidth.txt. iykyk π«
β οΈ also beware (again!): char here is specified as a Unicode codepoint.
π BUGS, IDEAS, FEEDBACK π
ngl, this document and the package it describes will undoubtedly contain bugs and other problems. like, for sure. so please report them in the textutil category of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. and if you've got ideas for enhancements for either the package and/or the documentation, send those over too, we want them fr fr π
when you're proposing code changes, please provide unified diffs, i.e. the output of diff -u. that's the move.
also note: attachments are strongly preferred over inlined patches. to attach one, go to the Edit form of the ticket right after you create it, then use the left-most button in the secondary navigation bar. iconic workflow, lowkey π
π SEE ALSO π
regexp(3tcl), split(3tcl), string(3tcl)
π₯ KEYWORDS π₯
character type, character width, double-wide character, prefix, regular expression, string
π CATEGORY π
Text processing
okay that's the whole page bestie, go compute some widths and slay πβ¨π¦
signing off with love from the tcllib girlies β this is version 35.3, and it's a whole main character moment. mwah ππ
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms