From 94cda5bb45f5dafdea612d1f2386a0f24d447afc Mon Sep 17 00:00:00 2001 From: Mihai Alexandru <77043862+MAJigsaw77@users.noreply.github.com> Date: Fri, 30 Aug 2024 20:02:51 +0300 Subject: [PATCH 1/7] Update Log.hx --- tools/hxcpp/Log.hx | 82 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 68 insertions(+), 14 deletions(-) diff --git a/tools/hxcpp/Log.hx b/tools/hxcpp/Log.hx index 40e601473..16d9c283e 100644 --- a/tools/hxcpp/Log.hx +++ b/tools/hxcpp/Log.hx @@ -128,22 +128,77 @@ 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"); + var colorTerm = Sys.getEnv("COLORTERM"); - colorSupported = (result == 0); + if (term == "dumb") + { + colorSupported = false; } else { - colorSupported = (Sys.getEnv("TERM") == "xterm" || Sys.getEnv("ANSICON") != null); + if (Sys.getEnv('CI') != null) + { + var ciEnvNames = [ + "GITHUB_ACTIONS", + "GITEA_ACTIONS", + "TRAVIS", + "CIRCLECI", + "APPVEYOR", + "GITLAB_CI", + "BUILDKITE", + "DRONE" + ]; + + for (ci in ciEnvNames) + { + if (Sys.getEnv(ci) != null) + { + colorSupported = true; + break; + } + } + if (!colorSupported) + { + if (Sys.getEnv("CI_NAME") == "codeship") + { + colorSupported = true; + } + } + } + + if (!colorSupported) + { + if (Sys.getEnv("TEAMCITY_VERSION") != null) + { + colorSupported = ~/^9\.(0*[1-9]\d*)\.|\d{2,}\./.match(Sys.getEnv("TEAMCITY_VERSION")); + } + else if (colorTerm == "truecolor") + { + colorSupported = true; + } + } + + if (!colorSupported) + { + colorSupported = Sys.getEnv("TERM_PROGRAM") == "iTerm.app" || Sys.getEnv("TERM_PROGRAM") == "Apple_Terminal"; + } + + if (!colorSupported) + { + colorSupported = ~/(?i)-256(color)?$/.match(term); + } + + if (!colorSupported) + { + colorSupported = ~/(?i)^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/.match(term) || (colorTerm != null); + } + + if (!colorSupported) + { + colorSupported = Sys.getEnv("COLORTERM") != null || Sys.getEnv("ANSICON") != null || Sys.getEnv("ConEmuANSI") != null + || Sys.getEnv("WT_SESSION") != null || Sys.getEnv("FORCE_COLOR") != null; + } } } @@ -153,8 +208,7 @@ class Log } else { - var colorCodes:EReg = ~/\x1b\[[^m]+m/g; - return colorCodes.replace(output, ""); + return ~/\x1b\[[0-9;]*m/g.replace(output, ""); } } From 7e320db596bcab9d9fdb9d90c1114a77e6043c89 Mon Sep 17 00:00:00 2001 From: Mihai Alexandru <77043862+MAJigsaw77@users.noreply.github.com> Date: Fri, 30 Aug 2024 20:23:40 +0300 Subject: [PATCH 2/7] Update Log.hx --- tools/hxcpp/Log.hx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/hxcpp/Log.hx b/tools/hxcpp/Log.hx index 16d9c283e..864dbf60a 100644 --- a/tools/hxcpp/Log.hx +++ b/tools/hxcpp/Log.hx @@ -158,7 +158,7 @@ class Log break; } } - if (!colorSupported) + if (colorSupported != true) { if (Sys.getEnv("CI_NAME") == "codeship") { @@ -167,7 +167,7 @@ class Log } } - if (!colorSupported) + if (colorSupported != true) { if (Sys.getEnv("TEAMCITY_VERSION") != null) { @@ -179,22 +179,22 @@ class Log } } - if (!colorSupported) + if (colorSupported != true) { colorSupported = Sys.getEnv("TERM_PROGRAM") == "iTerm.app" || Sys.getEnv("TERM_PROGRAM") == "Apple_Terminal"; } - if (!colorSupported) + if (colorSupported != true) { colorSupported = ~/(?i)-256(color)?$/.match(term); } - if (!colorSupported) + if (colorSupported != true) { colorSupported = ~/(?i)^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/.match(term) || (colorTerm != null); } - if (!colorSupported) + if (colorSupported != true) { colorSupported = Sys.getEnv("COLORTERM") != null || Sys.getEnv("ANSICON") != null || Sys.getEnv("ConEmuANSI") != null || Sys.getEnv("WT_SESSION") != null || Sys.getEnv("FORCE_COLOR") != null; From ac5ad38760bb72c80b9e0a0ece3f718a7ff98339 Mon Sep 17 00:00:00 2001 From: Mihai Alexandru <77043862+MAJigsaw77@users.noreply.github.com> Date: Fri, 30 Aug 2024 20:32:29 +0300 Subject: [PATCH 3/7] Update Log.hx --- tools/hxcpp/Log.hx | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/hxcpp/Log.hx b/tools/hxcpp/Log.hx index 864dbf60a..eb0d34f49 100644 --- a/tools/hxcpp/Log.hx +++ b/tools/hxcpp/Log.hx @@ -158,6 +158,7 @@ class Log break; } } + if (colorSupported != true) { if (Sys.getEnv("CI_NAME") == "codeship") From 7a2291bb372869fe3d33585d8024ec90057718c9 Mon Sep 17 00:00:00 2001 From: Mihai Alexandru <77043862+MAJigsaw77@users.noreply.github.com> Date: Fri, 30 Aug 2024 20:52:47 +0300 Subject: [PATCH 4/7] Simplified some things a bit. --- tools/hxcpp/Log.hx | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/tools/hxcpp/Log.hx b/tools/hxcpp/Log.hx index eb0d34f49..ab2956a7d 100644 --- a/tools/hxcpp/Log.hx +++ b/tools/hxcpp/Log.hx @@ -182,23 +182,19 @@ class Log if (colorSupported != true) { - colorSupported = Sys.getEnv("TERM_PROGRAM") == "iTerm.app" || Sys.getEnv("TERM_PROGRAM") == "Apple_Terminal"; + colorSupported = ~/(?i)-256(color)?$/.match(term) + || ~/(?i)^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/.match(term) + || (colorTerm != null); } if (colorSupported != true) { - colorSupported = ~/(?i)-256(color)?$/.match(term); - } - - if (colorSupported != true) - { - colorSupported = ~/(?i)^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/.match(term) || (colorTerm != null); - } - - if (colorSupported != true) - { - colorSupported = Sys.getEnv("COLORTERM") != null || Sys.getEnv("ANSICON") != null || Sys.getEnv("ConEmuANSI") != null - || Sys.getEnv("WT_SESSION") != null || Sys.getEnv("FORCE_COLOR") != null; + 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; } } } From 5d60abab50f569a57ca449e0af69173f1a09b8ff Mon Sep 17 00:00:00 2001 From: Mihai Alexandru <77043862+MAJigsaw77@users.noreply.github.com> Date: Fri, 30 Aug 2024 22:21:13 +0300 Subject: [PATCH 5/7] More simplified --- tools/hxcpp/Log.hx | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/tools/hxcpp/Log.hx b/tools/hxcpp/Log.hx index ab2956a7d..1176c3b64 100644 --- a/tools/hxcpp/Log.hx +++ b/tools/hxcpp/Log.hx @@ -129,7 +129,6 @@ class Log if (colorSupported == null) { var term = Sys.getEnv("TERM"); - var colorTerm = Sys.getEnv("COLORTERM"); if (term == "dumb") { @@ -159,32 +158,21 @@ class Log } } - if (colorSupported != true) + if (colorSupported != true && Sys.getEnv("CI_NAME") == "codeship") { - if (Sys.getEnv("CI_NAME") == "codeship") - { - colorSupported = true; - } + colorSupported = true; } } - if (colorSupported != true) + if (colorSupported != true && Sys.getEnv("TEAMCITY_VERSION") != null) { - if (Sys.getEnv("TEAMCITY_VERSION") != null) - { - colorSupported = ~/^9\.(0*[1-9]\d*)\.|\d{2,}\./.match(Sys.getEnv("TEAMCITY_VERSION")); - } - else if (colorTerm == "truecolor") - { - colorSupported = true; - } + colorSupported = ~/^9\.(0*[1-9]\d*)\.|\d{2,}\./.match(Sys.getEnv("TEAMCITY_VERSION")); } - if (colorSupported != true) + if (colorSupported != true && term != null) { colorSupported = ~/(?i)-256(color)?$/.match(term) - || ~/(?i)^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/.match(term) - || (colorTerm != null); + || ~/(?i)^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/.match(term); } if (colorSupported != true) From 43c0cdc595a2c4b364dd3826a5e5a33119ec32be Mon Sep 17 00:00:00 2001 From: Mihai Alexandru <77043862+MAJigsaw77@users.noreply.github.com> Date: Mon, 2 Sep 2024 11:36:38 +0300 Subject: [PATCH 6/7] Replace `CI` environment variables with `HXCPP_COLOR` define. --- tools/hxcpp/Log.hx | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/tools/hxcpp/Log.hx b/tools/hxcpp/Log.hx index 1176c3b64..5556d8928 100644 --- a/tools/hxcpp/Log.hx +++ b/tools/hxcpp/Log.hx @@ -136,38 +136,8 @@ class Log } else { - if (Sys.getEnv('CI') != null) - { - var ciEnvNames = [ - "GITHUB_ACTIONS", - "GITEA_ACTIONS", - "TRAVIS", - "CIRCLECI", - "APPVEYOR", - "GITLAB_CI", - "BUILDKITE", - "DRONE" - ]; - - for (ci in ciEnvNames) - { - if (Sys.getEnv(ci) != null) - { - colorSupported = true; - break; - } - } - - if (colorSupported != true && Sys.getEnv("CI_NAME") == "codeship") - { + if (Sys.getEnv('HXCPP_COLOR') != null) colorSupported = true; - } - } - - if (colorSupported != true && Sys.getEnv("TEAMCITY_VERSION") != null) - { - colorSupported = ~/^9\.(0*[1-9]\d*)\.|\d{2,}\./.match(Sys.getEnv("TEAMCITY_VERSION")); - } if (colorSupported != true && term != null) { From 95c69a2a41a450a3242a215582febec7ac8b4d5c Mon Sep 17 00:00:00 2001 From: Mihai Alexandru <77043862+MAJigsaw77@users.noreply.github.com> Date: Mon, 2 Sep 2024 09:05:26 +0000 Subject: [PATCH 7/7] Better handling for `HXCPP_COLOR`. --- tools/hxcpp/BuildTool.hx | 5 ++++- tools/hxcpp/Log.hx | 3 --- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/hxcpp/BuildTool.hx b/tools/hxcpp/BuildTool.hx index 22f85d898..3f04283db 100644 --- a/tools/hxcpp/BuildTool.hx +++ b/tools/hxcpp/BuildTool.hx @@ -1539,8 +1539,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"); diff --git a/tools/hxcpp/Log.hx b/tools/hxcpp/Log.hx index 5556d8928..4fa6ab836 100644 --- a/tools/hxcpp/Log.hx +++ b/tools/hxcpp/Log.hx @@ -136,9 +136,6 @@ class Log } else { - if (Sys.getEnv('HXCPP_COLOR') != null) - colorSupported = true; - if (colorSupported != true && term != null) { colorSupported = ~/(?i)-256(color)?$/.match(term)