threads / rfc / 13245

RFC patchMore colors for pretty format: yellow, purple, cyan, white and black

Subject: [PATCH/RFC] More colors for pretty format: yellow, purple, cyan, white and black

## tl;dr

2 messages between Apr 24, 2008 and Apr 25, 2008. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Tom ten Thij· Apr 24, 2008, 17:26 UTC · lore
Signed-off-by: Tom ten Thij <git@tomtenthij.nl>
---
Add support for other colors in pretty format the same way %Cred
works. I reordered the if
statements to start with the reset case and order the others by ansi
color code. Not sure if
I have to edit other files or how to do testing for a complete patch.
 Documentation/pretty-formats.txt |    5 +++++
 pretty.c                         |   21 ++++++++++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)
Show changes to 2 files +23 −3

Documentation/pretty-formats.txt, pretty.c

diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
index e8bea3e..c8631f8 100644
--- a/Documentation/pretty-formats.txt
+++ b/Documentation/pretty-formats.txt
@@ -120,6 +120,11 @@ The placeholders are:
 - '%Cred': switch color to red
 - '%Cgreen': switch color to green
 - '%Cblue': switch color to blue
+- '%Cyellow': switch color to yellow
+- '%Cpurple': switch color to purple
+- '%Ccyan': switch color to cyan
+- '%Cwhite': switch color to white
+- '%Cblack': switch color to black
 - '%Creset': reset color
 - '%m': left, right or boundary mark
 - '%n': newline
diff --git a/pretty.c b/pretty.c
index 6872932..b497008 100644
--- a/pretty.c
+++ b/pretty.c
@@ -471,17 +471,32 @@ static size_t format_commit_item(struct strbuf
*sb, const char *placeholder,
        /* these are independent of the commit */
        switch (placeholder[0]) {
        case 'C':
-               if (!prefixcmp(placeholder + 1, "red")) {
+               if (!prefixcmp(placeholder + 1, "reset")) {
+                       strbuf_addstr(sb, "\033[m");
+                       return 6;
+               } else if (!prefixcmp(placeholder + 1, "black")) {
+                       strbuf_addstr(sb, "\033[30m");
+                       return 6;
+               } else if (!prefixcmp(placeholder + 1, "red")) {
                        strbuf_addstr(sb, "\033[31m");
                        return 4;
                } else if (!prefixcmp(placeholder + 1, "green")) {
                        strbuf_addstr(sb, "\033[32m");
                        return 6;
+               } else if (!prefixcmp(placeholder + 1, "yellow")) {
+                       strbuf_addstr(sb, "\033[33m");
+                       return 7;
                } else if (!prefixcmp(placeholder + 1, "blue")) {
                        strbuf_addstr(sb, "\033[34m");
                        return 5;
-               } else if (!prefixcmp(placeholder + 1, "reset")) {
-                       strbuf_addstr(sb, "\033[m");
+               } else if (!prefixcmp(placeholder + 1, "purple")) {
+                       strbuf_addstr(sb, "\033[35m");
+                       return 7;
+               } else if (!prefixcmp(placeholder + 1, "cyan")) {
+                       strbuf_addstr(sb, "\033[36m");
+                       return 5;
+               } else if (!prefixcmp(placeholder + 1, "white")) {
+                       strbuf_addstr(sb, "\033[37m");
                        return 6;
                } else
                        return 0;
-- 
1.5.4.4
René Scharfe· Apr 25, 2008, 20:42 UTC · re: Tom ten Thij · lore

Re: [PATCH/RFC] More colors for pretty format: yellow, purple, cyan, white and black

Tom ten Thij schrieb:
> Add support for other colors in pretty format the same way %Cred
> works.

Hmm. Currently you can get the same effect by adding the escape codes to the format string directly. Arguably, --pretty=format should honour the config variable color.diff and the options --color and --no-color to make the colour placeholders useful (both your extended set and the current one).

René

← back to recent threads