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

Re: [RFC] Colorization of log --graph

From
Jeff King <peff@peff.net>
Date
Mar 20, 2009, 19:58 UTC
Message-ID
<20090320195806.GC26934@coredump.intra.peff.net>
In-Reply-To
<b2e43f8f0903201213o396de6c0sb52149ed1d889d1@mail.gmail.com>
On Fri, Mar 20, 2009 at 03:13:53PM -0400, Allan Caffee wrote:
Show 17 quoted lines
> /*
>  * Map names to ANSI escape sequences.  Consider putting this in color.c
>  * and providing color_name_get_ansi_code(enum color_name).
>  */
> const char* git_color_codes[] {
> 	GIT_COLOR_RESET,
> 	GIT_COLOR_BOLD,
> 	GIT_COLOR_RED,
> 	GIT_COLOR_GREEN,
> 	GIT_COLOR_YELLOW,
> 	GIT_COLOR_BLUE,
> 	GIT_COLOR_CYAN,
> 	GIT_COLOR_BG_RED,
> };
> 
> That conveniently offers clients access to both the raw escape codes and
> a clear type for storing/handling colors.

I want to point out one thing: an enum or a list like this is actually a subset of the useful color codes that git can represent. Actual configured colors can have attributes, foreground, and background colors. So they need to be stored in a character array.

Adding an enum for GIT_COLOR_RED and using it throughout the code can be helpful for simple cases, but it doesn't give you an easy way of saying "red background, blue foreground". Maybe that is enough for git internal usage, since we tend not to use backgrounds or attributes for defaults. But maybe it makes more sense to do this as:

  const char *ansi_color(enum color fg, enum color bg, enum attribute attr);

and return a pointer to a static array representing the color (and even cycle through a list the way sha1_to_hex or git_path does). And you could even use it to simplify and share code with the config color parsing in color.c.

-Peff
Previous: Allan CaffeeNext: Junio C Hamano
Message 7 of 24 in “[RFC] Colorization of log --graph”
  1. Allan CaffeeMar 18, 2009
  2. Johannes SchindelinMar 18, 2009
  3. Allan CaffeeMar 19, 2009
  4. Johannes SchindelinMar 19, 2009
  5. Nanako ShiraishiMar 19, 2009
  6. Allan CaffeeMar 20, 2009
  7. Jeff KingMar 20, 2009
  8. Junio C HamanoMar 20, 2009
  9. Eric RaibleMar 18, 2009
  10. Santi BéjarMar 18, 2009
  11. Eric RaibleMar 18, 2009
  12. Markus HeidelbergMar 19, 2009
  13. Eric RaibleMar 19, 2009
  14. Markus HeidelbergMar 19, 2009
  15. graph API: Added logic for colored edges.Allan Caffee, Mar 30, 2009
  16. Johannes SchindelinMar 30, 2009
  17. Johannes SchindelinMar 31, 2009
  18. Johannes SixtMar 31, 2009
  19. Johannes SchindelinMar 31, 2009
  20. Johannes SchindelinMar 31, 2009
  21. 1/2 graph.c: avoid compile warningsJohannes Schindelin, Mar 30, 2009
  22. Junio C HamanoMar 30, 2009
  23. Junio C HamanoMar 30, 2009
  24. 2/2 --graph: respect --no-colorJohannes Schindelin, Mar 30, 2009

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.