diff --git a/src/base/_foundation.lua b/src/base/_foundation.lua index 74b5da83..bd98b4d2 100644 --- a/src/base/_foundation.lua +++ b/src/base/_foundation.lua @@ -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 diff --git a/src/host/premake.c b/src/host/premake.c index 949a4b51..17c2273c 100644 --- a/src/host/premake.c +++ b/src/host/premake.c @@ -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); diff --git a/src/host/premake.h b/src/host/premake.h index 562d11a5..98f6df29 100644 --- a/src/host/premake.h +++ b/src/host/premake.h @@ -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); diff --git a/src/host/term_textColor.c b/src/host/term_textColor.c new file mode 100644 index 00000000..20e5e0a7 --- /dev/null +++ b/src/host/term_textColor.c @@ -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; + }