1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#include <curses.h>
#include <lua.h>
/* necessary because atexit() expects a function that returns void, and gcc
* whines otherwise */
static void _endwin(void)
{
endwin();
}
static int l_initialize(lua_State* L)
{
int ret;
/* XXX: do we want to do this? how important is cleaning up? */
signal(SIGTERM, exit);
atexit(_endwin);
ret = initscr();
if (has_colors()) {
start_color();
}
lua_pushboolean(L, ret == OK);
return 1;
}
static int l_initscr(lua_State* L)
{
lua_pushboolean(L, initscr() == OK);
return 1;
}
static int l_setup_term(lua_State* L)
{
int ret = 0;
luaL_checktype(L, 1, LUA_TTABLE);
lua_pushnil(L);
while (lua_next(L, t) != 0) {
if (lua_isstring(L, -2)) {
char* str;
str = lua_tostring(L, -2);
/* XXX: this certainly needs expansion */
if (!strcmp(str, "nl")) {
ret += ((lua_toboolean(L, -1) ? nl() : nonl()) == OK);
}
else if (!strcmp(str, "cbreak")) {
ret += ((lua_toboolean(L, -1) ? cbreak() : nocbreak()) == OK);
}
else if (!strcmp(str, "echo")) {
ret += ((lua_toboolean(L, -1) ? echo() : noecho()) == OK);
}
else if (!strcmp(str, "keypad")) {
ret += ((keypad(stdscr, lua_toboolean(L, -1))) == OK);
}
else {
luaL_error(L, "Unknown or unimplemented terminal mode %s", str);
}
}
lua_pop(L, 1);
}
lua_pushnumber(L, ret);
return 1;
}
static int l_init_pair(lua_State* L)
{
}
static int l_getch(lua_State* L)
{
}
static int l_move(lua_State* L)
{
}
static int l_addch(lua_State* L)
{
}
static int l_refresh(lua_State* L)
{
}
int luaopen_ncurses(lua_State* L)
{
}
|