mirror of https://github.com/PCSX2/pcsx2.git
GUI: Check console color support before using it
This commit is contained in:
parent
0f4f09c597
commit
ffbfd2c844
|
@ -26,8 +26,22 @@ static DeclareTls(int) conlog_Indent(0);
|
||||||
static DeclareTls(ConsoleColors) conlog_Color(DefaultConsoleColor);
|
static DeclareTls(ConsoleColors) conlog_Color(DefaultConsoleColor);
|
||||||
|
|
||||||
#ifdef __POSIX__
|
#ifdef __POSIX__
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
static FILE* stdout_fp = stdout;
|
static FILE* stdout_fp = stdout;
|
||||||
|
|
||||||
|
static bool checkSupportsColor()
|
||||||
|
{
|
||||||
|
if (!isatty(fileno(stdout_fp)))
|
||||||
|
return false;
|
||||||
|
char* term = getenv("TERM");
|
||||||
|
if (!term || (0 == strcmp(term, "dumb")))
|
||||||
|
return false;
|
||||||
|
return true; // Probably supports color
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool supports_color = checkSupportsColor();
|
||||||
|
|
||||||
void Console_SetStdout(FILE* fp)
|
void Console_SetStdout(FILE* fp)
|
||||||
{
|
{
|
||||||
stdout_fp = fp;
|
stdout_fp = fp;
|
||||||
|
@ -177,6 +191,8 @@ static void __concall ConsoleStdout_Newline()
|
||||||
static void __concall ConsoleStdout_DoSetColor(ConsoleColors color)
|
static void __concall ConsoleStdout_DoSetColor(ConsoleColors color)
|
||||||
{
|
{
|
||||||
#if defined(__POSIX__)
|
#if defined(__POSIX__)
|
||||||
|
if (!supports_color)
|
||||||
|
return;
|
||||||
fprintf(stdout_fp, "\033[0m%s", GetLinuxConsoleColor(color));
|
fprintf(stdout_fp, "\033[0m%s", GetLinuxConsoleColor(color));
|
||||||
fflush(stdout_fp);
|
fflush(stdout_fp);
|
||||||
#endif
|
#endif
|
||||||
|
@ -185,9 +201,11 @@ static void __concall ConsoleStdout_DoSetColor(ConsoleColors color)
|
||||||
static void __concall ConsoleStdout_SetTitle(const wxString& title)
|
static void __concall ConsoleStdout_SetTitle(const wxString& title)
|
||||||
{
|
{
|
||||||
#if defined(__POSIX__)
|
#if defined(__POSIX__)
|
||||||
fputs("\033]0;", stdout_fp);
|
if (supports_color)
|
||||||
|
fputs("\033]0;", stdout_fp);
|
||||||
fputs(title.utf8_str(), stdout_fp);
|
fputs(title.utf8_str(), stdout_fp);
|
||||||
fputs("\007", stdout_fp);
|
if (supports_color)
|
||||||
|
fputs("\007", stdout_fp);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue