textu...width(n)
π NAME π
textutil::wcswidth β procs that figure out how wide your strings actually are when they hit a terminal, bestie π«Ά
So like, you know how some characters take up one little cell and others are these big double-wide icons from Asian scripts and stuff? Yeah. This package is the vibe check for that. It tells you character type, character width, and how long a whole string is when it's printed to the terminal. β¨
πΈ 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 π¦
Okay so the textutil::wcswidth package gives you commands that determine character type and width when used in terminals, plus the length of strings when they're printed in a terminal. It's giving "finally, alignment that isn't a mess." π
The data underlying all of this comes from the Unicode database file:
http://www.unicode.org/Public/UCD/latest/ucd/EastAsianWidth.txt
The complete set of procedures is described below, queen. π
::textutil::wcswidth stringβ Returns the number of character cells taken by the string when printed to the terminal. It takes double-wide characters from the various Asian and other scripts into account. So yes, your CJK text gets counted correctly, no cap. π₯::textutil::wcswidth_char charβ Returns the number of character cells taken by the character when printed to the terminal.
β οΈ Beware: the character char is specified as a Unicode codepoint. Not a glyph, not a string β a codepoint. Don't come for me, I'm just the messenger. π
::textutil::wcswidth_type charβ Returns the character type of the specified character. This is a single character in the set ofA,F,H,N,Na, andW, exactly as specified per:
http://www.unicode.org/Public/UCD/latest/ucd/EastAsianWidth.txt
β οΈ Beware: the character char is specified as a Unicode codepoint here too, bestie. Same energy, same rule. π
π BUGS, IDEAS, FEEDBACK π
Real talk: this document, and the package it describes, will undoubtedly contain bugs and other problems. Not me being dramatic, it literally says so. π
Please report such in the category textutil of the Tcllib Trackers:
http://core.tcl.tk/tcllib/reportlist
Also please report any ideas for enhancements you may have for either the package and/or the documentation. We love a glow-up suggestion. π
When proposing code changes, please provide unified diffs, i.e. the output of diff -u.
Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button</left-most> in the secondary navigation bar. It's iconic, trust. π
π SEE ALSO π
β KEYWORDS β
character type, character width, double-wide character, prefix, regular expression, string
π§ CATEGORY π§
Text processing
That's the whole page, bestie β slay, you read all of it. π This one's from tcllib, version 35.3, and yeah it lives in section n of the manual, which is why the header up top is all textu...width(n) and the footer whispers the same thing back at you. Periodt. π
β¨
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms