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

Re: Fwd: Add support for axiterm colors in parse_color

From
Eyal Soha <shawarmakarma@gmail.com>
Date
Jan 15, 2020, 15:32 UTC
Message-ID
<CANsz78Kh3YUPfbea6=oCRJf6PC5RMLihTmpX0SPZdhTKuo-D5w@mail.gmail.com>
In-Reply-To
<CANsz78Knt4RKGzNj4W3j7G9rh8N8jtCsOgOa_jTU-NetpgvVGA@mail.gmail.com>
I sent out my patches.  Can someone take a look?
Thanks,
Eyal
On Fri, Jan 10, 2020 at 10:02 AM Eyal Soha <shawarmakarma@gmail.com> wrote:
Show 133 quoted lines
>
> Thanks.  I think that 3 patches are in order.  The first will refactor
> and add the enums.  The second will add the aixterm colors.  The last
> will alias RGB 8-15 to aixterm colors.
>
> What's the correct way to email those patches?  I will try with
> git-send-email.  BTW, is "git help send-email" supposed to work?
>
> Eyal
> On Fri, Jan 10, 2020 at 6:15 AM Jeff King <peff@peff.net> wrote:
> >
> > On Thu, Jan 09, 2020 at 07:20:09PM -0500, Eyal Soha wrote:
> >
> > > > That said, I'm not entirely opposed to having more human-readable
> > > > aliases. I'm not sure if it's worth using the 16-color version (e.g.,
> > > > "ESC[91m" versus the 256-color version "ESC[38;5;9m"). It's possible it
> > > > would be compatible with more terminals, and it is slightly fewer bytes.
> > >
> > > My motivation for this patch was to fix the github workflow log output
> > > that doesn't support 8bit colors properly.  Only the "ANSI" colors
> > > 0-15 worked.  None of the 8-bit colors worked except for 30-37, 40-47,
> > > 90-97, and 100-107, which matched the ANSI colors.  That is a very
> > > broken color scheme!  But that's how it displayed.
> >
> > That makes sense. I'm not too surprised to see a terminal that supports
> > one but not the other.
> >
> > But I wonder if there are ones that go the other way around: supporting
> > 256-color mode but not ANSI 90-97, etc. I doubt it, but I think it would
> > be nice to split that change out into a separate commit in case we do
> > run into problems.
> >
> > > Done.  Here's a new patch!
> >
> > Thanks. The content here is looking pretty good (though I have a few
> > comments below).
> >
> > Can you also format it as described in Documentation/SubmittingPatches
> > and re-send? In particular, it needs a regular commit message and your
> > signoff.
> >
> > > +enum {
> > > +       COLOR_BACKGROUND_OFFSET = 10,
> > > +       COLOR_FOREGROUND_ANSI = 30,
> > > +       COLOR_FOREGROUND_RGB = 38,
> > > +       COLOR_FOREGROUND_256 = 38,
> > > +       COLOR_FOREGROUND_BRIGHT_ANSI = 90,
> > > +};
> >
> > The split in this enum mostly makes sense to me. It changes the meaning
> > of "value" for COLOR_ANSI, but this is all local to color.c, so your
> > changes to output_color() are all that's needed.
> >
> > It might be easier to follow the patch if switching to this enum came in
> > a separate preparatory patch.
> >
> > > @@ -92,7 +100,13 @@ static int parse_color(struct color *out, const
> > > char *name, int len)
> > >         for (i = 0; i < ARRAY_SIZE(color_names); i++) {
> > >                 if (match_word(name, len, color_names[i])) {
> > >                         out->type = COLOR_ANSI;
> > > -                       out->value = i;
> > > +                       out->value = i + COLOR_FOREGROUND_ANSI;
> > > +                       return 0;
> > > +               }
> > > +               if (*name == '+' &&
> > > +                   match_word(name+1, len-1, color_names[i])) {
> > > +                       out->type = COLOR_ANSI;
> > > +                       out->value = i + COLOR_FOREGROUND_BRIGHT_ANSI;
> > >                         return 0;
> > >                 }
> >
> > It would be slightly simpler and more efficient handle the "+" outside
> > the loop, like:
> >
> >   int offset = COLOR_FOREGROUND_ANSI;
> >   if (*name == '+') {
> >           offset = COLOR_FOREGROUND_BRIGHT_ANSI;
> >           name++;
> >           len--;
> >   }
> >
> > and then in the loop just set "out->value = i + offset".
> >
> > You'd probably want to hoist this out to a separate function since
> > "name" needs to be unchanged in the later part of the function.
> >
> > I dunno. It's almost certainly an unmeasurable micro-optimization, but
> > somehow the flow of it seems simpler to me.
> >
> > I also wondered if we'd want English aliases like "brightred" that some
> > other systems use. It would be easy to add that to the check I showed
> > above without having to repeat as much.
> >
> > > @@ -109,10 +123,15 @@ static int parse_color(struct color *out, const
> > > char *name, int len)
> > >                 else if (val < 0) {
> > >                         out->type = COLOR_NORMAL;
> > >                         return 0;
> > > -               /* Rewrite low numbers as more-portable standard colors. */
> > > +               /* Rewrite 0-7 as more-portable standard colors. */
> > >                 } else if (val < 8) {
> > >                         out->type = COLOR_ANSI;
> > > -                       out->value = val;
> > > +                       out->value = val + COLOR_FOREGROUND_ANSI;
> > > +                       return 0;
> > > +               /* Rewrite 8-15 as more-portable aixterm colors. */
> > > +               } else if (val < 16) {
> > > +                       out->type = COLOR_ANSI;
> > > +                       out->value = val - 8 + COLOR_FOREGROUND_BRIGHT_ANSI;
> >
> > And I think this 8-15 handling might want to be a separate commit on
> > top, just because it's possible it might regress some cases (though
> > again, I do doubt it).
> >
> > >         case COLOR_256:
> > > -               out += xsnprintf(out, len, "%c8;5;%d", type, c->value);
> > > +         out += xsnprintf(out, len, "%d;5;%d", COLOR_FOREGROUND_256 + offset,
> > > +                          c->value);
> >
> > Looks like some unwanted tab/space conversion (here and elsewhere).
> >
> > > +test_expect_success 'axiterm bright fg color' '
> > > +       color "+red" "[91m"
> >
> > s/axi/aix/ (here and below).
> >
> > > +test_expect_success '8-15 are aliases for aixterm color names' '
> > > +       color "12 13" "[94;105m"
> >
> > Makes sense.
> >
> > -Peff
Previous: Eyal SohaNext: Eyal Soha
Message 6 of 37 in “Fwd: Add support for axiterm colors in parse_color”
  1. Eyal SohaJan 7, 2020
  2. Jeff KingJan 8, 2020
  3. Eyal SohaJan 10, 2020
  4. Jeff KingJan 10, 2020
  5. Eyal SohaJan 10, 2020
  6. Eyal SohaJan 15, 2020
  7. 1/3 color.c: Refactor color_output to use enumsEyal Soha, Jan 10, 2020
  8. 2/3 color.c: Support bright aixterm colorsEyal Soha, Jan 10, 2020
  9. Jeff KingJan 15, 2020
  10. 3/3 color.c: Alias RGB colors 8-15 to aixterm colorsEyal Soha, Jan 10, 2020
  11. Jeff KingJan 15, 2020
  12. Jeff KingJan 15, 2020
  13. Junio C HamanoJan 16, 2020
  14. Jeff KingJan 16, 2020
  15. Eyal SohaJan 16, 2020
  16. 1/3 color.c: Refactor color_output to use enumsEyal Soha, Jan 18, 2020
  17. 2/3 color.c: Support bright aixterm colorsEyal Soha, Jan 18, 2020
  18. Junio C HamanoJan 18, 2020
  19. Eyal SohaJan 21, 2020
  20. 1/3 color.c: refactor color_output argumentsEyal Soha, Jan 21, 2020
  21. 2/3 color.c: support bright aixterm colorsEyal Soha, Jan 21, 2020
  22. Junio C HamanoJan 23, 2020
  23. 3/3 color.c: alias RGB colors 8-15 to aixterm colorsEyal Soha, Jan 21, 2020
  24. Junio C HamanoJan 23, 2020
  25. 0/3 es/bright-colors (hopefully final) rerollJunio C Hamano, Feb 11, 2020
  26. 2/3 color.c: support bright aixterm colorsJunio C Hamano, Feb 11, 2020
  27. 3/3 color.c: alias RGB colors 8-15 to aixterm colorsJunio C Hamano, Feb 11, 2020
  28. 1/3 color.c: refactor color_output argumentsJunio C Hamano, Feb 11, 2020
  29. Jeff KingFeb 11, 2020
  30. Eyal SohaFeb 11, 2020
  31. Junio C HamanoFeb 11, 2020
  32. Junio C HamanoJan 21, 2020
  33. 3/3 color.c: Alias RGB colors 8-15 to aixterm colorsEyal Soha, Jan 18, 2020
  34. Junio C HamanoJan 18, 2020
  35. Junio C HamanoJan 18, 2020
  36. Eyal SohaJan 21, 2020
  37. Junio C HamanoJan 21, 2020

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.