-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Tweak console error/warning print colors #98796
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -81,76 +81,51 @@ | |||||
if (!hCon || hCon == INVALID_HANDLE_VALUE) { | ||||||
StdLogger::log_error(p_function, p_file, p_line, p_code, p_rationale, p_type); | ||||||
} else { | ||||||
CONSOLE_SCREEN_BUFFER_INFO sbi; //original | ||||||
GetConsoleScreenBufferInfo(hCon, &sbi); | ||||||
|
||||||
WORD current_bg = sbi.wAttributes & (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY); | ||||||
|
||||||
uint32_t basecol = 0; | ||||||
switch (p_type) { | ||||||
case ERR_ERROR: | ||||||
basecol = FOREGROUND_RED; | ||||||
break; | ||||||
case ERR_WARNING: | ||||||
basecol = FOREGROUND_RED | FOREGROUND_GREEN; | ||||||
break; | ||||||
case ERR_SCRIPT: | ||||||
basecol = FOREGROUND_RED | FOREGROUND_BLUE; | ||||||
break; | ||||||
case ERR_SHADER: | ||||||
basecol = FOREGROUND_GREEN | FOREGROUND_BLUE; | ||||||
break; | ||||||
const char *err_details; | ||||||
if (p_rationale && p_rationale[0]) { | ||||||
err_details = p_rationale; | ||||||
} else { | ||||||
err_details = p_code; | ||||||
} | ||||||
|
||||||
basecol |= current_bg; | ||||||
// Disable color codes if stdout is not a TTY. | ||||||
// This prevents Godot from writing ANSI escape codes when redirecting | ||||||
// stdout and stderr to a file. | ||||||
// | ||||||
// FIXME: Is there a way to check whether stdout is a TTY on Windows? | ||||||
const char *red = "\E[0;91m"; | ||||||
Check failure on line 96 in platform/windows/windows_terminal_logger.cpp GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)
Check warning on line 96 in platform/windows/windows_terminal_logger.cpp GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)
Check failure on line 96 in platform/windows/windows_terminal_logger.cpp GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably avoid using
Suggested change
Footnotes |
||||||
const char *red_bold = "\E[1;91m"; | ||||||
Check warning on line 97 in platform/windows/windows_terminal_logger.cpp GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)
|
||||||
const char *red_faint = "\E[2;91m"; | ||||||
Check warning on line 98 in platform/windows/windows_terminal_logger.cpp GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)
|
||||||
const char *yellow = "\E[0;93m"; | ||||||
Check warning on line 99 in platform/windows/windows_terminal_logger.cpp GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)
|
||||||
const char *yellow_bold = "\E[1;93m"; | ||||||
Check warning on line 100 in platform/windows/windows_terminal_logger.cpp GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)
|
||||||
const char *yellow_faint = "\E[2;93m"; | ||||||
Check warning on line 101 in platform/windows/windows_terminal_logger.cpp GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)
|
||||||
const char *magenta = "\E[0;95m"; | ||||||
Check warning on line 102 in platform/windows/windows_terminal_logger.cpp GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)
|
||||||
const char *magenta_bold = "\E[1;95m"; | ||||||
Check warning on line 103 in platform/windows/windows_terminal_logger.cpp GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)
|
||||||
const char *magenta_faint = "\E[2;95m"; | ||||||
Check warning on line 104 in platform/windows/windows_terminal_logger.cpp GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)
|
||||||
const char *cyan = "\E[0;96m"; | ||||||
Check warning on line 105 in platform/windows/windows_terminal_logger.cpp GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)
|
||||||
const char *cyan_bold = "\E[1;96m"; | ||||||
const char *cyan_faint = "\E[2;96m"; | ||||||
const char *reset = "\E[0m"; | ||||||
|
||||||
SetConsoleTextAttribute(hCon, basecol | FOREGROUND_INTENSITY); | ||||||
switch (p_type) { | ||||||
case ERR_ERROR: | ||||||
logf_error("ERROR:"); | ||||||
break; | ||||||
case ERR_WARNING: | ||||||
logf_error("WARNING:"); | ||||||
logf_error("%sWARNING:%s %s\n", yellow_bold, yellow, err_details); | ||||||
logf_error("%s at: %s (%s:%i)%s\n", yellow_faint, p_function, p_file, p_line, reset); | ||||||
break; | ||||||
case ERR_SCRIPT: | ||||||
logf_error("SCRIPT ERROR:"); | ||||||
logf_error("%sSCRIPT ERROR:%s %s\n", magenta_bold, magenta, err_details); | ||||||
logf_error("%s at: %s (%s:%i)%s\n", magenta_faint, p_function, p_file, p_line, reset); | ||||||
break; | ||||||
case ERR_SHADER: | ||||||
logf_error("SHADER ERROR:"); | ||||||
logf_error("%sSHADER ERROR:%s %s\n", cyan_bold, cyan, err_details); | ||||||
logf_error("%s at: %s (%s:%i)%s\n", cyan_faint, p_function, p_file, p_line, reset); | ||||||
break; | ||||||
} | ||||||
|
||||||
SetConsoleTextAttribute(hCon, basecol); | ||||||
if (p_rationale && p_rationale[0]) { | ||||||
logf_error(" %s\n", p_rationale); | ||||||
} else { | ||||||
logf_error(" %s\n", p_code); | ||||||
} | ||||||
|
||||||
// `FOREGROUND_INTENSITY` alone results in gray text. | ||||||
SetConsoleTextAttribute(hCon, FOREGROUND_INTENSITY); | ||||||
switch (p_type) { | ||||||
case ERR_ERROR: | ||||||
logf_error(" at: "); | ||||||
break; | ||||||
case ERR_WARNING: | ||||||
logf_error(" at: "); | ||||||
break; | ||||||
case ERR_SCRIPT: | ||||||
logf_error(" at: "); | ||||||
break; | ||||||
case ERR_SHADER: | ||||||
logf_error(" at: "); | ||||||
default: | ||||||
logf_error("%sERROR:%s %s\n", red_bold, red, err_details); | ||||||
logf_error("%s at: %s (%s:%i)%s\n", red_faint, p_function, p_file, p_line, reset); | ||||||
break; | ||||||
} | ||||||
|
||||||
if (p_rationale && p_rationale[0]) { | ||||||
logf_error("(%s:%i)\n", p_file, p_line); | ||||||
} else { | ||||||
logf_error("%s (%s:%i)\n", p_function, p_file, p_line); | ||||||
} | ||||||
|
||||||
SetConsoleTextAttribute(hCon, sbi.wAttributes); | ||||||
} | ||||||
} | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#91201