Re: [RFC PATCH 1/3] usage: extract `prefix_suffix_lines()` from `advise()`
- From
Jeff King <peff@peff.net>
- Date
- May 29, 2018, 21:39 UTC
- Message-ID
- <20180529213957.GF7964@sigill.intra.peff.net>
- In-Reply-To
- <90ac0a41563f070a840076521d8935ad7c21beb9.1527279322.git.martin.agren@gmail.com>
On Fri, May 25, 2018 at 11:00:53PM +0200, Martin Ågren wrote:
Show 6 quoted lines
> +/* > + * Write the message to the file, prefixing and suffixing > + * each line with `prefix` resp. `suffix`. > + */ > +void prefix_suffix_lines(FILE *f, const char *prefix, > + const char *message, const char *suffix);
Should this perhaps learn about colors, too?
That would save us from having to allocate here:
Show 15 quoted lines
> diff --git a/advice.c b/advice.c
> index 370a56d054..ffb29e7ef4 100644
> --- a/advice.c
> +++ b/advice.c
> @@ -79,24 +79,22 @@ static struct {
>
> void advise(const char *advice, ...)
> {
> + struct strbuf prefix = STRBUF_INIT;
> struct strbuf buf = STRBUF_INIT;
> va_list params;
> - const char *cp, *np;
> +
> + strbuf_addf(&prefix, _("%shint: "),
> + advise_get_color(ADVICE_COLOR_HINT));But most importantly, it means we could eventually colorize errors, too, where we are not allowed to allocate.
So perhaps:
void report_lines(FILE *out,
const char *color, const char *color_reset,
const char *prefix, const char *msg);or something?
-Peff