[core] Print warnings in purple

This commit is contained in:
Tom van Dijck 2017-04-27 16:12:51 -07:00
parent 206c53610f
commit 6e175f026a
4 changed files with 51 additions and 0 deletions

View File

@ -334,7 +334,10 @@
if _OPTIONS.fatal then
error(message)
else
local color = term.getTextColor();
term.setTextColor(13);
io.stderr:write(string.format("** Warning: " .. message .. "\n", ...))
term.setTextColor(color);
end
end

View File

@ -101,6 +101,12 @@ static const luaL_Reg buffered_functions[] = {
{ NULL, NULL }
};
static const luaL_Reg term_functions[] = {
{ "getTextColor", term_getTextColor },
{ "setTextColor", term_setTextColor },
{ NULL, NULL }
};
#ifdef PREMAKE_CURL
static const luaL_Reg http_functions[] = {
{ "get", http_get },
@ -130,6 +136,7 @@ int premake_init(lua_State* L)
luaL_register(L, "os", os_functions);
luaL_register(L, "string", string_functions);
luaL_register(L, "buffered", buffered_functions);
luaL_register(L, "term", term_functions);
#ifdef PREMAKE_CURL
luaL_register(L, "http", http_functions);

View File

@ -134,6 +134,8 @@ int buffered_write(lua_State* L);
int buffered_writeln(lua_State* L);
int buffered_close(lua_State* L);
int buffered_tostring(lua_State* L);
int term_getTextColor(lua_State* L);
int term_setTextColor(lua_State* L);
#ifdef PREMAKE_CURL
int http_get(lua_State* L);

39
src/host/term_textColor.c Normal file
View File

@ -0,0 +1,39 @@
/**
* \file term_textColor.c
* \brief Change the foreground color of the terminal output.
* \author Copyright (c) 2017 Blizzard Entertainment and the Premake project
*/
#include "premake.h"
int term_getTextColor(lua_State* L)
{
#if PLATFORM_WINDOWS
CONSOLE_SCREEN_BUFFER_INFO info;
if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info))
return 0;
lua_pushinteger(L, (int)info.wAttributes);
return 1;
#else
(void)(L); /* warning: unused parameter */
return 0;
#endif
}
int term_setTextColor(lua_State* L)
{
#if PLATFORM_WINDOWS
lua_Integer color = luaL_optinteger(L, 1, -1);
if (color >= 0)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), (WORD)color);
SetConsoleTextAttribute(GetStdHandle(STD_ERROR_HANDLE), (WORD)color);
}
#else
(void)(L); /* warning: unused parameter */
#endif
return 0;
}