]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mbsalign: add support for SCS escape sequences
authorWanBingjiang <wanbingjiang@webray.com.cn>
Tue, 17 Mar 2026 02:17:15 +0000 (10:17 +0800)
committerWanBingjiang <wanbingjiang@webray.com.cn>
Tue, 17 Mar 2026 02:32:53 +0000 (10:32 +0800)
Add handling for SCS (Select Character Set) escape sequences:
\e(X, \e)X, \e*X, \e+X. These sequences are now properly skipped
when calculating string width.

Addresses: https://github.com/util-linux/util-linux/issues/4121
Signed-off-by: WanBingjiang <wanbingjiang@webray.com.cn>
lib/mbsalign.c

index f94866b8b6a86d85c995ffc8bb1f796cdaf0187c..97627537f80cd969158d933c70f7a73a059bad6a 100644 (file)
@@ -53,6 +53,12 @@ size_t mbs_nwidth(const char *buf, size_t bufsz)
                                if (*e == 'm')
                                        p = e + 1;
                        }
+                       /* try detect SCS sequences "\e(X", "\e)X", "\e*X", "\e+X" and skip on success */
+                       else if (*p && (*p == '(' || *p == ')' || *p == '*' || *p == '+')) {
+                               p++;  /* skip the SCS introducer */
+                               if (p <= last)
+                                       p++;  /* skip the character */
+                       }
                        continue;
                }
 #ifdef HAVE_WIDECHAR