mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-12 22:03:02 +00:00
cex: don't display twice unifying examples if there is no color
It makes no sense, and is actually confusing, to display twice the same example with no visible difference. * src/complain.h, src/complain.c (is_styled): New. * src/counterexample.c (print_counterexample): Display the unified example a second time only if it makes a difference. * tests/conflicts.at, tests/counterexample.at, tests/report.at: Adjust. * tests/diagnostics.at: Make sure we do display the unifying examples twice when colors are enabled. And check those colors.
This commit is contained in:
@@ -104,6 +104,23 @@ flush (FILE *out)
|
||||
fflush (out);
|
||||
}
|
||||
|
||||
bool
|
||||
is_styled (FILE *out)
|
||||
{
|
||||
if (out != stderr)
|
||||
return false;
|
||||
if (color_debug)
|
||||
return true;
|
||||
#if HAVE_LIBTEXTSTYLE
|
||||
return (color_mode == color_yes
|
||||
|| color_mode == color_html
|
||||
|| (color_mode == color_tty && isatty (STDERR_FILENO)));
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*------------------------.
|
||||
| --warnings's handling. |
|
||||
`------------------------*/
|
||||
@@ -288,9 +305,7 @@ void
|
||||
complain_init_color (void)
|
||||
{
|
||||
#if HAVE_LIBTEXTSTYLE
|
||||
if (color_mode == color_yes
|
||||
|| color_mode == color_html
|
||||
|| (color_mode == color_tty && isatty (STDERR_FILENO)))
|
||||
if (is_styled (stderr))
|
||||
{
|
||||
style_file_prepare ("BISON_STYLE", "BISON_STYLEDIR", pkgdatadir (),
|
||||
"bison-default.css");
|
||||
|
||||
@@ -36,6 +36,8 @@ void end_use_class (const char *style, FILE *out);
|
||||
/** Flush \a out. */
|
||||
void flush (FILE *out);
|
||||
|
||||
/** Whether there's styling on OUT. */
|
||||
bool is_styled (FILE *out);
|
||||
|
||||
/*-------------.
|
||||
| --warnings. |
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <gl_rbtreehash_list.h>
|
||||
#include <hash.h>
|
||||
#include <stdlib.h>
|
||||
#include <textstyle.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "closure.h"
|
||||
@@ -109,9 +110,15 @@ print_counterexample (counterexample *cex, FILE *out, const char *prefix)
|
||||
prefix, _("First derivation"));
|
||||
derivation_print (cex->d1, out, prefix);
|
||||
|
||||
fprintf (out, " %s%-20s ",
|
||||
prefix, cex->unifying ? _("Example") : _("Second example"));
|
||||
derivation_print_leaves (cex->d2, out, prefix);
|
||||
// If we output to the terminal (via stderr) and we have color
|
||||
// support, display unifying examples a second time, as color allows
|
||||
// to see the differences.
|
||||
if (!cex->unifying || is_styled (stderr))
|
||||
{
|
||||
fprintf (out, " %s%-20s ",
|
||||
prefix, cex->unifying ? _("Example") : _("Second example"));
|
||||
derivation_print_leaves (cex->d2, out, prefix);
|
||||
}
|
||||
fprintf (out, " %s%-20s ",
|
||||
prefix, _("Second derivation"));
|
||||
derivation_print (cex->d2, out, prefix);
|
||||
|
||||
Reference in New Issue
Block a user