summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut2022-04-11 15:36:44 +0000
committerPeter Eisentraut2022-04-11 15:36:44 +0000
commitc215cc7b61cbe06425c8ea3ac9d49581e6b5c6cd (patch)
treec0cc13b40f5b69a2f7775d5e24645d39a6a7b4ee
parentdfd0f2bbc5776f261ef4c8ab128469ef9091dcfe (diff)
Add color support for new frontend detail/hint messages
As before, the defaults are similar to gcc's default appearance.
-rw-r--r--doc/src/sgml/color.sgml14
-rw-r--r--src/common/logging.c13
2 files changed, 25 insertions, 2 deletions
diff --git a/doc/src/sgml/color.sgml b/doc/src/sgml/color.sgml
index a01a0c778f..5b782f7cc2 100644
--- a/doc/src/sgml/color.sgml
+++ b/doc/src/sgml/color.sgml
@@ -75,6 +75,14 @@
</varlistentry>
<varlistentry>
+ <term><literal>note</literal></term>
+ <listitem>
+ <para>used to highlight the text <quote>detail</quote> and
+ <quote>hint</quote> in such messages</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><literal>locus</literal></term>
<listitem>
<para>used to highlight location information (e.g., program name and
@@ -85,9 +93,11 @@
</para>
<para>
- The default value is <literal>error=01;31:warning=01;35:locus=01</literal>
+ The default value is
+ <literal>error=01;31:warning=01;35:note=01;36:locus=01</literal>
(<literal>01;31</literal> = bold red, <literal>01;35</literal> = bold
- magenta, <literal>01</literal> = bold default color).
+ magenta, <literal>01;36</literal> = bold cyan, <literal>01</literal> = bold
+ default color).
</para>
<tip>
diff --git a/src/common/logging.c b/src/common/logging.c
index 18d6669f27..2933cab85c 100644
--- a/src/common/logging.c
+++ b/src/common/logging.c
@@ -28,10 +28,12 @@ static void (*log_locus_callback) (const char **, uint64 *);
static const char *sgr_error = NULL;
static const char *sgr_warning = NULL;
+static const char *sgr_note = NULL;
static const char *sgr_locus = NULL;
#define SGR_ERROR_DEFAULT "01;31"
#define SGR_WARNING_DEFAULT "01;35"
+#define SGR_NOTE_DEFAULT "01;36"
#define SGR_LOCUS_DEFAULT "01"
#define ANSI_ESCAPE_FMT "\x1b[%sm"
@@ -134,6 +136,8 @@ pg_logging_init(const char *argv0)
sgr_error = strdup(value);
if (strcmp(name, "warning") == 0)
sgr_warning = strdup(value);
+ if (strcmp(name, "note") == 0)
+ sgr_note = strdup(value);
if (strcmp(name, "locus") == 0)
sgr_locus = strdup(value);
}
@@ -146,6 +150,7 @@ pg_logging_init(const char *argv0)
{
sgr_error = SGR_ERROR_DEFAULT;
sgr_warning = SGR_WARNING_DEFAULT;
+ sgr_note = SGR_NOTE_DEFAULT;
sgr_locus = SGR_LOCUS_DEFAULT;
}
}
@@ -281,10 +286,18 @@ pg_log_generic_v(enum pg_log_level level, enum pg_log_part part,
}
break;
case PG_LOG_DETAIL:
+ if (sgr_note)
+ fprintf(stderr, ANSI_ESCAPE_FMT, sgr_note);
fprintf(stderr, _("detail: "));
+ if (sgr_note)
+ fprintf(stderr, ANSI_ESCAPE_RESET);
break;
case PG_LOG_HINT:
+ if (sgr_note)
+ fprintf(stderr, ANSI_ESCAPE_FMT, sgr_note);
fprintf(stderr, _("hint: "));
+ if (sgr_note)
+ fprintf(stderr, ANSI_ESCAPE_RESET);
break;
}
}