aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjluehrs2 <jluehrs2@uiuc.edu>2008-03-18 15:11:44 -0500
committerjluehrs2 <jluehrs2@uiuc.edu>2008-03-18 15:11:44 -0500
commit4b7d8b7ef50d1bcdf5de02bb737d585fc4950a75 (patch)
tree5bf88e0565f5e71d9c09d6bcc2f42e0bebb1b9f6
parent0ff6783d7f0f8822f61116e6da4318d737b2cb74 (diff)
downloadluancurses-4b7d8b7ef50d1bcdf5de02bb737d585fc4950a75.tar.gz
luancurses-4b7d8b7ef50d1bcdf5de02bb737d585fc4950a75.zip
implement use_default_colors and assume_default_colors as functions available to lua rather than calling use_default_colors automatically in start_color
-rw-r--r--src/curses.c45
1 files changed, 44 insertions, 1 deletions
diff --git a/src/curses.c b/src/curses.c
index 23a0a69..564bdbf 100644
--- a/src/curses.c
+++ b/src/curses.c
@@ -55,6 +55,16 @@ static void register_color(const char* color_str, int color_tag, void* data)
ncolors++;
}
+static void register_default_color(lua_State* L)
+{
+ lua_getfield(L, LUA_REGISTRYINDEX, REG_TABLE);
+ lua_getfield(L, -1, "colors");
+ lua_pushinteger(L, -1);
+ lua_setfield(L, -2, "default");
+ lua_pop(L, 2);
+ default_color_available = 1;
+}
+
static void init_colors(lua_State* L)
{
lua_getfield(L, LUA_REGISTRYINDEX, REG_TABLE);
@@ -162,7 +172,6 @@ static int l_start_color(lua_State* L)
init_color_pairs(L);
init_colors(L);
lua_pushboolean(L, start_color() == OK);
- use_default_colors();
}
else {
lua_pushboolean(L, FALSE);
@@ -171,6 +180,38 @@ static int l_start_color(lua_State* L)
return 1;
}
+static int l_use_default_colors(lua_State* L)
+{
+ register_default_color(L);
+ lua_pushboolean(L, use_default_colors() == OK);
+ return 1;
+}
+
+static int l_assume_default_colors(lua_State* L)
+{
+ const char* fg;
+ const char* bg;
+ int nfg, nbg;
+
+ register_default_color(L);
+
+ fg = luaL_optlstring(L, 1, "default", NULL);
+ bg = luaL_optlstring(L, 2, "default", NULL);
+
+ lua_getfield(L, LUA_REGISTRYINDEX, REG_TABLE);
+ lua_getfield(L, -1, "colors");
+ lua_getfield(L, -1, fg);
+ nfg = luaL_checkint(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, -1, bg);
+ nbg = luaL_checkint(L, -1);
+ lua_pop(L, 3);
+
+ lua_pushboolean(L, assume_default_colors(nfg, nbg) == OK);
+ return 1;
+}
+
static int l_setup_term(lua_State* L)
{
int ret = 0;
@@ -615,6 +656,8 @@ const luaL_Reg reg[] = {
{ "endwin", l_endwin },
{ "isendwin", l_isendwin },
{ "start_color", l_start_color },
+ { "use_default_colors", l_use_default_colors },
+ { "assume_default_colors", l_assume_default_colors },
{ "setup_term", l_setup_term },
{ "init_color", l_init_color },
{ "init_pair", l_init_pair },