Make the `color` atom a pseudo atom and ensure that it uses `ref_formatting_state`. --- ref-filter.c | 19 ++++++++++++++++++- ref-filter.h | 4 +++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index a3625e8..cc25c85 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -662,6 +662,8 @@ static void populate_value(struct ref_array_item *ref) if (color_parse(name + 6, color) < 0) die(_("unable to parse format")); v->s = xstrdup(color); + v->pseudo_atom = 1; + v->color = 1; continue; } else if (!strcmp(name, "flag")) { char buf[256], *cp = buf; @@ -1195,6 +1197,11 @@ void ref_array_sort(struct ref_sorting *sorting, struct ref_array *array) static void ref_formatting(struct ref_formatting_state *state, struct atom_value *v, struct strbuf *value) { + if (state->color) { + strbuf_addstr(value, state->color); + free(state->color); + state->color = NULL; + } strbuf_addf(value, "%s", v->s); } @@ -1266,6 +1273,13 @@ static void emit(const char *cp, const char *ep) } } +static void apply_pseudo_state(struct ref_formatting_state *state, + struct atom_value *v) +{ + if (v->color) + state->color = (char *)v->s; +} + void show_ref_array_item(struct ref_array_item *info, const char *format, int quote_style) { const char *cp, *sp, *ep; @@ -1281,7 +1295,10 @@ void show_ref_array_item(struct ref_array_item *info, const char *format, int qu if (cp < sp) emit(cp, sp); get_ref_atom_value(info, parse_ref_filter_atom(sp + 2, ep), &atomv); - print_value(&state, atomv); + if (atomv->pseudo_atom) + apply_pseudo_state(&state, atomv); + else + print_value(&state, atomv); } if (*cp) { sp = cp + strlen(cp); diff --git a/ref-filter.h b/ref-filter.h index f24e3ef..7687879 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -19,11 +19,13 @@ struct atom_value { const char *s; unsigned long ul; /* used for sorting when not FIELD_STR */ - unsigned int pseudo_atom : 1; /* atoms which aren't placeholders for ref attributes */ + unsigned int pseudo_atom : 1, /* atoms which aren't placeholders for ref attributes */ + color : 1; }; struct ref_formatting_state { int quote_style; + char *color; }; struct ref_sorting { -- 2.4.6 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html