expand --pretty=format color options
Currently, the only colors available to --pretty=format users are red, green, and blue. Rather than expand it with a few new colors, this patch makes the usual config color syntax available, including more colors, backgrounds, and attributes. Because colors are no longer bounded to a single word (e.g., %Cred), this uses a more advanced syntax that features a beginning and end delimiter (but the old syntax still works). So you can now do: git log --pretty=tformat:'%C(yellow)%h%C(reset) %s' to emulate --pretty=oneline, or even git log --pretty=tformat:'%C(cyan magenta bold)%s%C(reset)' if you want to relive the awesomeness of 4-color CGA. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
5ef8d77a75
commit
c002922adc
12
pretty.c
12
pretty.c
@ -6,6 +6,7 @@
|
||||
#include "string-list.h"
|
||||
#include "mailmap.h"
|
||||
#include "log-tree.h"
|
||||
#include "color.h"
|
||||
|
||||
static char *user_format;
|
||||
|
||||
@ -554,6 +555,17 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
|
||||
/* these are independent of the commit */
|
||||
switch (placeholder[0]) {
|
||||
case 'C':
|
||||
if (placeholder[1] == '(') {
|
||||
const char *end = strchr(placeholder + 2, ')');
|
||||
char color[COLOR_MAXLEN];
|
||||
if (!end)
|
||||
return 0;
|
||||
color_parse_mem(placeholder + 2,
|
||||
end - (placeholder + 2),
|
||||
"--pretty format", color);
|
||||
strbuf_addstr(sb, color);
|
||||
return end - placeholder + 1;
|
||||
}
|
||||
if (!prefixcmp(placeholder + 1, "red")) {
|
||||
strbuf_addstr(sb, "\033[31m");
|
||||
return 4;
|
||||
|
Reference in New Issue
Block a user