From 277abfab2b0fe4e761c3d09ea05e76f9e9a964e5 Mon Sep 17 00:00:00 2001 From: MAJigsaw77 <77043862+MAJigsaw77@users.noreply.github.com> Date: Fri, 17 Oct 2025 16:19:29 +0300 Subject: [PATCH] Fix `html5` compile aswell as some other `ANSI` not showing up. --- source/funkin/util/AnsiUtil.hx | 102 +++++++++++++++--------- source/funkin/util/logging/AnsiTrace.hx | 7 +- tools/AnsiUtil.hx | 102 +++++++++++++++--------- 3 files changed, 129 insertions(+), 82 deletions(-) diff --git a/source/funkin/util/AnsiUtil.hx b/source/funkin/util/AnsiUtil.hx index 6d20a8035..a63822947 100644 --- a/source/funkin/util/AnsiUtil.hx +++ b/source/funkin/util/AnsiUtil.hx @@ -62,25 +62,25 @@ class AnsiUtil { #if sys @:noCompletion - private static final REGEX_TEAMCITY_VERSION:EReg = ~/^9\.(0*[1-9]\d*)\.|\d{2,}\./; + static final REGEX_TEAMCITY_VERSION:EReg = ~/^9\.(0*[1-9]\d*)\.|\d{2,}\./; @:noCompletion - private static final REGEX_TERM_256:EReg = ~/(?i)-256(color)?$/; + static final REGEX_TERM_256:EReg = ~/(?i)-256(color)?$/; @:noCompletion - private static final REGEX_TERM_TYPES:EReg = ~/(?i)^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/; + static final REGEX_TERM_TYPES:EReg = ~/(?i)^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/; #end @:noCompletion - private static final REGEX_ANSI_CODES:EReg = ~/\x1b\[[0-9;]*m/g; + static final REGEX_ANSI_CODES:EReg = ~/\x1b\[[0-9;]*m/g; @:noCompletion - private static var codesSupported:Null = null; + static var codesSupported:Null = null; /** * Safe wrapper for Sys.getEnv (returns null on non-sys targets). */ - private static function getEnvSafe(name:String):Null + static function getEnvSafe(name:String):Null { #if sys return Sys.getEnv(name); @@ -274,55 +274,79 @@ class AnsiUtil return stripCodes(code + input + AnsiCode.RESET); } - @:noCompletion - private static function stripCodes(output:String):String + /** + * Whether ANSI codes are supported or not. + * + * @return `true` if ANSI codes are supported, `false` otherwise. + */ + public static function isColorCodesSupported():Bool { - #if sys if (codesSupported == null) { - final term:Null = getEnvSafe('TERM'); - - if (term == 'dumb') codesSupported = false; - else + #if sys + if (codesSupported == null) { - if (codesSupported != true && term != null) codesSupported = REGEX_TERM_256.match(term) || REGEX_TERM_TYPES.match(term); + final term:Null = getEnvSafe('TERM'); - if (getEnvSafe('CI') != null) + if (term == 'dumb') codesSupported = false; + else { - final ciEnvNames:Array = [ - "GITHUB_ACTIONS", "GITEA_ACTIONS", "TRAVIS", "CIRCLECI", - "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE" - ]; - - for (ci in ciEnvNames) + if (codesSupported != true && term != null) { - if (getEnvSafe(ci) != null) + codesSupported = REGEX_TERM_256.match(term) || REGEX_TERM_TYPES.match(term); + } + + if (getEnvSafe('CI') != null) + { + final ciEnvNames:Array = [ + "GITHUB_ACTIONS", "GITEA_ACTIONS", "TRAVIS", "CIRCLECI", + "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE" + ]; + + for (ci in ciEnvNames) + { + if (getEnvSafe(ci) != null) + { + codesSupported = true; + break; + } + } + + if (codesSupported != true && getEnvSafe("CI_NAME") == "codeship") { codesSupported = true; - break; } } - if (codesSupported != true && getEnvSafe("CI_NAME") == "codeship") codesSupported = true; - } + final teamCity:Null = getEnvSafe("TEAMCITY_VERSION"); - final teamCity:Null = getEnvSafe("TEAMCITY_VERSION"); - if (codesSupported != true && teamCity != null) codesSupported = REGEX_TEAMCITY_VERSION.match(teamCity); + if (codesSupported != true && teamCity != null) + { + codesSupported = REGEX_TEAMCITY_VERSION.match(teamCity); + } - if (codesSupported != true) - { - codesSupported = getEnvSafe('TERM_PROGRAM') == 'iTerm.app' - || getEnvSafe('TERM_PROGRAM') == 'Apple_Terminal' - || getEnvSafe('COLORTERM') != null - || getEnvSafe('ANSICON') != null - || getEnvSafe('ConEmuANSI') != null - || getEnvSafe('WT_SESSION') != null; + if (codesSupported != true) + { + codesSupported = getEnvSafe('TERM_PROGRAM') == 'iTerm.app' + || getEnvSafe('TERM_PROGRAM') == 'Apple_Terminal' + || getEnvSafe('COLORTERM') != null + || getEnvSafe('ANSICON') != null + || getEnvSafe('ConEmuANSI') != null + || getEnvSafe('WT_SESSION') != null; + } } } + #else + codesSupported = false; + #end } - #else - codesSupported = false; - #end - return codesSupported == true ? output : REGEX_ANSI_CODES.replace(output, ''); + + return codesSupported == true; + } + + @:noCompletion + static function stripCodes(output:String):String + { + return isColorCodesSupported() ? output : REGEX_ANSI_CODES.replace(output, ''); } } diff --git a/source/funkin/util/logging/AnsiTrace.hx b/source/funkin/util/logging/AnsiTrace.hx index 59de7be39..75f9a0444 100644 --- a/source/funkin/util/logging/AnsiTrace.hx +++ b/source/funkin/util/logging/AnsiTrace.hx @@ -18,14 +18,13 @@ using StringTools; @:nullSafety class AnsiTrace { - #if sys private static final HEADER_REGEX = ~/^\s*\[(.*?)\]\s*(.*)$/; + #if (sys && FEATURE_DEBUG_FILE_LOGGING) private static final logFilePath:String = 'logs/log-${DateUtil.generateTimestamp()}.txt'; private static var logFile:Null = null; private static var logFileClosed:Bool = false; #end - #end /** * Output a message to the log. @@ -91,7 +90,7 @@ class AnsiTrace var str:String = Std.string(v); if (infos == null) return str; - if (colorSupported) + if (AnsiUtil.isColorCodesSupported()) { var dirs:Array = infos.fileName.split("/"); dirs[dirs.length - 1] = dirs[dirs.length - 1].bold(); @@ -123,7 +122,7 @@ class AnsiTrace public static function traceBF() { #if (sys && debug) - if (colorSupported) + if (AnsiUtil.isColorCodesSupported()) { for (line in ansiBF) Sys.stdout().writeString(line + "\n"); diff --git a/tools/AnsiUtil.hx b/tools/AnsiUtil.hx index a675a2039..76599d21d 100644 --- a/tools/AnsiUtil.hx +++ b/tools/AnsiUtil.hx @@ -62,25 +62,25 @@ class AnsiUtil { #if sys @:noCompletion - private static final REGEX_TEAMCITY_VERSION:EReg = ~/^9\.(0*[1-9]\d*)\.|\d{2,}\./; + static final REGEX_TEAMCITY_VERSION:EReg = ~/^9\.(0*[1-9]\d*)\.|\d{2,}\./; @:noCompletion - private static final REGEX_TERM_256:EReg = ~/(?i)-256(color)?$/; + static final REGEX_TERM_256:EReg = ~/(?i)-256(color)?$/; @:noCompletion - private static final REGEX_TERM_TYPES:EReg = ~/(?i)^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/; + static final REGEX_TERM_TYPES:EReg = ~/(?i)^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/; #end @:noCompletion - private static final REGEX_ANSI_CODES:EReg = ~/\x1b\[[0-9;]*m/g; + static final REGEX_ANSI_CODES:EReg = ~/\x1b\[[0-9;]*m/g; @:noCompletion - private static var codesSupported:Null = null; + static var codesSupported:Null = null; /** * Safe wrapper for Sys.getEnv (returns null on non-sys targets). */ - private static function getEnvSafe(name:String):Null + static function getEnvSafe(name:String):Null { #if sys return Sys.getEnv(name); @@ -274,55 +274,79 @@ class AnsiUtil return stripCodes(code + input + AnsiCode.RESET); } - @:noCompletion - private static function stripCodes(output:String):String + /** + * Whether ANSI codes are supported or not. + * + * @return `true` if ANSI codes are supported, `false` otherwise. + */ + public static function isColorCodesSupported():Bool { - #if sys if (codesSupported == null) { - final term:Null = getEnvSafe('TERM'); - - if (term == 'dumb') codesSupported = false; - else + #if sys + if (codesSupported == null) { - if (codesSupported != true && term != null) codesSupported = REGEX_TERM_256.match(term) || REGEX_TERM_TYPES.match(term); + final term:Null = getEnvSafe('TERM'); - if (getEnvSafe('CI') != null) + if (term == 'dumb') codesSupported = false; + else { - final ciEnvNames:Array = [ - "GITHUB_ACTIONS", "GITEA_ACTIONS", "TRAVIS", "CIRCLECI", - "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE" - ]; - - for (ci in ciEnvNames) + if (codesSupported != true && term != null) { - if (getEnvSafe(ci) != null) + codesSupported = REGEX_TERM_256.match(term) || REGEX_TERM_TYPES.match(term); + } + + if (getEnvSafe('CI') != null) + { + final ciEnvNames:Array = [ + "GITHUB_ACTIONS", "GITEA_ACTIONS", "TRAVIS", "CIRCLECI", + "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE" + ]; + + for (ci in ciEnvNames) + { + if (getEnvSafe(ci) != null) + { + codesSupported = true; + break; + } + } + + if (codesSupported != true && getEnvSafe("CI_NAME") == "codeship") { codesSupported = true; - break; } } - if (codesSupported != true && getEnvSafe("CI_NAME") == "codeship") codesSupported = true; - } + final teamCity:Null = getEnvSafe("TEAMCITY_VERSION"); - final teamCity:Null = getEnvSafe("TEAMCITY_VERSION"); - if (codesSupported != true && teamCity != null) codesSupported = REGEX_TEAMCITY_VERSION.match(teamCity); + if (codesSupported != true && teamCity != null) + { + codesSupported = REGEX_TEAMCITY_VERSION.match(teamCity); + } - if (codesSupported != true) - { - codesSupported = getEnvSafe('TERM_PROGRAM') == 'iTerm.app' - || getEnvSafe('TERM_PROGRAM') == 'Apple_Terminal' - || getEnvSafe('COLORTERM') != null - || getEnvSafe('ANSICON') != null - || getEnvSafe('ConEmuANSI') != null - || getEnvSafe('WT_SESSION') != null; + if (codesSupported != true) + { + codesSupported = getEnvSafe('TERM_PROGRAM') == 'iTerm.app' + || getEnvSafe('TERM_PROGRAM') == 'Apple_Terminal' + || getEnvSafe('COLORTERM') != null + || getEnvSafe('ANSICON') != null + || getEnvSafe('ConEmuANSI') != null + || getEnvSafe('WT_SESSION') != null; + } } } + #else + codesSupported = false; + #end } - #else - codesSupported = false; - #end - return codesSupported == true ? output : REGEX_ANSI_CODES.replace(output, ''); + + return codesSupported == true; + } + + @:noCompletion + static function stripCodes(output:String):String + { + return isColorCodesSupported() ? output : REGEX_ANSI_CODES.replace(output, ''); } }