Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c215cc7

Browse files
committed
Add color support for new frontend detail/hint messages
As before, the defaults are similar to gcc's default appearance.
1 parent dfd0f2b commit c215cc7

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

doc/src/sgml/color.sgml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@
7474
</listitem>
7575
</varlistentry>
7676

77+
<varlistentry>
78+
<term><literal>note</literal></term>
79+
<listitem>
80+
<para>used to highlight the text <quote>detail</quote> and
81+
<quote>hint</quote> in such messages</para>
82+
</listitem>
83+
</varlistentry>
84+
7785
<varlistentry>
7886
<term><literal>locus</literal></term>
7987
<listitem>
@@ -85,9 +93,11 @@
8593
</para>
8694

8795
<para>
88-
The default value is <literal>error=01;31:warning=01;35:locus=01</literal>
96+
The default value is
97+
<literal>error=01;31:warning=01;35:note=01;36:locus=01</literal>
8998
(<literal>01;31</literal> = bold red, <literal>01;35</literal> = bold
90-
magenta, <literal>01</literal> = bold default color).
99+
magenta, <literal>01;36</literal> = bold cyan, <literal>01</literal> = bold
100+
default color).
91101
</para>
92102

93103
<tip>

src/common/logging.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ static void (*log_locus_callback) (const char **, uint64 *);
2828

2929
static const char *sgr_error = NULL;
3030
static const char *sgr_warning = NULL;
31+
static const char *sgr_note = NULL;
3132
static const char *sgr_locus = NULL;
3233

3334
#define SGR_ERROR_DEFAULT "01;31"
3435
#define SGR_WARNING_DEFAULT "01;35"
36+
#define SGR_NOTE_DEFAULT "01;36"
3537
#define SGR_LOCUS_DEFAULT "01"
3638

3739
#define ANSI_ESCAPE_FMT "\x1b[%sm"
@@ -134,6 +136,8 @@ pg_logging_init(const char *argv0)
134136
sgr_error = strdup(value);
135137
if (strcmp(name, "warning") == 0)
136138
sgr_warning = strdup(value);
139+
if (strcmp(name, "note") == 0)
140+
sgr_note = strdup(value);
137141
if (strcmp(name, "locus") == 0)
138142
sgr_locus = strdup(value);
139143
}
@@ -146,6 +150,7 @@ pg_logging_init(const char *argv0)
146150
{
147151
sgr_error = SGR_ERROR_DEFAULT;
148152
sgr_warning = SGR_WARNING_DEFAULT;
153+
sgr_note = SGR_NOTE_DEFAULT;
149154
sgr_locus = SGR_LOCUS_DEFAULT;
150155
}
151156
}
@@ -281,10 +286,18 @@ pg_log_generic_v(enum pg_log_level level, enum pg_log_part part,
281286
}
282287
break;
283288
case PG_LOG_DETAIL:
289+
if (sgr_note)
290+
fprintf(stderr, ANSI_ESCAPE_FMT, sgr_note);
284291
fprintf(stderr, _("detail: "));
292+
if (sgr_note)
293+
fprintf(stderr, ANSI_ESCAPE_RESET);
285294
break;
286295
case PG_LOG_HINT:
296+
if (sgr_note)
297+
fprintf(stderr, ANSI_ESCAPE_FMT, sgr_note);
287298
fprintf(stderr, _("hint: "));
299+
if (sgr_note)
300+
fprintf(stderr, ANSI_ESCAPE_RESET);
288301
break;
289302
}
290303
}

0 commit comments

Comments
 (0)