From: Junio C Hamano Date: Tue, 28 Feb 2012 18:22:54 GMT Subject: Re: [PATCH v7 03/10] column: add columnar layout Message-ID: <7vy5rmzukh.fsf@alter.siamese.dyndns.org> In-Reply-To: <1330430331-19945-4-git-send-email-pclouds@gmail.com> Nguyễn Thái Ngọc Duy writes: > COL_MODE_COLUMN and COL_MODE_ROW fill column by column (or row by row > respectively), given the terminal width and how many space between > columns. > > Strings are supposed to be in UTF-8. If strings contain ANSI escape > strings, COL_ANSI must be specified for correct length calculation. Hrm, is it too heavyweight to autodetect and relieve the caller from the burden of passing COL_ANSI? Perhaps if you update utf8_strwidth() so that it takes input not NUL terminated string, you can do item_length like this, no? cp = s; width = 0; while (1) { ep = strstr(cp, "\033["); if (!ep) { width += utf8_strwidth(cp); break; } utf8_strwidth_counted(cp, ep - cp); ... scan ep to skip the "\033[...;X" cp = ep; }