textu...width(n)

πŸ“¦ version 2.0, in fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

πŸ’– 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 of A, F, H, N, Na, and W, 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