mirror of
https://github.com/unrealircd/unrealircd.git
synced 2026-07-09 22:13:11 +02:00
Add terminal_supports_color(), used by logging to terminal code.
We now also correctly disable color support if someone is on a color-capable terminal but redirects the output of the boot to a file, eg: bin/unrealircd >boot.log 2>&1
This commit is contained in:
@@ -1054,6 +1054,7 @@ extern char *get_connect_extinfo(Client *client);
|
||||
extern char *unreal_strftime(char *str);
|
||||
extern void strtolower_safe(char *dst, char *src, int size);
|
||||
extern int running_interactively(void);
|
||||
extern int terminal_supports_color(void);
|
||||
extern void skip_whitespace(char **p);
|
||||
extern void read_until(char **p, char *stopchars);
|
||||
/* src/unrealdb.c start */
|
||||
|
||||
@@ -1044,9 +1044,7 @@ void do_unreal_log_disk(LogLevel loglevel, char *subsystem, char *event_id, Mult
|
||||
else
|
||||
win_log("* [%s] %s\n", log_level_valtostring(loglevel), m->line);
|
||||
#else
|
||||
char *t = getenv("TERM");
|
||||
/* Very lazy color detection */
|
||||
if (t && strstr(t, "color"))
|
||||
if (terminal_supports_color())
|
||||
{
|
||||
if (show_event_id_console)
|
||||
{
|
||||
|
||||
+28
@@ -2129,6 +2129,34 @@ int running_interactively(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
int terminal_supports_color(void)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
char *s;
|
||||
|
||||
/* Yeah we check all of stdin, stdout, stderr, because
|
||||
* or more may be redirected (bin/unrealircd >log 2>&1),
|
||||
* and then we want to say no to color support.
|
||||
*/
|
||||
if (!isatty(0) || !isatty(1) || !isatty(2))
|
||||
return 0;
|
||||
|
||||
s = getenv("TERM");
|
||||
/* Yeah this is a lazy way to detect color-capable terminals
|
||||
* but it is good enough for me.
|
||||
*/
|
||||
if (s)
|
||||
{
|
||||
if (strstr(s, "color") || strstr(s, "ansi"))
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Skip whitespace (if any) */
|
||||
void skip_whitespace(char **p)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user