Re: [RFC PATCH 1/3] usage: extract `prefix_suffix_lines()` from `advise()`

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, May 25, 2018 at 11:00:53PM +0200, Martin Ågren wrote:

> +/*
> + * 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:

> 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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux