/
curses.c
100 lines (83 loc) · 1.98 KB
/
curses.c
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
91
92
93
94
95
96
97
98
99
100
#include <unistd.h>
#include <curses.h>
#include <caml/mlvalues.h>
#include <caml/memory.h>
value curses_initscr(value unit)
{
CAMLparam1 (unit);
CAMLreturn ((value) initscr()); /* OK to coerce directly from WINDOW * to
value since that's a block created by malloc() */
}
value curses_wrefresh(value win)
{
CAMLparam1 (win);
wrefresh((WINDOW *) win);
CAMLreturn (Val_unit);
}
value curses_newwin(value nlines, value ncols, value x0, value y0)
{
CAMLparam4 (nlines, ncols, x0, y0);
CAMLreturn ((value) newwin(Int_val(nlines), Int_val(ncols),
Int_val(x0), Int_val(y0)));
}
value curses_addch(value c)
{
CAMLparam1 (c);
addch(Int_val(c)); /* Characters are encoded like integers */
CAMLreturn (Val_unit);
}
value curses_mvwaddch(value win, value y, value x, value c)
{
CAMLparam4 (win, y, x, c);
mvwaddch((WINDOW *)win, Int_val(y), Int_val(x), Int_val(c)); /* Characters are encoded like integers */
CAMLreturn (Val_unit);
}
value curses_addstr(value s)
{
CAMLparam1 (s);
addstr(String_val(s));
CAMLreturn (Val_unit);
}
value curses_get_lines(value unit)
{
CAMLparam1 (unit);
CAMLreturn (Val_int(LINES));
}
value curses_get_cols(value unit)
{
CAMLparam1 (unit);
CAMLreturn (Val_int(COLS));
}
value curses_noecho(value unit)
{
CAMLparam1 (unit);
noecho();
CAMLreturn (Val_unit);
}
value curses_endwin(value unit)
{
CAMLparam1 (unit);
endwin();
CAMLreturn (Val_unit);
}
value curses_leaveok(value win, value b)
{
CAMLparam2 (win, b);
CAMLreturn (leaveok((WINDOW *)win, Int_val(b)));
}
value curses_scrollok(value win, value b)
{
CAMLparam2 (win, b);
CAMLreturn (scrollok((WINDOW *)win, Int_val(b)));
}
value curses_mvcur(value i1, value i2, value i3, value i4)
{
CAMLparam4 (i1, i2, i3, i4);
CAMLreturn (mvcur(Int_val(i1), Int_val(i2), Int_val(i3), Int_val(i4)));
}
value curses_usleep(value i)
{
CAMLparam1 (i);
usleep(Int_val(i));
CAMLreturn (Val_unit);
}