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

Re: [PATCH] log: support 256 colors with --graph=256colors

From
Duy Nguyen <pclouds@gmail.com>
Date
Dec 22, 2016, 09:48 UTC
Message-ID
<CACsJy8CnS1=_vA5xhbZ94Qyh7ySC5FvaALu1vhQwt_YJya4wHA@mail.gmail.com>
In-Reply-To
<20161220165754.hkmnsxiwbcgn6uin@sigill.intra.peff.net>
On Tue, Dec 20, 2016 at 11:57 PM, Jeff King <peff@peff.net> wrote:
Show 38 quoted lines
> On Tue, Dec 20, 2016 at 07:39:29PM +0700, Nguyễn Thái Ngọc Duy wrote:
>
>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
>> ---
>>  I got mad after tracing two consecutive red history lines in `git log
>>  --graph --oneline` back to their merge points, far far away. Yeah
>>  probably should fire up tig, or gitk or something.
>>
>>  This may sound like a good thing to add, but I don't know how good it
>>  is compared to the good old 16 color palette, yet as I haven't tried it
>>  for long since it's just written.
>
> Hmm. At some point the colors become too close together to be easily
> distinguishable. In your code you have:
>
>> +     if (arg && !strcmp(arg, "256colors")) {
>> +             int i, start = 17, stop = 232;
>> +             column_colors_max = stop - start;
>> +             column_colors =
>> +                     xmalloc((column_colors_max + 1) * sizeof(*column_colors));
>> +             for (i = start; i < stop; i++) {
>> +                     struct strbuf sb = STRBUF_INIT;
>> +                     strbuf_addf(&sb, "\033[38;5;%dm", i);
>> +                     column_colors[i - start] = strbuf_detach(&sb, NULL);
>> +             }
>> +             column_colors[column_colors_max] = xstrdup(GIT_COLOR_RESET);
>> +             /* ignore the closet 16 colors on either side for the next line */
>> +             column_colors_step = 16;
>> +     }
>
> So you step by 16, over a set of 215 colors. That seems to give only 13
> colors, versus the original 16. :)
>
> I know that is a simplification. If you wrap around, then you get your
> 13 colors, and then another 13 colors that aren't _quite_ the same, and
> so on, until you've used all 256. I'm just not sure if the 1st and 14th
> color would be visually different enough for it to matter (I admit I
> didn't do any experiments, though).

Yep. If the jump sequence is a random one, we're less likely to run into this. But I think Junio's "run git-log in 2 terminals with the same coloring" convinces me randomization here is not the best thing.

The best solution would be select colors per text line, so we can pick different colors. But I think that's a lot of computation (and probably an NP problem too). The second best option is have a good, predefined color palette. We don't need a red of all shades, we need something that look distinct enough from the rest. I googled for this first and failed. But I think I could approach it a different way: collect colors that have names. That reduces the number of colors so we can go back to "step 1 at a time" and still don't run into two similar colors often.

Show 7 quoted lines
>> ---graph::
>> +--graph[=<options>]::
>>       Draw a text-based graphical representation of the commit history
>>       on the left hand side of the output.  This may cause extra lines
>>       to be printed in between commits, in order for the graph history
>
> I wonder if we would ever want another use for "--graph=foo"

I do. See the screenshot in [1] from the original mail. I have to stare at --graph so often lately that it might get my attention before other things.

> I guess any such thing could fall under the name of "graph options", and we'd
> end up with "--graph=256colors,unicode" or something like that.
Exactly.
> I do suspect people would want a config option for this, though. I.e.,
> you'd want to enable it all the time if you have a terminal which can
> handle 256 colors, not just for a particular invocation.

Yeah. That also means we need the ability to override/negate config options, perhaps something like --graph=-256colors.

-- 
Duy
Previous: Jeff KingNext: Junio C Hamano
Message 3 of 30 in “log: support 256 colors with --graph=256colors”
  1. log: support 256 colors with --graph=256colorsNguyễn Thái Ngọc Duy, Dec 20, 2016
  2. Jeff KingDec 20, 2016
  3. Duy NguyenDec 22, 2016
  4. Junio C HamanoDec 22, 2016
  5. Duy NguyenDec 25, 2016
  6. Junio C HamanoDec 20, 2016
  7. Duy NguyenDec 22, 2016
  8. log --graph: customize the graph lines with config log.graphColorsNguyễn Thái Ngọc Duy, Dec 24, 2016
  9. Junio C HamanoDec 25, 2016
  10. log --graph: customize the graph lines with config log.graphColorsNguyễn Thái Ngọc Duy, Jan 8, 2017
  11. Junio C HamanoJan 9, 2017
  12. Jeff KingJan 9, 2017
  13. Duy NguyenJan 9, 2017
  14. Junio C HamanoJan 9, 2017
  15. Jeff KingJan 9, 2017
  16. Duy NguyenJan 9, 2017
  17. log --graph: customize the graph lines with config log.graphColorsNguyễn Thái Ngọc Duy, Jan 9, 2017
  18. Junio C HamanoJan 9, 2017
  19. Duy NguyenJan 12, 2017
  20. 0/3 nd/log-graph-configurable-colorsNguyễn Thái Ngọc Duy, Jan 19, 2017
  21. 1/3 color.c: fix color_parse_mem() with value_len == 0Nguyễn Thái Ngọc Duy, Jan 19, 2017
  22. Jeff KingJan 19, 2017
  23. Jeff KingJan 28, 2017
  24. 2/3 color.c: trim leading spaces in color_parse_mem()Nguyễn Thái Ngọc Duy, Jan 19, 2017
  25. Jeff KingJan 19, 2017
  26. Junio C HamanoJan 19, 2017
  27. 3/3 log --graph: customize the graph lines with config log.graphColorsNguyễn Thái Ngọc Duy, Jan 19, 2017
  28. Jeff KingJan 19, 2017
  29. Junio C HamanoJan 19, 2017
  30. Junio C HamanoJan 19, 2017

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.