git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] utf8: add display_mode_esc_sequence_len_counted()

From
Andy Koppe <andy.koppe@gmail.com>
Date
Nov 18, 2026, 09:48 UTC
Message-ID
<CAHWeT-Yh8yTnG7rLjvO+XBtU=bZHJ3WWoQQsPfvJO013P2GSPA@mail.gmail.com>
In-Reply-To
<ghwlqak2j9.fsf@gouders.net>
Dirk Gouders <wrote:
Show 33 quoted lines
>
> On Wed, Nov 18 2026, Andy Koppe wrote:
>
> > Junio C Hamano wrote:
> >>
> >> Andy Koppe <andy.koppe@gmail.com> writes:
> >>
> >> > Junio C Hamano wrote:
> >> >
> >> >> -       while (isdigit(*p) || *p == ';')
> >> >> +       while (p < end && (isdigit(*p) || *p == ';'))
> >> >
> >> > While you're there, could you add colons (':') to that?
> >>
> >> Do we generate such a sequence that uses subseparators?
> >>
> >> IIRC, this code is not counting the display width of end-user
> >> supplied string.  Rather, it gets string we paint in a buffer and
> >> then counts how much display column it occupies.
> >
> > You're right that Git itself doesn't generate them (although future
> > enhancements might change that).
> >
> > However, display_mode_esc_sequence_len() already operates on expanded
> > custom formats and message text, e.g. in rewrap_message_tail() via
> > strbuf_wrap(). And on stdin in git-column. They could all contain SGR
> > sequences with colons, whose width currently isn't ignored as
> > intended. (And my proposed make_line_colors_self_contained() wouldn't
> > reset or replay them.)
> >
> > The check could be changed to `*p >= '0' && *p<=';'` to cheaply include colons.
>
> I would suggest to not mix these changes simply for bisection purposes.

Fair, and there's testing work as well of course. It was silly of me to suggest just sneaking that change in.

> And as far as I know, we would need an FSM to identify valid sequences
> if we are going to allow colons.

No. The parameter field can be any mix of digits, colons and semicolons. Semicolons separate parameters, colons separate subparameters, and individual (sub)parameters can be empty, which is equivalent to zero. If the field consists of nothing but colons, that's one parameter with multiple empty subparameters.

Whether any particular SGR sequence means anything to a terminal is another matter of course, but git doesn't try to determine that for colon-less sequences either, and nor should it. Well-behaved terminals ignore valid sequences they don't understand.

Andy
Previous: Dirk GoudersNext: Dirk Gouders
Message 12 of 15 in “utf8: make display_mode_esc_sequence_len() take a length”
  1. utf8: make display_mode_esc_sequence_len() take a lengthJunio C Hamano, Nov 17, 2026
  2. utf8: add display_mode_esc_sequence_len_counted()Junio C Hamano, Nov 17, 2026
  3. Dirk GoudersNov 17, 2026
  4. Junio C HamanoNov 17, 2026
  5. Dirk GoudersNov 17, 2026
  6. Junio C HamanoNov 18, 2026
  7. Dirk GoudersNov 18, 2026
  8. Andy KoppeNov 17, 2026
  9. Junio C HamanoNov 17, 2026
  10. Andy KoppeNov 18, 2026
  11. Dirk GoudersNov 18, 2026
  12. Andy KoppeNov 18, 2026
  13. Dirk GoudersNov 18, 2026
  14. Andy KoppeNov 18, 2026
  15. Dirk GoudersNov 18, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.