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::wcswidth string β€” 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_char char β€” returns how many character cells that one char takes up when printed to the terminal.
⚠️ bestie beware: char is specified as a Unicode codepoint.
⚠️ 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