]> gitweb.factorcode.org Git - factor.git/blob - extra/curses/ffi/ffi.factor
curses: start support for mouse events
[factor.git] / extra / curses / ffi / ffi.factor
1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien alien.c-types alien.libraries
4 alien.syntax classes.struct combinators kernel math system unix.types ;
5 IN: curses.ffi
6
7 << "curses" {
8     { [ os winnt? ]  [ "libcurses.dll" ] }
9     { [ os macosx? ] [ "libcurses.dylib" ] }
10     { [ os unix?  ]  [ "libncurses.so.5.7" ] }
11 } cond cdecl add-library >>
12
13 C-TYPE: WINDOW
14 C-TYPE: SCREEN
15 TYPEDEF: void* va_list
16
17 TYPEDEF: uint chtype
18 TYPEDEF: chtype attr_t
19 TYPEDEF: short NCURSES_SIZE_T
20 TYPEDEF: ushort wchar_t
21 TYPEDEF: ulong mmask_t
22
23 CONSTANT: CCHARW_MAX  5
24
25 CONSTANT: ERR -1
26 CONSTANT: FALSE 0
27 CONSTANT: TRUE 1
28
29 STRUCT: cchar_t
30 { attr attr_t }
31 { chars { wchar_t CCHARW_MAX } } ;
32
33 STRUCT: pdat
34 { _pad_y NCURSES_SIZE_T }
35 { _pad_x NCURSES_SIZE_T }
36 { _pad_top NCURSES_SIZE_T }
37 { _pad_left NCURSES_SIZE_T }
38 { _pad_bottom NCURSES_SIZE_T }
39 { _pad_right NCURSES_SIZE_T } ;
40
41 STRUCT: c-window
42 { _cury NCURSES_SIZE_T }
43 { _curx NCURSES_SIZE_T }
44
45 { _maxy NCURSES_SIZE_T }
46 { _maxx NCURSES_SIZE_T }
47 { _begy NCURSES_SIZE_T }
48 { _begx NCURSES_SIZE_T }
49
50 { _flags short }
51
52 { _attrs attr_t }
53 { _bkgd chtype }
54
55 { _notimeout bool }
56 { _clear bool }
57 { _leaveok bool }
58 { _scroll bool }
59 { _idlok bool }
60 { _idcok bool }
61 { _immed bool }
62 { _sync bool }
63 { _use_keypad bool }
64 { _delay int }
65
66 { _line c-string }
67 { _regtop NCURSES_SIZE_T }
68 { _regbottom NCURSES_SIZE_T }
69
70 { _parx int }
71 { _pary int }
72 { _parent WINDOW* }
73
74 { _pad pdat }
75
76 { _yoffset NCURSES_SIZE_T }
77
78 { _bkgrnd cchar_t } ;
79
80 STRUCT: MEVENT
81     { id short }
82     { x int } { y int } { z int }
83     { bstate mmask_t } ;
84
85 LIBRARY: curses
86
87 C-GLOBAL: void* stdscr
88
89 FUNCTION: WINDOW* initscr ( ) ;
90 FUNCTION: int endwin ( ) ;
91 FUNCTION: bool isendwin ( ) ;
92 FUNCTION: SCREEN* newterm ( c-string type, FILE* outfd, FILE* infd ) ;
93 FUNCTION: SCREEN* set_term ( SCREEN* new ) ;
94 FUNCTION: void delscreen ( SCREEN* sp ) ;
95
96 FUNCTION: int def_prog_mode ( ) ;
97 FUNCTION: int def_shell_mode ( ) ;
98 FUNCTION: int reset_prog_mode ( ) ;
99 FUNCTION: int reset_shell_mode ( ) ;
100 FUNCTION: int resetty ( ) ;
101 FUNCTION: int savetty ( ) ;
102 FUNCTION: int ripoffline ( int line, void* callback ) ;
103 FUNCTION: int curs_set ( int visibility ) ;
104 FUNCTION: int napms ( int ms ) ;
105
106 FUNCTION: WINDOW* newwin ( int nlines, int ncols, int begin_y, int begin_x ) ;
107 FUNCTION: int delwin ( WINDOW* win ) ;
108 FUNCTION: int mvwin ( WINDOW* win, int y, int x ) ;
109 FUNCTION: WINDOW* subwin ( WINDOW* orig, int nlines, int ncols, int begin_y, int begin_x ) ;
110 FUNCTION: WINDOW* derwin ( WINDOW* orig, int nlines, int ncols, int begin_y, int begin_x ) ;
111 FUNCTION: int mvderwin ( WINDOW* win, int par_y, int par_x ) ;
112 FUNCTION: WINDOW* dupwin ( WINDOW* win ) ;
113 FUNCTION: void wsyncup ( WINDOW* win ) ;
114 FUNCTION: int syncok ( WINDOW* win, bool bf ) ;
115 FUNCTION: void wcursyncup ( WINDOW* win ) ;
116 FUNCTION: void wsyncdown ( WINDOW* win ) ;
117
118 FUNCTION: int cbreak ( ) ;
119 FUNCTION: int nocbreak ( ) ;
120 FUNCTION: int echo ( ) ;
121 FUNCTION: int noecho ( ) ;
122 FUNCTION: int halfdelay ( int tenths ) ;
123 FUNCTION: int intrflush ( WINDOW* win, bool bf ) ;
124 FUNCTION: int keypad ( WINDOW* win, bool bf ) ;
125 FUNCTION: int meta ( WINDOW* win, bool bf ) ;
126 FUNCTION: int nodelay ( WINDOW* win, bool bf ) ;
127 FUNCTION: int raw ( ) ;
128 FUNCTION: int noraw ( ) ;
129 FUNCTION: void noqiflush ( ) ;
130 FUNCTION: void qiflush ( ) ;
131 FUNCTION: int notimeout ( WINDOW* win, bool bf ) ;
132 FUNCTION: void timeout ( int delay ) ;
133 FUNCTION: void wtimeout ( WINDOW* win, int delay ) ;
134 FUNCTION: int typeahead ( int fd ) ;
135
136 FUNCTION: int clearok ( WINDOW* win, bool bf ) ;
137 FUNCTION: int idlok ( WINDOW* win, bool bf ) ;
138 FUNCTION: void idcok ( WINDOW* win, bool bf ) ;
139 FUNCTION: void immedok ( WINDOW* win, bool bf ) ;
140 FUNCTION: int leaveok ( WINDOW* win, bool bf ) ;
141 FUNCTION: int setscrreg ( int top, int bot ) ;
142 FUNCTION: int wsetscrreg ( WINDOW* win, int top, int bot ) ;
143 FUNCTION: int scrollok ( WINDOW* win, bool bf ) ;
144 FUNCTION: int nl ( ) ;
145 FUNCTION: int nonl ( ) ;
146
147 FUNCTION: int erase ( ) ;
148 FUNCTION: int werase ( WINDOW* win ) ;
149 FUNCTION: int clear ( ) ;
150 FUNCTION: int wclear ( WINDOW* win ) ;
151 FUNCTION: int clrtobot ( ) ;
152 FUNCTION: int wclrtobot ( WINDOW* win ) ;
153 FUNCTION: int clrtoeol ( ) ;
154 FUNCTION: int wclrtoeol ( WINDOW* win ) ;
155
156 FUNCTION: int refresh ( ) ;
157 FUNCTION: int wrefresh ( WINDOW* win ) ;
158 FUNCTION: int wnoutrefresh ( WINDOW* win ) ;
159 FUNCTION: int doupdate ( ) ;
160 FUNCTION: int redrawwin ( WINDOW* win ) ;
161 FUNCTION: int wredrawln ( WINDOW* win, int beg_line, int num_lines ) ;
162
163 FUNCTION: int getch ( ) ;
164 FUNCTION: int wgetch ( WINDOW* win ) ;
165 FUNCTION: int mvgetch ( int y, int x ) ;
166 FUNCTION: int mvwgetch ( WINDOW* win, int y, int x ) ;
167 FUNCTION: int ungetch ( int ch ) ;
168 FUNCTION: int has_key ( int ch ) ;
169
170 FUNCTION: int getstr ( c-string str ) ;
171 FUNCTION: int getnstr ( c-string str, int n ) ;
172 FUNCTION: int wgetstr ( WINDOW* win, c-string str ) ;
173 FUNCTION: int wgetnstr ( WINDOW* win, c-string str, int n ) ;
174 FUNCTION: int mvgetstr ( int y, int x, c-string str ) ;
175 FUNCTION: int mvwgetstr ( WINDOW* win, int y, int x, c-string str ) ;
176 FUNCTION: int mvgetnstr ( int y, int x, c-string str, int n ) ;
177 FUNCTION: int mvwgetnstr ( WINDOW* win, int y, int x, c-string str, int n ) ;
178
179 FUNCTION: int printw ( c-string fmt, int lol ) ;
180 FUNCTION: int wprintw ( WINDOW* win, c-string fmt, int lol ) ;
181 FUNCTION: int mvprintw ( int y, int x, c-string fmt, int lol ) ;
182 FUNCTION: int mvwprintw ( WINDOW* win, int y, int x, c-string fmt, int lol ) ;
183 FUNCTION: int vwprintw ( WINDOW* win, c-string fmt, va_list varglist ) ;
184 FUNCTION: int vw_printw ( WINDOW* win, c-string fmt, va_list varglist ) ;
185
186 FUNCTION: int move ( int y, int x ) ;
187 FUNCTION: int wmove ( WINDOW* win, int y, int x ) ;
188
189 FUNCTION: int scroll ( WINDOW* win ) ;
190 FUNCTION: int scrl ( int n ) ;
191 FUNCTION: int wscrl ( WINDOW* win, int n ) ;
192
193 ! int setupterm(char *term, int fildes, int *errret);
194 ! int setterm(char *term);
195 ! TERMINAL *set_curterm(TERMINAL *nterm);
196 ! int del_curterm(TERMINAL *oterm);
197 ! int restartterm(const char *term, int fildes, int *errret);
198 ! char *tparm(char *str, ...);
199 ! int tputs(const char *str, int affcnt, int (*putc)(int));
200 ! int putp(const char *str);
201 ! int vidputs(chtype attrs, int (*putc)(int));
202 ! int vidattr(chtype attrs);
203 ! int vid_puts(attr_t attrs, short pair, void *opts, int (*putc)(char));
204 ! int vid_attr(attr_t attrs, short pair, void *opts);
205 FUNCTION: int mvcur ( int oldrow, int oldcol, int newrow, int newcol ) ;
206 ! int tigetflag(char *capname);
207 ! int tigetnum(char *capname);
208 ! char *tigetstr(char *capname);
209
210 FUNCTION: int touchwin ( WINDOW* win ) ;
211 FUNCTION: int touchline ( WINDOW* win, int start, int count ) ;
212 FUNCTION: int untouchwin ( WINDOW* win ) ;
213 FUNCTION: int wtouchln ( WINDOW* win, int y, int n, int changed ) ;
214 FUNCTION: bool is_linetouched ( WINDOW* win, int line ) ;
215 FUNCTION: bool is_wintouched ( WINDOW* win ) ;
216
217 FUNCTION: int insch ( chtype ch ) ;
218 FUNCTION: int winsch ( WINDOW* win, chtype ch ) ;
219 FUNCTION: int mvinsch ( int y, int x, chtype ch ) ;
220 FUNCTION: int mvwinsch ( WINDOW* win, int y, int x, chtype ch ) ;
221 FUNCTION: int delch ( ) ;
222 FUNCTION: int wdelch ( WINDOW* win ) ;
223 FUNCTION: int mvdelch ( int y, int x ) ;
224 FUNCTION: int mvwdelch ( WINDOW* win, int y, int x ) ;
225
226 FUNCTION: int deleteln ( ) ;
227 FUNCTION: int wdeleteln ( WINDOW* win ) ;
228 FUNCTION: int insdelln ( int n ) ;
229 FUNCTION: int winsdelln ( WINDOW* win, int n ) ;
230 FUNCTION: int insertln ( ) ;
231 FUNCTION: int winsertln ( WINDOW* win ) ;
232
233 FUNCTION: int addstr ( c-string str ) ;
234 FUNCTION: int addnstr ( c-string str, int n ) ;
235 FUNCTION: int waddstr ( WINDOW* win, c-string str ) ;
236 FUNCTION: int waddnstr ( WINDOW* win, c-string str, int n ) ;
237 FUNCTION: int mvaddstr ( int y, int x, c-string str ) ;
238 FUNCTION: int mvaddnstr ( int y, int x, c-string str, int n ) ;
239 FUNCTION: int mvwaddstr ( WINDOW* win, int y, int x, c-string str ) ;
240 FUNCTION: int mvwaddnstr ( WINDOW* win, int y, int x, c-string str, int n ) ;
241
242 FUNCTION: int waddch ( WINDOW* win, chtype ch ) ;
243
244 FUNCTION: int start_color ( ) ;
245 FUNCTION: int init_pair ( short pair, short f, short b ) ;
246 FUNCTION: int init_color ( short color, short r, short g, short b ) ;
247 FUNCTION: bool has_colors ( ) ;
248 FUNCTION: bool can_change_color ( ) ;
249 FUNCTION: int color_content ( short color, short* r, short* g, short* b ) ;
250 FUNCTION: int pair_content ( short pair, short* f, short* b ) ;
251
252 C-GLOBAL: int COLORS
253 C-GLOBAL: int COLOR_PAIRS
254
255 : COLOR_PAIR ( n -- n' ) 8 shift ; inline foldable
256
257 FUNCTION: int wattron ( WINDOW* win, int attrs ) ;
258 FUNCTION: int wattroff ( WINDOW* win, int attrs ) ;
259 FUNCTION: int wattrset ( WINDOW* win, int attrs ) ;
260
261 : NCURSES_MOUSE_MASK ( b m -- mask ) swap 1 - 5 * shift ; inline
262
263 CONSTANT: NCURSES_BUTTON_RELEASED OCT: 01
264 CONSTANT: NCURSES_BUTTON_PRESSED  OCT: 02
265 CONSTANT: NCURSES_BUTTON_CLICKED  OCT: 04
266 CONSTANT: NCURSES_DOUBLE_CLICKED  OCT: 10
267 CONSTANT: NCURSES_TRIPLE_CLICKED  OCT: 20
268 CONSTANT: NCURSES_RESERVED_EVENT  OCT: 40
269
270 FUNCTION: int getmouse ( MEVENT* event ) ;
271 FUNCTION: int ungetmouse ( MEVENT* event ) ;
272 FUNCTION: mmask_t mousemask ( mmask_t newmask, mmask_t* oldmask ) ;
273 FUNCTION: bool wenclose ( WINDOW* win, int y, int x ) ;
274 FUNCTION: bool mouse_trafo ( int* pY, int* pX, bool to_screen ) ;
275 FUNCTION: bool wmouse_trafo ( WINDOW* win, int* pY, int* pX, bool to_screen ) ;
276 FUNCTION: int mouseinterval ( int erval ) ;