UNICODE_WCWIDTH(3)
π UNICODE_WCWIDTH(3) π
ok bestie, so this is a page from the Courier Unicode Library manual, and we're gonna talk about figuring out how wide stuff is when you print it to a terminal. because apparently characters don't all take up one lil slot like you'd think. rude, honestly. π¦
β¨ NAME β¨
unicode_wcwidth, unicode_wcwidth_str β the width of a Unicode character string, no cap π
πΈ SYNOPSIS πΈ
#include <courier-unicode.h>
int unicode_wcwidth(char32_t c);
size_t unicode_wcwidth_str(const char32_t *str);
π DESCRIPTION π
so unicode_wcwidth is the vibe-check function. you hand it one character, it tells you how much horizontal space that character eats up:
- returns
1for regular Unicode characters (the normal ones, the standard girlies) - returns
0for control characters (they take up zero space, they're literally not even visible, main character energy but invisible π) - returns
2for characters that normally take up the width of two regular characters on a text console (yeah, some of them are just Built Different and hog two slots) π
then there's unicode_wcwidth_str, the group-chat version. it adds up unicode_wcwidth of all the characters in the null-terminated string and returns the total. so like, the whole squad's width combined. periodt. β¨
π BUGS π
ok so here's the thing, and it's lowkey important β the width of a Unicode character is looked up in the Unicode database, and not your terminal's character set font. so it's not peeking at what your terminal is actually doing, it's trusting the database. hopefully your terminal's character set font is Unicide-compatible. π (that's what it says, bestie, i'm just the messenger)
ngl this is genuinely the kind of caveat that bites people. the function does not know what your font looks like. it knows what the database says. those can disagree and that's just the situation. π«Ά
π¦ SEE ALSO π¦
go read these too, they're all part of the same lil ecosystem:
courier-unicode(7)unicode_uc(3)unicode_convert(3)unicode_default_chset(3)unicode_html40ent_lookup(3)unicode_category_lookup(3)unicode_grapheme_break(3)unicode_word_break(3)unicode_line_break(3)
π AUTHOR π
Sam Varshavchik β Author π
that's the whole page, bestie!! go measure some characters, stay iconic, and remember: width 0 is still a valid width, we don't discriminate here. π
β this masterpiece was brought to you by the Courier Unicode Library, dated 04/12/2026, and yes the manual page section is still UNICODE_WCWIDTH(3). mwah. π
π
π¦ where this page comes from
- nixpkgs unstable: courier-unicode 2.6.0
- ubuntu stonking: libcourier-unicode-dev 2.6.0-2ubuntu1 Β· GPL-3.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms