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