Selaa lähdekoodia

Merge pull request #2827 from ZuBsPaCe/error-log-colors-windows

Improved error log colours in the Windows terminal
Juan Linietsky 9 vuotta sitten
vanhempi
commit
f2727b8dd2
2 muutettua tiedostoa jossa 60 lisäystä ja 48 poistoa
  1. 51 39
      platform/windows/os_windows.cpp
  2. 9 9
      platform/winrt/os_winrt.cpp

+ 51 - 39
platform/windows/os_windows.cpp

@@ -1765,84 +1765,96 @@ bool OS_Windows::is_window_maximized() const{
 }
 }
 
 
 
 
-void OS_Windows::print_error(const char* p_function,const char* p_file,int p_line,const char *p_code,const char*p_rationale,ErrorType p_type) {
+void OS_Windows::print_error(const char* p_function, const char* p_file, int p_line, const char* p_code, const char* p_rationale, ErrorType p_type) {
 
 
-	HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE);
-	if (!hCon || hCon==INVALID_HANDLE_VALUE) {
+	HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
+	if (!hCon || hCon == INVALID_HANDLE_VALUE) {
 
 
 		const char* err_details;
 		const char* err_details;
 		if (p_rationale && p_rationale[0])
 		if (p_rationale && p_rationale[0])
-			err_details=p_rationale;
+			err_details = p_rationale;
 		else
 		else
-			err_details=p_code;
+			err_details = p_code;
 
 
 		switch(p_type) {
 		switch(p_type) {
 			case ERR_ERROR:
 			case ERR_ERROR:
-				print("\E[1;31mERROR: %s: \E[0m\E[1m%s\n",p_function,err_details);
-				print("\E[0;31m   At: %s:%i.\E[0m\n",p_file,p_line);
+				print("ERROR: %s: %s\n", p_function, err_details);
+				print("   At: %s:%i\n", p_file, p_line);
 				break;
 				break;
 			case ERR_WARNING:
 			case ERR_WARNING:
-				print("\E[1;33mWARNING: %s: \E[0m\E[1m%s\n",p_function,err_details);
-				print("\E[0;33m     At: %s:%i.\E[0m\n",p_file,p_line);
+				print("WARNING: %s: %s\n", p_function, err_details);
+				print("     At: %s:%i\n", p_file, p_line);
 				break;
 				break;
 			case ERR_SCRIPT:
 			case ERR_SCRIPT:
-				print("\E[1;35mSCRIPT ERROR: %s: \E[0m\E[1m",p_function,err_details);
-				print("\E[0;35m          At: %s:%i.\E[0m\n",p_file,p_line);
+				print("SCRIPT ERROR: %s: %s\n", p_function, err_details);
+				print("          At: %s:%i\n", p_file, p_line);
 				break;
 				break;
 		}
 		}
+
 	} else {
 	} else {
 
 
 		CONSOLE_SCREEN_BUFFER_INFO sbi; //original
 		CONSOLE_SCREEN_BUFFER_INFO sbi; //original
-		GetConsoleScreenBufferInfo(hCon,&sbi);
-
-		SetConsoleTextAttribute(hCon,sbi.wAttributes);
+		GetConsoleScreenBufferInfo(hCon, &sbi);
 
 
+		WORD current_fg = sbi.wAttributes & (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
+		WORD current_bg = sbi.wAttributes & (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY);
 
 
-
-		uint32_t basecol=0;
+		uint32_t basecol = 0;
 		switch(p_type) {
 		switch(p_type) {
 			case ERR_ERROR: basecol = FOREGROUND_RED; break;
 			case ERR_ERROR: basecol = FOREGROUND_RED; break;
-			case ERR_WARNING: basecol = FOREGROUND_RED|FOREGROUND_GREEN; break;
-			case ERR_SCRIPT: basecol = FOREGROUND_GREEN; break;
+			case ERR_WARNING: basecol = FOREGROUND_RED | FOREGROUND_GREEN; break;
+			case ERR_SCRIPT: basecol = FOREGROUND_RED | FOREGROUND_BLUE; break;
 		}
 		}
 
 
-		if (p_rationale && p_rationale[0]) {
-
-			SetConsoleTextAttribute(hCon,basecol|FOREGROUND_INTENSITY);
+		basecol |= current_bg;
 
 
+		if (p_rationale && p_rationale[0]) {
 
 
+			SetConsoleTextAttribute(hCon, basecol | FOREGROUND_INTENSITY);
 			switch(p_type) {
 			switch(p_type) {
 				case ERR_ERROR: print("ERROR: "); break;
 				case ERR_ERROR: print("ERROR: "); break;
 				case ERR_WARNING: print("WARNING: "); break;
 				case ERR_WARNING: print("WARNING: "); break;
 				case ERR_SCRIPT: print("SCRIPT ERROR: "); break;
 				case ERR_SCRIPT: print("SCRIPT ERROR: "); break;
 			}
 			}
 
 
-			SetConsoleTextAttribute(hCon,FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
-			print(" %s\n",p_rationale);
-			SetConsoleTextAttribute(hCon,basecol);
-			print("At: ");
-			SetConsoleTextAttribute(hCon,FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN);
-			print(" %s:%i\n",p_file,p_line);
+			SetConsoleTextAttribute(hCon, current_fg | current_bg | FOREGROUND_INTENSITY);
+			print("%s\n", p_rationale);
+
+			SetConsoleTextAttribute(hCon, basecol);
+			switch (p_type) {
+				case ERR_ERROR: print("   At: "); break;
+				case ERR_WARNING: print("     At: "); break;
+				case ERR_SCRIPT: print("          At: "); break;
+			}
 
 
+			SetConsoleTextAttribute(hCon, current_fg | current_bg);
+			print("%s:%i\n", p_file, p_line);
 
 
 		} else {
 		} else {
-			SetConsoleTextAttribute(hCon,basecol|FOREGROUND_INTENSITY);
+
+			SetConsoleTextAttribute(hCon, basecol | FOREGROUND_INTENSITY);
 			switch(p_type) {
 			switch(p_type) {
-				case ERR_ERROR: print("ERROR: %s: ",p_function); break;
-				case ERR_WARNING: print("WARNING: %s: ",p_function); break;
-				case ERR_SCRIPT: print("SCRIPT ERROR: %s: ",p_function); break;
+				case ERR_ERROR: print("ERROR: %s: ", p_function); break;
+				case ERR_WARNING: print("WARNING: %s: ", p_function); break;
+				case ERR_SCRIPT: print("SCRIPT ERROR: %s: ", p_function); break;
 			}
 			}
-			SetConsoleTextAttribute(hCon,FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
-			print(" %s\n",p_code);
-			SetConsoleTextAttribute(hCon,basecol);
-			print("At: ");
-			SetConsoleTextAttribute(hCon,FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN);
-			print(" %s:%i\n",p_file,p_line);
+
+			SetConsoleTextAttribute(hCon, current_fg | current_bg | FOREGROUND_INTENSITY);
+			print("%s\n", p_code);
+
+			SetConsoleTextAttribute(hCon, basecol);
+			switch (p_type) {
+				case ERR_ERROR: print("   At: "); break;
+				case ERR_WARNING: print("     At: "); break;
+				case ERR_SCRIPT: print("          At: "); break;
+			}
+
+			SetConsoleTextAttribute(hCon, current_fg | current_bg);
+			print("%s:%i\n", p_file, p_line);
 		}
 		}
 
 
-		SetConsoleTextAttribute(hCon,sbi.wAttributes);
+		SetConsoleTextAttribute(hCon, sbi.wAttributes);
 	}
 	}
-
 }
 }
 
 
 
 

+ 9 - 9
platform/winrt/os_winrt.cpp

@@ -423,26 +423,26 @@ void OSWinrt::get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen) con
 	
 	
 }
 }
 
 
-void OSWinrt::print_error(const char* p_function,const char* p_file,int p_line,const char *p_code,const char*p_rationale,ErrorType p_type) {
+void OSWinrt::print_error(const char* p_function, const char* p_file, int p_line, const char* p_code, const char* p_rationale, ErrorType p_type) {
 
 
 	const char* err_details;
 	const char* err_details;
 	if (p_rationale && p_rationale[0])
 	if (p_rationale && p_rationale[0])
-		err_details=p_rationale;
+		err_details = p_rationale;
 	else
 	else
-		err_details=p_code;
+		err_details = p_code;
 
 
 	switch(p_type) {
 	switch(p_type) {
 		case ERR_ERROR:
 		case ERR_ERROR:
-			print("\E[1;31mERROR: %s: \E[0m\E[1m%s\n",p_function,err_details);
-			print("\E[0;31m   At: %s:%i.\E[0m\n",p_file,p_line);
+			print("ERROR: %s: %s\n", p_function, err_details);
+			print("   At: %s:%i\n", p_file, p_line);
 			break;
 			break;
 		case ERR_WARNING:
 		case ERR_WARNING:
-			print("\E[1;33mWARNING: %s: \E[0m\E[1m%s\n",p_function,err_details);
-			print("\E[0;33m     At: %s:%i.\E[0m\n",p_file,p_line);
+			print("WARNING: %s: %s\n", p_function, err_details);
+			print("     At: %s:%i\n", p_file, p_line);
 			break;
 			break;
 		case ERR_SCRIPT:
 		case ERR_SCRIPT:
-			print("\E[1;35mSCRIPT ERROR: %s: \E[0m\E[1m",p_function,err_details);
-			print("\E[0;35m          At: %s:%i.\E[0m\n",p_file,p_line);
+			print("SCRIPT ERROR: %s: %s\n", p_function, err_details);
+			print("          At: %s:%i\n", p_file, p_line);
 			break;
 			break;
 	}
 	}
 }
 }