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