Re: [PATCH 1/3] color.c: refactor color_output arguments
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 23, 2020, 22:50 UTC
- Message-ID
- <xmqqsgk53hyr.fsf@gitster-ct.c.googlers.com>
- In-Reply-To
- <20200121165623.151880-1-shawarmakarma@gmail.com>
Eyal Soha <shawarmakarma@gmail.com> writes:
Show 8 quoted lines
> @@ -166,23 +173,26 @@ int color_parse(const char *value, char *dst)
> * already have the ANSI escape code in it. "out" should have enough
> * space in it to fit any color.
> */
> -static char *color_output(char *out, int len, const struct color *c, char type)
> +static char *color_output(char *out, int len, const struct color *c, int background)
> {
> + int offset = 0;Have a blank line here, between the end of decl/defn and the first stmt.
> + if (background) {
> + offset = COLOR_BACKGROUND_OFFSET;
> + }No {} around a single statement block.Show 15 quoted lines
> switch (c->type) {
> case COLOR_UNSPECIFIED:
> case COLOR_NORMAL:
> break;
> case COLOR_ANSI:
> - if (len < 2)
> - BUG("color parsing ran out of space");
> - *out++ = type;
> - *out++ = '0' + c->value;
> + out += xsnprintf(out, len, "%d", c->value + offset);
> break;
> case COLOR_256:
> - out += xsnprintf(out, len, "%c8;5;%d", type, c->value);
> + out += xsnprintf(out, len, "%d;5;%d", COLOR_FOREGROUND_256 + offset,
> + c->value);Break the line after the format string instead, i.e.
> + out += xsnprintf(out, len, "%d;5;%d", > + COLOR_FOREGROUND_256 + offset, c->value);
that would make it easier to see which parameter corresponds to which placeholder and also saves line width at the same time.
Show 6 quoted lines
> break; > case COLOR_RGB: > - out += xsnprintf(out, len, "%c8;2;%d;%d;%d", type, > + out += xsnprintf(out, len, "%d;2;%d;%d;%d", > + COLOR_FOREGROUND_RGB + offset, > c->red, c->green, c->blue);
... like you did here.