Eyal Soha <shawarmakarma@xxxxxxxxx> writes: > @@ -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. > 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. > 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.