diff options
author | Thaddeus Crews <repiteo@outlook.com> | 2024-04-26 12:35:07 -0500 |
---|---|---|
committer | Thaddeus Crews <repiteo@outlook.com> | 2024-04-28 16:24:48 -0500 |
commit | e0e8ce1fc00dad7cbbcd4a1f4fcedea4b760e6be (patch) | |
tree | c6bd29831b3b146f4c67f36c101b9f150331a485 /modules/text_server_adv/gdextension_build/methods.py | |
parent | 6118592c6d88350d01f74faff6fd49754f84a7d0 (diff) | |
download | redot-engine-e0e8ce1fc00dad7cbbcd4a1f4fcedea4b760e6be.tar.gz |
SCons: Colorize warnings/errors during generation
Diffstat (limited to 'modules/text_server_adv/gdextension_build/methods.py')
-rw-r--r-- | modules/text_server_adv/gdextension_build/methods.py | 117 |
1 files changed, 62 insertions, 55 deletions
diff --git a/modules/text_server_adv/gdextension_build/methods.py b/modules/text_server_adv/gdextension_build/methods.py index 32dbc59fd4..1c43759c55 100644 --- a/modules/text_server_adv/gdextension_build/methods.py +++ b/modules/text_server_adv/gdextension_build/methods.py @@ -1,66 +1,73 @@ import os import sys +from enum import Enum +# Colors are disabled in non-TTY environments such as pipes. This means +# that if output is redirected to a file, it won't contain color codes. +# Colors are always enabled on continuous integration. +_colorize = bool(sys.stdout.isatty() or os.environ.get("CI")) -def no_verbose(sys, env): - colors = {} - # Colors are disabled in non-TTY environments such as pipes. This means - # that if output is redirected to a file, it will not contain color codes - if sys.stdout.isatty(): - colors["blue"] = "\033[0;94m" - colors["bold_blue"] = "\033[1;94m" - colors["reset"] = "\033[0m" - else: - colors["blue"] = "" - colors["bold_blue"] = "" - colors["reset"] = "" +class ANSI(Enum): + """ + Enum class for adding ansi colorcodes directly into strings. + Automatically converts values to strings representing their + internal value, or an empty string in a non-colorized scope. + """ + + GRAY = "\x1b[0;30m" + RED = "\x1b[0;31m" + GREEN = "\x1b[0;32m" + YELLOW = "\x1b[0;33m" + BLUE = "\x1b[0;34m" + PURPLE = "\x1b[0;35m" + CYAN = "\x1b[0;36m" + WHITE = "\x1b[0;37m" + + BOLD_GRAY = "\x1b[1;90m" + BOLD_RED = "\x1b[1;91m" + BOLD_GREEN = "\x1b[1;92m" + BOLD_YELLOW = "\x1b[1;93m" + BOLD_BLUE = "\x1b[1;94m" + BOLD_PURPLE = "\x1b[1;95m" + BOLD_CYAN = "\x1b[1;96m" + BOLD_WHITE = "\x1b[1;97m" + + RESET = "\x1b[0m" + + def __str__(self): + global _colorize + return self.value if _colorize else "" + + +def no_verbose(env): + colors = [ANSI.BLUE, ANSI.BOLD_BLUE, ANSI.RESET] # There is a space before "..." to ensure that source file names can be # Ctrl + clicked in the VS Code terminal. - compile_source_message = "{}Compiling {}$SOURCE{} ...{}".format( - colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"] - ) - java_compile_source_message = "{}Compiling {}$SOURCE{} ...{}".format( - colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"] - ) - compile_shared_source_message = "{}Compiling shared {}$SOURCE{} ...{}".format( - colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"] - ) - link_program_message = "{}Linking Program {}$TARGET{} ...{}".format( - colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"] - ) - link_library_message = "{}Linking Static Library {}$TARGET{} ...{}".format( - colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"] - ) - ranlib_library_message = "{}Ranlib Library {}$TARGET{} ...{}".format( - colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"] - ) - link_shared_library_message = "{}Linking Shared Library {}$TARGET{} ...{}".format( - colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"] - ) - java_library_message = "{}Creating Java Archive {}$TARGET{} ...{}".format( - colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"] - ) - compiled_resource_message = "{}Creating Compiled Resource {}$TARGET{} ...{}".format( - colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"] - ) - generated_file_message = "{}Generating {}$TARGET{} ...{}".format( - colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"] - ) - - env.Append(CXXCOMSTR=[compile_source_message]) - env.Append(CCCOMSTR=[compile_source_message]) - env.Append(SHCCCOMSTR=[compile_shared_source_message]) - env.Append(SHCXXCOMSTR=[compile_shared_source_message]) - env.Append(ARCOMSTR=[link_library_message]) - env.Append(RANLIBCOMSTR=[ranlib_library_message]) - env.Append(SHLINKCOMSTR=[link_shared_library_message]) - env.Append(LINKCOMSTR=[link_program_message]) - env.Append(JARCOMSTR=[java_library_message]) - env.Append(JAVACCOMSTR=[java_compile_source_message]) - env.Append(RCCOMSTR=[compiled_resource_message]) - env.Append(GENCOMSTR=[generated_file_message]) + compile_source_message = "{0}Compiling {1}$SOURCE{0} ...{2}".format(*colors) + java_compile_source_message = "{0}Compiling {1}$SOURCE{0} ...{2}".format(*colors) + compile_shared_source_message = "{0}Compiling shared {1}$SOURCE{0} ...{2}".format(*colors) + link_program_message = "{0}Linking Program {1}$TARGET{0} ...{2}".format(*colors) + link_library_message = "{0}Linking Static Library {1}$TARGET{0} ...{2}".format(*colors) + ranlib_library_message = "{0}Ranlib Library {1}$TARGET{0} ...{2}".format(*colors) + link_shared_library_message = "{0}Linking Shared Library {1}$TARGET{0} ...{2}".format(*colors) + java_library_message = "{0}Creating Java Archive {1}$TARGET{0} ...{2}".format(*colors) + compiled_resource_message = "{0}Creating Compiled Resource {1}$TARGET{0} ...{2}".format(*colors) + generated_file_message = "{0}Generating {1}$TARGET{0} ...{2}".format(*colors) + + env.Append(CXXCOMSTR=compile_source_message) + env.Append(CCCOMSTR=compile_source_message) + env.Append(SHCCCOMSTR=compile_shared_source_message) + env.Append(SHCXXCOMSTR=compile_shared_source_message) + env.Append(ARCOMSTR=link_library_message) + env.Append(RANLIBCOMSTR=ranlib_library_message) + env.Append(SHLINKCOMSTR=link_shared_library_message) + env.Append(LINKCOMSTR=link_program_message) + env.Append(JARCOMSTR=java_library_message) + env.Append(JAVACCOMSTR=java_compile_source_message) + env.Append(RCCOMSTR=compiled_resource_message) + env.Append(GENCOMSTR=generated_file_message) def disable_warnings(self): |