summaryrefslogtreecommitdiff
path: root/drivers/unix/os_unix.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/unix/os_unix.cpp')
-rw-r--r--drivers/unix/os_unix.cpp36
1 files changed, 26 insertions, 10 deletions
diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp
index 25dee6aedb..2d8d37b2f1 100644
--- a/drivers/unix/os_unix.cpp
+++ b/drivers/unix/os_unix.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -59,6 +59,7 @@
#include <poll.h>
#include <signal.h>
#include <stdarg.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
@@ -554,23 +555,38 @@ void UnixTerminalLogger::log_error(const char *p_function, const char *p_file, i
else
err_details = p_code;
+ // Disable color codes if stdout is not a TTY.
+ // This prevents Godot from writing ANSI escape codes when redirecting
+ // stdout and stderr to a file.
+ const bool tty = isatty(fileno(stdout));
+ const char *gray = tty ? "\E[0;90m" : "";
+ const char *red = tty ? "\E[0;91m" : "";
+ const char *red_bold = tty ? "\E[1;31m" : "";
+ const char *yellow = tty ? "\E[0;93m" : "";
+ const char *yellow_bold = tty ? "\E[1;33m" : "";
+ const char *magenta = tty ? "\E[0;95m" : "";
+ const char *magenta_bold = tty ? "\E[1;35m" : "";
+ const char *cyan = tty ? "\E[0;96m" : "";
+ const char *cyan_bold = tty ? "\E[1;36m" : "";
+ const char *reset = tty ? "\E[0m" : "";
+
switch (p_type) {
case ERR_WARNING:
- logf_error("\E[1;33mWARNING: %s: \E[0m\E[1m%s\n", p_function, err_details);
- logf_error("\E[0;33m At: %s:%i.\E[0m\n", p_file, p_line);
+ logf_error("%sWARNING:%s %s\n", yellow_bold, yellow, err_details);
+ logf_error("%s at: %s (%s:%i)%s\n", gray, p_function, p_file, p_line, reset);
break;
case ERR_SCRIPT:
- logf_error("\E[1;35mSCRIPT ERROR: %s: \E[0m\E[1m%s\n", p_function, err_details);
- logf_error("\E[0;35m At: %s:%i.\E[0m\n", p_file, p_line);
+ logf_error("%sSCRIPT ERROR:%s %s\n", magenta_bold, magenta, err_details);
+ logf_error("%s at: %s (%s:%i)%s\n", gray, p_function, p_file, p_line, reset);
break;
case ERR_SHADER:
- logf_error("\E[1;36mSHADER ERROR: %s: \E[0m\E[1m%s\n", p_function, err_details);
- logf_error("\E[0;36m At: %s:%i.\E[0m\n", p_file, p_line);
+ logf_error("%sSHADER ERROR:%s %s\n", cyan_bold, cyan, err_details);
+ logf_error("%s at: %s (%s:%i)%s\n", gray, p_function, p_file, p_line, reset);
break;
case ERR_ERROR:
default:
- logf_error("\E[1;31mERROR: %s: \E[0m\E[1m%s\n", p_function, err_details);
- logf_error("\E[0;31m At: %s:%i.\E[0m\n", p_file, p_line);
+ logf_error("%sERROR:%s %s\n", red_bold, red, err_details);
+ logf_error("%s at: %s (%s:%i)%s\n", gray, p_function, p_file, p_line, reset);
break;
}
}