/* Output colorization.
- Copyright (C) 2011-2019 Free Software Foundation, Inc.
+ Copyright (C) 2011-2020 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
{ "range2", SGR_SEQ (COLOR_FG_BLUE), 6, false },
{ "locus", SGR_SEQ (COLOR_BOLD), 5, false },
{ "quote", SGR_SEQ (COLOR_BOLD), 5, false },
+ { "path", SGR_SEQ (COLOR_BOLD COLOR_SEPARATOR COLOR_FG_CYAN), 4, false },
{ "fixit-insert", SGR_SEQ (COLOR_FG_GREEN), 12, false },
{ "fixit-delete", SGR_SEQ (COLOR_FG_RED), 12, false },
{ "diff-filename", SGR_SEQ (COLOR_BOLD), 13, false },
/* Parse GCC_COLORS. The default would look like:
GCC_COLORS='error=01;31:warning=01;35:note=01;36:\
- range1=32:range2=34:locus=01:quote=01:\
+ range1=32:range2=34:locus=01:quote=01:path=01;36:\
fixit-insert=32:fixit-delete=31:'\
diff-filename=01:diff-hunk=32:diff-delete=31:diff-insert=32:\
type-diff=01;32'
&& GetConsoleMode (h, &m);
#else
char const *t = getenv ("TERM");
+ /* emacs M-x shell sets TERM="dumb". */
return t && strcmp (t, "dumb") != 0 && isatty (STDERR_FILENO);
#endif
}
}
}
-/* Determine if URLs should be enabled, based on RULE.
+/* Return URL_FORMAT_XXX which tells how we should emit urls
+ when in always mode.
+ We use GCC_URLS and if that is not defined TERM_URLS.
+ If neither is defined the feature is enabled by default. */
+
+static diagnostic_url_format
+parse_env_vars_for_urls ()
+{
+ const char *p;
+
+ p = getenv ("GCC_URLS"); /* Plural! */
+ if (p == NULL)
+ p = getenv ("TERM_URLS");
+
+ if (p == NULL)
+ return URL_FORMAT_DEFAULT;
+
+ if (*p == '\0')
+ return URL_FORMAT_NONE;
+
+ if (!strcmp (p, "no"))
+ return URL_FORMAT_NONE;
+
+ if (!strcmp (p, "st"))
+ return URL_FORMAT_ST;
+
+ if (!strcmp (p, "bel"))
+ return URL_FORMAT_BEL;
+
+ return URL_FORMAT_DEFAULT;
+}
+
+/* Return true if we should use urls when in auto mode, false otherwise. */
+
+static bool
+auto_enable_urls ()
+{
+#ifdef __MINGW32__
+ return false;
+#else
+ const char *term, *colorterm;
+
+ /* First check the terminal is capable of printing color escapes,
+ if not URLs won't work either. */
+ if (!should_colorize ())
+ return false;
+
+ /* xfce4-terminal is known to not implement URLs at this time.
+ Recently new installations (0.8) will safely ignore the URL escape
+ sequences, but a large number of legacy installations (0.6.3) print
+ garbage when URLs are printed. Therefore we lose nothing by
+ disabling this feature for that specific terminal type. */
+ colorterm = getenv ("COLORTERM");
+ if (colorterm && !strcmp (colorterm, "xfce4-terminal"))
+ return false;
+
+ /* Old versions of gnome-terminal where URL escapes cause screen
+ corruptions set COLORTERM="gnome-terminal", recent versions
+ with working URL support set this to "truecolor". */
+ if (colorterm && !strcmp (colorterm, "gnome-terminal"))
+ return false;
+
+ /* Since the following checks are less specific than the ones
+ above, let GCC_URLS and TERM_URLS override the decision. */
+ if (getenv ("GCC_URLS") || getenv ("TERM_URLS"))
+ return true;
+
+ /* In an ssh session the COLORTERM is not there, but TERM=xterm
+ can be used as an indication of a incompatible terminal while
+ TERM=xterm-256color appears to be a working terminal. */
+ term = getenv ("TERM");
+ if (!colorterm && term && !strcmp (term, "xterm"))
+ return false;
+
+ /* When logging in a linux over serial line, we see TERM=linux
+ and no COLORTERM, it is unlikely that the URL escapes will
+ work in that environmen either. */
+ if (!colorterm && term && !strcmp (term, "linux"))
+ return false;
+
+ return true;
+#endif
+}
+
+/* Determine if URLs should be enabled, based on RULE,
+ and, if so, which format to use.
This reuses the logic for colorization. */
-bool
-diagnostic_urls_enabled_p (diagnostic_url_rule_t rule)
+diagnostic_url_format
+determine_url_format (diagnostic_url_rule_t rule)
{
switch (rule)
{
case DIAGNOSTICS_URL_NO:
- return false;
+ return URL_FORMAT_NONE;
case DIAGNOSTICS_URL_YES:
- return true;
+ return parse_env_vars_for_urls ();
case DIAGNOSTICS_URL_AUTO:
- return should_colorize ();
+ if (auto_enable_urls ())
+ return parse_env_vars_for_urls ();
+ else
+ return URL_FORMAT_NONE;
default:
gcc_unreachable ();
}