Thread (9 messages) flat view 9 messages, 4 authors, 2018-05-29

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

From: Jeff King <hidden>
Date: 2018-05-29 21:40:02

Possibly related (same subject, not in this thread)

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:
quoted hunk ↗ jump to hunk
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help