aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2010-12-15 01:53:33 +0500
committerWaqas Hussain <waqas20@gmail.com>2010-12-15 01:53:33 +0500
commitd3aac67ca6730108e857ef1202ae81c844252dad (patch)
tree1e191f9a92ac42dd4e9b22e36d224c91117676d6
parent91b6b03395c13347506865c97a7e2845d19cc6f9 (diff)
downloadprosody-d3aac67ca6730108e857ef1202ae81c844252dad.tar.gz
prosody-d3aac67ca6730108e857ef1202ae81c844252dad.zip
util-src/windows.c: Added get_consolecolor, set_consolecolor.
-rw-r--r--util-src/windows.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/util-src/windows.c b/util-src/windows.c
index 12bd7ce9..e1e07608 100644
--- a/util-src/windows.c
+++ b/util-src/windows.c
@@ -43,9 +43,38 @@ static int Lget_nameservers(lua_State *L) {
}
}
+static void lassert(lua_State *L, BOOL test, char* string) {
+ if (!test) {
+ luaL_error(L, "%s: %d", string, GetLastError());
+ }
+}
+
+static int Lget_consolecolor(lua_State *L) {
+ HWND console = GetStdHandle(STD_OUTPUT_HANDLE);
+ WORD color; DWORD read_len;
+
+ CONSOLE_SCREEN_BUFFER_INFO info;
+
+ lassert(L, console != INVALID_HANDLE_VALUE, "GetStdHandle");
+ lassert(L, GetConsoleScreenBufferInfo(console, &info), "GetConsoleScreenBufferInfo");
+ lassert(L, ReadConsoleOutputAttribute(console, &color, sizeof(WORD), info.dwCursorPosition, &read_len), "ReadConsoleOutputAttribute");
+
+ lua_pushnumber(L, color);
+ return 1;
+}
+static int Lset_consolecolor(lua_State *L) {
+ int color = luaL_checkint(L, 1);
+ HWND console = GetStdHandle(STD_OUTPUT_HANDLE);
+ lassert(L, console != INVALID_HANDLE_VALUE, "GetStdHandle");
+ lassert(L, SetConsoleTextAttribute(console, color), "SetConsoleTextAttribute");
+ return 0;
+}
+
static const luaL_Reg Reg[] =
{
{ "get_nameservers", Lget_nameservers },
+ { "get_consolecolor", Lget_consolecolor },
+ { "set_consolecolor", Lset_consolecolor },
{ NULL, NULL }
};