Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better ANSI Color Support Detection #1146

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
5 changes: 4 additions & 1 deletion tools/hxcpp/BuildTool.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1541,8 +1541,11 @@ class BuildTool
}


if (defines.exists("HXCPP_NO_COLOUR") || defines.exists("HXCPP_NO_COLOR"))
if (Sys.getEnv("HXCPP_COLOUR") != null || Sys.getEnv("HXCPP_COLOR") != null)
Log.colorSupported = !(defines.exists("HXCPP_NO_COLOUR") || defines.exists("HXCPP_NO_COLOR"));
else if (defines.exists("HXCPP_NO_COLOUR") || defines.exists("HXCPP_NO_COLOR"))
Log.colorSupported = false;

Log.verbose = defines.exists("HXCPP_VERBOSE");
exitOnThreadError = defines.exists("HXCPP_EXIT_ON_ERROR");

Expand Down
34 changes: 20 additions & 14 deletions tools/hxcpp/Log.hx
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,29 @@ class Log
{
if (colorSupported == null)
{
if (!BuildTool.isWindows)
{
var result = -1;
try
{
var process = new Process ("tput", [ "colors" ]);
result = process.exitCode ();
process.close ();
}
catch (e:Dynamic) {};
var term = Sys.getEnv("TERM");

colorSupported = (result == 0);
if (term == "dumb")
{
colorSupported = false;
}
else
{
colorSupported = (Sys.getEnv("TERM") == "xterm" || Sys.getEnv("ANSICON") != null);
if (colorSupported != true && term != null)
{
colorSupported = ~/(?i)-256(color)?$/.match(term)
|| ~/(?i)^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/.match(term);
}

if (colorSupported != true)
{
colorSupported = Sys.getEnv("TERM_PROGRAM") == "iTerm.app"
|| Sys.getEnv("TERM_PROGRAM") == "Apple_Terminal"
|| Sys.getEnv("COLORTERM") != null
|| Sys.getEnv("ANSICON") != null
|| Sys.getEnv("ConEmuANSI") != null
|| Sys.getEnv("WT_SESSION") != null;
}
}
}

Expand All @@ -153,8 +160,7 @@ class Log
}
else
{
var colorCodes:EReg = ~/\x1b\[[^m]+m/g;
return colorCodes.replace(output, "");
return ~/\x1b\[[0-9;]*m/g.replace(output, "");
}
}

Expand Down