1 | [[tags: egg]] |
---|
2 | |
---|
3 | == ncurses |
---|
4 | |
---|
5 | [[toc:]] |
---|
6 | |
---|
7 | === Description |
---|
8 | |
---|
9 | Provides text-mode and terminal operations for text-based user interfaces. |
---|
10 | |
---|
11 | === Author |
---|
12 | |
---|
13 | [[/users/felix winkelmann|felix winkelmann]] |
---|
14 | |
---|
15 | === Requirements |
---|
16 | |
---|
17 | [[easyffi]] |
---|
18 | |
---|
19 | === Download |
---|
20 | |
---|
21 | [[http://www.call-with-current-continuation.org/eggs/ncurses.egg|ncurses.egg]] |
---|
22 | |
---|
23 | === Documentation |
---|
24 | |
---|
25 | The following definitions are provided (full documentation can be |
---|
26 | found in your system's {{man}} pages): |
---|
27 | |
---|
28 | ==== Constants |
---|
29 | |
---|
30 | * <constant>A_ALTCHARSET</constant> |
---|
31 | * <constant>A_ATTRIBUTES</constant> |
---|
32 | * <constant>A_BLINK</constant> |
---|
33 | * <constant>A_BOLD</constant> |
---|
34 | * <constant>A_CHARTEXT</constant> |
---|
35 | * <constant>A_COLOR</constant> |
---|
36 | * <constant>A_DIM</constant> |
---|
37 | * <constant>A_INVIS</constant> |
---|
38 | * <constant>A_LEFT</constant> |
---|
39 | * <constant>A_LOW</constant> |
---|
40 | * <constant>A_NORMAL</constant> |
---|
41 | * <constant>A_PROTECT</constant> |
---|
42 | * <constant>A_REVERSE</constant> |
---|
43 | * <constant>A_RIGHT</constant> |
---|
44 | * <constant>A_STANDOUT</constant> |
---|
45 | * <constant>A_TOP</constant> |
---|
46 | * <constant>A_UNDERLINE</constant> |
---|
47 | * <constant>A_VERTICAL</constant> |
---|
48 | * <constant>COLOR_BLACK</constant> |
---|
49 | * <constant>COLOR_BLUE</constant> |
---|
50 | * <constant>COLOR_CYAN</constant> |
---|
51 | * <constant>COLOR_GREEN</constant> |
---|
52 | * <constant>COLOR_MAGENTA</constant> |
---|
53 | * <constant>COLOR_PAIR</constant> |
---|
54 | * <constant>COLOR_RED</constant> |
---|
55 | * <constant>COLOR_WHITE</constant> |
---|
56 | * <constant>COLOR_YELLOW</constant> |
---|
57 | * <constant>KEY_A1</constant> |
---|
58 | * <constant>KEY_A3</constant> |
---|
59 | * <constant>KEY_B2</constant> |
---|
60 | * <constant>KEY_BACKSPACE</constant> |
---|
61 | * <constant>KEY_BEG</constant> |
---|
62 | * <constant>KEY_BREAK</constant> |
---|
63 | * <constant>KEY_BTAB</constant> |
---|
64 | * <constant>KEY_C1</constant> |
---|
65 | * <constant>KEY_C3</constant> |
---|
66 | * <constant>KEY_CANCEL</constant> |
---|
67 | * <constant>KEY_CATAB</constant> |
---|
68 | * <constant>KEY_CLEAR</constant> |
---|
69 | * <constant>KEY_CLOSE</constant> |
---|
70 | * <constant>KEY_CODE_YES</constant> |
---|
71 | * <constant>KEY_COMMAND</constant> |
---|
72 | * <constant>KEY_COPY</constant> |
---|
73 | * <constant>KEY_CREATE</constant> |
---|
74 | * <constant>KEY_CTAB</constant> |
---|
75 | * <constant>KEY_DC</constant> |
---|
76 | * <constant>KEY_DL</constant> |
---|
77 | * <constant>KEY_DOWN</constant> |
---|
78 | * <constant>KEY_EIC</constant> |
---|
79 | * <constant>KEY_END</constant> |
---|
80 | * <constant>KEY_ENTER</constant> |
---|
81 | * <constant>KEY_EOL</constant> |
---|
82 | * <constant>KEY_EOS</constant> |
---|
83 | * <constant>KEY_EXIT</constant> |
---|
84 | * <constant>KEY_F0</constant> |
---|
85 | * <constant>KEY_FIND</constant> |
---|
86 | * <constant>KEY_HELP</constant> |
---|
87 | * <constant>KEY_HOME</constant> |
---|
88 | * <constant>KEY_IC</constant> |
---|
89 | * <constant>KEY_IL</constant> |
---|
90 | * <constant>KEY_LEFT</constant> |
---|
91 | * <constant>KEY_LL</constant> |
---|
92 | * <constant>KEY_MARK</constant> |
---|
93 | * <constant>KEY_MESSAGE</constant> |
---|
94 | * <constant>KEY_MIN</constant> |
---|
95 | * <constant>KEY_MOUSE</constant> |
---|
96 | * <constant>KEY_MOVE</constant> |
---|
97 | * <constant>KEY_NEXT</constant> |
---|
98 | * <constant>KEY_NPAGE</constant> |
---|
99 | * <constant>KEY_OPEN</constant> |
---|
100 | * <constant>KEY_OPTIONS</constant> |
---|
101 | * <constant>KEY_PPAGE</constant> |
---|
102 | * <constant>KEY_PREVIOUS</constant> |
---|
103 | * <constant>KEY_PRINT</constant> |
---|
104 | * <constant>KEY_REDO</constant> |
---|
105 | * <constant>KEY_REFERENCE</constant> |
---|
106 | * <constant>KEY_REFRESH</constant> |
---|
107 | * <constant>KEY_REPLACE</constant> |
---|
108 | * <constant>KEY_RESET</constant> |
---|
109 | * <constant>KEY_RESIZE</constant> |
---|
110 | * <constant>KEY_RESTART</constant> |
---|
111 | * <constant>KEY_RESUME</constant> |
---|
112 | * <constant>KEY_RIGHT</constant> |
---|
113 | * <constant>KEY_SAVE</constant> |
---|
114 | * <constant>KEY_SBEG</constant> |
---|
115 | * <constant>KEY_SCANCEL</constant> |
---|
116 | * <constant>KEY_SCOMMAND</constant> |
---|
117 | * <constant>KEY_SCOPY</constant> |
---|
118 | * <constant>KEY_SCREATE</constant> |
---|
119 | * <constant>KEY_SDC</constant> |
---|
120 | * <constant>KEY_SDL</constant> |
---|
121 | * <constant>KEY_SELECT</constant> |
---|
122 | * <constant>KEY_SEND</constant> |
---|
123 | * <constant>KEY_SEOL</constant> |
---|
124 | * <constant>KEY_SEXIT</constant> |
---|
125 | * <constant>KEY_SF</constant> |
---|
126 | * <constant>KEY_SFIND</constant> |
---|
127 | * <constant>KEY_SHELP</constant> |
---|
128 | * <constant>KEY_SHOME</constant> |
---|
129 | * <constant>KEY_SIC</constant> |
---|
130 | * <constant>KEY_SLEFT</constant> |
---|
131 | * <constant>KEY_SMESSAGE</constant> |
---|
132 | * <constant>KEY_SMOVE</constant> |
---|
133 | * <constant>KEY_SNEXT</constant> |
---|
134 | * <constant>KEY_SOPTIONS</constant> |
---|
135 | * <constant>KEY_SPREVIOUS</constant> |
---|
136 | * <constant>KEY_SPRINT</constant> |
---|
137 | * <constant>KEY_SR</constant> |
---|
138 | * <constant>KEY_SREDO</constant> |
---|
139 | * <constant>KEY_SREPLACE</constant> |
---|
140 | * <constant>KEY_SRESET</constant> |
---|
141 | * <constant>KEY_SRIGHT</constant> |
---|
142 | * <constant>KEY_SRSUME</constant> |
---|
143 | * <constant>KEY_SSAVE</constant> |
---|
144 | * <constant>KEY_SSUSPEND</constant> |
---|
145 | * <constant>KEY_STAB</constant> |
---|
146 | * <constant>KEY_SUNDO</constant> |
---|
147 | * <constant>KEY_SUSPEND</constant> |
---|
148 | * <constant>KEY_UNDO</constant> |
---|
149 | * <constant>KEY_UP</constant> |
---|
150 | |
---|
151 | ==== Variables |
---|
152 | |
---|
153 | * <procedure>(ACS_BLOCK)</procedure> |
---|
154 | * <procedure>(ACS_BTEE)</procedure> |
---|
155 | * <procedure>(ACS_BULLET)</procedure> |
---|
156 | * <procedure>(ACS_CKBOARD)</procedure> |
---|
157 | * <procedure>(ACS_DARROW)</procedure> |
---|
158 | * <procedure>(ACS_DEGREE)</procedure> |
---|
159 | * <procedure>(ACS_DIAMOND)</procedure> |
---|
160 | * <procedure>(ACS_HLINE)</procedure> |
---|
161 | * <procedure>(ACS_LANTERN)</procedure> |
---|
162 | * <procedure>(ACS_LARROW)</procedure> |
---|
163 | * <procedure>(ACS_LLCORNER)</procedure> |
---|
164 | * <procedure>(ACS_LRCORNER)</procedure> |
---|
165 | * <procedure>(ACS_LTEE)</procedure> |
---|
166 | * <procedure>(ACS_PLMINUS)</procedure> |
---|
167 | * <procedure>(ACS_PLUS)</procedure> |
---|
168 | * <procedure>(ACS_RARROW)</procedure> |
---|
169 | * <procedure>(ACS_RTEE)</procedure> |
---|
170 | * <procedure>(ACS_S1)</procedure> |
---|
171 | * <procedure>(ACS_S9)</procedure> |
---|
172 | * <procedure>(ACS_TTEE)</procedure> |
---|
173 | * <procedure>(ACS_UARROW)</procedure> |
---|
174 | * <procedure>(ACS_ULCORNER)</procedure> |
---|
175 | * <procedure>(ACS_URCORNER)</procedure> |
---|
176 | * <procedure>(ACS_VLINE)</procedure> |
---|
177 | * <procedure>(COLORS)</procedure> |
---|
178 | * <procedure>(COLOR_PAIRS)</procedure> |
---|
179 | * <procedure>(LINES)</procedure> |
---|
180 | * <procedure>(COLS)</procedure> |
---|
181 | |
---|
182 | All these return an integer value as their result. |
---|
183 | |
---|
184 | * <procedure>(stdscr)</procedure> |
---|
185 | * <procedure>(curscr)</procedure> |
---|
186 | |
---|
187 | These two procedures return a {{WINDOW}} object. |
---|
188 | |
---|
189 | ==== Procedures |
---|
190 | |
---|
191 | * <procedure>(KEY_F INT)</procedure> |
---|
192 | * <procedure>(PAIR_NUMBER INT)</procedure> |
---|
193 | |
---|
194 | These two procedures return an integer. |
---|
195 | |
---|
196 | * <procedure>(addch CHAR)</procedure> |
---|
197 | * <procedure>(addnstr STRING INT)</procedure> |
---|
198 | * <procedure>(addstr STRING)</procedure> |
---|
199 | * <procedure>(attroff INT)</procedure> |
---|
200 | * <procedure>(attron INT)</procedure> |
---|
201 | * <procedure>(attrset INT)</procedure> |
---|
202 | * <procedure>(beep)</procedure> |
---|
203 | * <procedure>(border CHAR CHAR CHAR CHAR CHAR CHAR CHAR CHAR)</procedure> |
---|
204 | * <procedure>(box WINDOW CHAR CHAR)</procedure> |
---|
205 | |
---|
206 | <procedure>(can_change_color)</procedure> |
---|
207 | |
---|
208 | Returns a boolean. |
---|
209 | |
---|
210 | * <procedure>(cbreak)</procedure> |
---|
211 | * <procedure>(clear)</procedure> |
---|
212 | * <procedure>(clearok WINDOW BOOL)</procedure> |
---|
213 | * <procedure>(clrtobot)</procedure> |
---|
214 | * <procedure>(clrtoeol)</procedure> |
---|
215 | * <procedure>(copywin WINDOW WINDOW INT INT INT INT INT INT BOOL)</procedure> |
---|
216 | * <procedure>(curs_set INT)</procedure> |
---|
217 | * <procedure>(def_prog_mode)</procedure> |
---|
218 | * <procedure>(def_shell_mode)</procedure> |
---|
219 | * <procedure>(delay_output INT)</procedure> |
---|
220 | * <procedure>(delch)</procedure> |
---|
221 | * <procedure>(deleteln)</procedure> |
---|
222 | * <procedure>(delwin WINDOW)</procedure> |
---|
223 | * <procedure>(derwin WINDOW INT INT INT INT)</procedure> |
---|
224 | * <procedure>(doupdate)</procedure> |
---|
225 | * <procedure>(echo)</procedure> |
---|
226 | * <procedure>(echochar WINDOW CHAR)</procedure> |
---|
227 | * <procedure>(endwin)</procedure> |
---|
228 | * <procedure>(erase)</procedure> |
---|
229 | |
---|
230 | <procedure>(erasechar)</procedure> |
---|
231 | |
---|
232 | Returns the erased character. |
---|
233 | |
---|
234 | * <procedure>(flash)</procedure> |
---|
235 | * <procedure>(flushinp)</procedure> |
---|
236 | |
---|
237 | <procedure>(getbegyx WINDOW)</procedure> |
---|
238 | |
---|
239 | Returns two integer values. |
---|
240 | |
---|
241 | <procedure>(getch)</procedure> |
---|
242 | |
---|
243 | Returns a character value. |
---|
244 | |
---|
245 | <procedure>(getmaxyx WINDOW)</procedure> |
---|
246 | |
---|
247 | Returns two integer values. |
---|
248 | |
---|
249 | <procedure>(getnstr STRING INT)</procedure> |
---|
250 | |
---|
251 | <procedure>(getparyx WINDOW)</procedure> |
---|
252 | |
---|
253 | Returns two integer values. |
---|
254 | |
---|
255 | <procedure>(getstr STRING)</procedure> |
---|
256 | |
---|
257 | <procedure>(getsyx)</procedure> |
---|
258 | |
---|
259 | Returns two integer values. |
---|
260 | |
---|
261 | <procedure>(getyx WINDOW)</procedure> |
---|
262 | |
---|
263 | Returns two integer values. |
---|
264 | |
---|
265 | <procedure>(halfdelay INT)</procedure> |
---|
266 | |
---|
267 | * <procedure>(has_colors)</procedure> |
---|
268 | * <procedure>(has_ic)</procedure> |
---|
269 | * <procedure>(has_il)</procedure> |
---|
270 | |
---|
271 | Return a boolean value. |
---|
272 | |
---|
273 | * <procedure>(hline CHAR INT)</procedure> |
---|
274 | * <procedure>(idlok WINDOW BOOL)</procedure> |
---|
275 | |
---|
276 | <procedure>(inch)</procedure> |
---|
277 | |
---|
278 | Returns a character value. |
---|
279 | |
---|
280 | * <procedure>(init_color INT INT INT INT)</procedure> |
---|
281 | * <procedure>(init_pair INT INT INT)</procedure> |
---|
282 | |
---|
283 | <procedure>(initscr)</procedure> |
---|
284 | |
---|
285 | Returns an opaque {{WINDOW}} object. |
---|
286 | |
---|
287 | <procedure>(insch CHAR)</procedure> |
---|
288 | |
---|
289 | Returns a character. |
---|
290 | |
---|
291 | * <procedure>(insertln)</procedure> |
---|
292 | * <procedure>(intrflush WINDOW BOOL)</procedure> |
---|
293 | |
---|
294 | * <procedure>(is_linetouched WINDOW INT)</procedure> |
---|
295 | * <procedure>(is_wintouched WINDOW)</procedure> |
---|
296 | * <procedure>(isendwin)</procedure> |
---|
297 | |
---|
298 | Return a boolean value. |
---|
299 | |
---|
300 | <procedure>(keyname INT)</procedure> |
---|
301 | |
---|
302 | Returns a string value. |
---|
303 | |
---|
304 | * <procedure>(keypad WINDOW BOOL)</procedure> |
---|
305 | * <procedure>(killchar CHAR)</procedure> |
---|
306 | * <procedure>(leaveok WINDOW BOOL)</procedure> |
---|
307 | |
---|
308 | <procedure>(longname)</procedure> |
---|
309 | |
---|
310 | Returns a string value. |
---|
311 | |
---|
312 | * <procedure>(meta WINDOW BOOL)</procedure> |
---|
313 | * <procedure>(move INT INT)</procedure> |
---|
314 | * <procedure>(mvaddch INT INT CHAR)</procedure> |
---|
315 | * <procedure>(mvaddnstr INT INT STRING INT)</procedure> |
---|
316 | * <procedure>(mvaddstr INT INT STRING)</procedure> |
---|
317 | * <procedure>(mvcur INT INT INT INT)</procedure> |
---|
318 | * <procedure>(mvdelch INT INT)</procedure> |
---|
319 | * <procedure>(mvgetnstr INT INT STRING INT)</procedure> |
---|
320 | * <procedure>(mvgetstr INT INT STRING)</procedure> |
---|
321 | * <procedure>(mvhline INT INT CHAR INT)</procedure> |
---|
322 | |
---|
323 | * <procedure>(mvinch INT INT)</procedure> |
---|
324 | * <procedure>(mvinsch INT INT CHAR)</procedure> |
---|
325 | |
---|
326 | Return a char value. |
---|
327 | |
---|
328 | * <procedure>(mvprintw INT INT FORMATSTRING ARG ...)</procedure> |
---|
329 | * <procedure>(mvvline INT INT CHAR INT)</procedure> |
---|
330 | * <procedure>(mvwaddch INT INT CHAR)</procedure> |
---|
331 | * <procedure>(mvwaddnstr WINDOW INT INT STRING INT)</procedure> |
---|
332 | * <procedure>(mvwaddstr WINDOW INT INT STRING)</procedure> |
---|
333 | * <procedure>(mvwdelch WINDOW INT INT)</procedure> |
---|
334 | * <procedure>(mvwgetnstr WINDOW INT INT STRING INT)</procedure> |
---|
335 | * <procedure>(mvwgetstr WINDOW INT INT STRING)</procedure> |
---|
336 | * <procedure>(mvwhline WINDOW INT INT CHAR INT)</procedure> |
---|
337 | * <procedure>(mvwin WINDOW INT INT)</procedure> |
---|
338 | |
---|
339 | * <procedure>(mvwinch WINDOW INT INT)</procedure> |
---|
340 | * <procedure>(mvwinsch WINDOW INT INT CHAR)</procedure> |
---|
341 | |
---|
342 | Return a char value |
---|
343 | |
---|
344 | * <procedure>(mvwprintw WINDOW INT INT FORMATSTRING ARG ...)</procedure> |
---|
345 | * <procedure>(mvwvline WINDOW INT INT CHAR INT)</procedure> |
---|
346 | |
---|
347 | * <procedure>(newpad INT INT)</procedure> |
---|
348 | * <procedure>(newwin INT INT INT INT)</procedure> |
---|
349 | |
---|
350 | Return an opaque {{WINDOW}} object. |
---|
351 | |
---|
352 | * <procedure>(nl)</procedure> |
---|
353 | * <procedure>(nocbreak)</procedure> |
---|
354 | * <procedure>(nodelay WINDOW BOOL)</procedure> |
---|
355 | * <procedure>(noecho)</procedure> |
---|
356 | * <procedure>(nonl)</procedure> |
---|
357 | * <procedure>(noraw)</procedure> |
---|
358 | * <procedure>(notimeout WINDOW BOOL)</procedure> |
---|
359 | * <procedure>(overlay WINDOW WINDOW)</procedure> |
---|
360 | * <procedure>(overwrite WINDOW WINDOW)</procedure> |
---|
361 | |
---|
362 | <procedure>(pair_content INT)</procedure> |
---|
363 | |
---|
364 | Returns two integer values. |
---|
365 | |
---|
366 | * <procedure>(pnoutrefresh WINDOW INT INT INT INT INT INT)</procedure> |
---|
367 | * <procedure>(prefresh WINDOW INT INT INT INT INT INT)</procedure> |
---|
368 | * <procedure>(printw FORMATSTRING ARG ...)</procedure> |
---|
369 | * <procedure>(raw)</procedure> |
---|
370 | * <procedure>(refresh)</procedure> |
---|
371 | * <procedure>(reset_prog_mode)</procedure> |
---|
372 | * <procedure>(reset_shell_mode)</procedure> |
---|
373 | * <procedure>(resetty)</procedure> |
---|
374 | * <procedure>(savetty)</procedure> |
---|
375 | * <procedure>(scr_dump STRING)</procedure> |
---|
376 | * <procedure>(scr_init STRING)</procedure> |
---|
377 | * <procedure>(scr_restore STRING)</procedure> |
---|
378 | * <procedure>(scr_set STRING)</procedure> |
---|
379 | * <procedure>(scrl INT)</procedure> |
---|
380 | * <procedure>(scroll WINDOW)</procedure> |
---|
381 | * <procedure>(scrollok WINDOW BOOL)</procedure> |
---|
382 | * <procedure>(setscrreg INT INT)</procedure> |
---|
383 | * <procedure>(setsyx INT INT)</procedure> |
---|
384 | * <procedure>(standend)</procedure> |
---|
385 | * <procedure>(standout)</procedure> |
---|
386 | * <procedure>(start_color)</procedure> |
---|
387 | |
---|
388 | * <procedure>(subpad WINDOW INT INT INT INT)</procedure> |
---|
389 | * <procedure>(subwin WINDOW INT INT INT INT)</procedure> |
---|
390 | |
---|
391 | Return an opaque {{WINDOW}} object. |
---|
392 | |
---|
393 | * <procedure>(timeout INT)</procedure> |
---|
394 | * <procedure>(touchline WINDOW INT INT)</procedure> |
---|
395 | * <procedure>(touchwin WINDOW)</procedure> |
---|
396 | |
---|
397 | <procedure>(unctrl CHAR)</procedure> |
---|
398 | |
---|
399 | Returns a string value. |
---|
400 | |
---|
401 | * <procedure>(ungetch INT)</procedure> |
---|
402 | * <procedure>(untouchwin WINDOW)</procedure> |
---|
403 | * <procedure>(vline CHAR INT)</procedure> |
---|
404 | * <procedure>(waddch WINDOW CHAR)</procedure> |
---|
405 | * <procedure>(waddnstr WINDOW STRING INT)</procedure> |
---|
406 | * <procedure>(waddstr WINDOW STRING)</procedure> |
---|
407 | * <procedure>(wattroff WINDOW INT)</procedure> |
---|
408 | * <procedure>(wattron WINDOW INT)</procedure> |
---|
409 | * <procedure>(wattrset WINDOW INT)</procedure> |
---|
410 | * <procedure>(wborder WINDOW CHAR CHAR CHAR CHAR CHAR CHAR CHAR CHAR)</procedure> |
---|
411 | * <procedure>(wclear WINDOW)</procedure> |
---|
412 | * <procedure>(wclrtobot WINDOW)</procedure> |
---|
413 | * <procedure>(wclrtoeol WINDOW)</procedure> |
---|
414 | * <procedure>(wdelch WINDOW)</procedure> |
---|
415 | * <procedure>(wdeleteln WINDOW)</procedure> |
---|
416 | * <procedure>(wechochar WINDOW CHAR)</procedure> |
---|
417 | * <procedure>(werase WINDOW)</procedure> |
---|
418 | |
---|
419 | <procedure>(wgetch WINDOW)</procedure> |
---|
420 | |
---|
421 | Returns a char value. |
---|
422 | |
---|
423 | * <procedure>(wgetnstr WINDOW STRING INT)</procedure> |
---|
424 | * <procedure>(whline WINDOW CHAR INT)</procedure> |
---|
425 | |
---|
426 | * <procedure>(winch WINDOW)</procedure> |
---|
427 | * <procedure>(winsch WINDOW CHAR)</procedure> |
---|
428 | |
---|
429 | Return a char value. |
---|
430 | |
---|
431 | * <procedure>(winsertln WINDOW)</procedure> |
---|
432 | * <procedure>(wvline WINDOW CHAR INT)</procedure> |
---|
433 | * <procedure>(wmove WINDOW INT INT)</procedure> |
---|
434 | * <procedure>(wnoutrefresh WINDOW)</procedure> |
---|
435 | * <procedure>(wprintw WINDOW FORMATSTRING ARG ...)</procedure> |
---|
436 | * <procedure>(wrefresh WINDOW)</procedure> |
---|
437 | * <procedure>(wscrl WINDOW INT)</procedure> |
---|
438 | * <procedure>(wsetscrreg WINDOW INT INT)</procedure> |
---|
439 | * <procedure>(wstandend WINDOW)</procedure> |
---|
440 | * <procedure>(wstandout WINDOW)</procedure> |
---|
441 | * <procedure>(wtimeout WINDOW INT)</procedure> |
---|
442 | * <procedure>(wtouchln WINDOW INT INT BOOL)</procedure> |
---|
443 | |
---|
444 | ==== Notes: |
---|
445 | |
---|
446 | * Arguments of type CHAR may be either characters or integers (the caracter code) |
---|
447 | * Procedures that normally return an error code are checked, and a condition of the kind {{(exn curses)}} is raised. |
---|
448 | * The {{...printw}} procedures accept {{printf}} style format-strings (not the C {{printf}}, but the {{printf}} in Chicken's {{extras}} library unit). |
---|
449 | |
---|
450 | === Example |
---|
451 | |
---|
452 | <examples><example> |
---|
453 | <init> |
---|
454 | (declare (block) (fixnum) (usual-integrations)) |
---|
455 | |
---|
456 | (require 'ncurses 'srfi-25) |
---|
457 | </init> |
---|
458 | <expr> |
---|
459 | ;;;; life |
---|
460 | |
---|
461 | (define STARTX 0) |
---|
462 | (define STARTY 0) |
---|
463 | (define ENDX 79) |
---|
464 | (define ENDY 24) |
---|
465 | |
---|
466 | (define CELL_CHAR #\#) |
---|
467 | (define TIME_OUT 300) |
---|
468 | |
---|
469 | (define oldstate car) |
---|
470 | (define newstate cdr) |
---|
471 | (define oldstate-set! set-car!) |
---|
472 | (define newstate-set! set-cdr!) |
---|
473 | |
---|
474 | (define cols #f) |
---|
475 | (define lines #f) |
---|
476 | |
---|
477 | (define (life-display win area startx starty endx endy) |
---|
478 | (wclear win) |
---|
479 | (do ([i startx (add1 i)]) |
---|
480 | ((>= i endx)) |
---|
481 | (do ([j starty (add1 j)]) |
---|
482 | ((>= j endy)) |
---|
483 | (unless (zero? (newstate (array-ref area i j))) |
---|
484 | (mvwaddch win j i CELL_CHAR) ) ) ) |
---|
485 | (wrefresh win) ) |
---|
486 | |
---|
487 | (define (calc area i j) |
---|
488 | (let ([neighbours |
---|
489 | (+ (oldstate (array-ref area (modulo (+ i -1 cols) cols) j)) |
---|
490 | (oldstate (array-ref area (modulo (+ i -1 cols) cols) (modulo (+ j -1 lines) lines))) |
---|
491 | (oldstate (array-ref area (modulo (+ i -1 cols) cols) (modulo (add1 j) lines))) |
---|
492 | (oldstate (array-ref area (modulo (add1 i) cols) j)) |
---|
493 | (oldstate (array-ref area (modulo (add1 i) cols) (modulo (+ j -1 lines) lines))) |
---|
494 | (oldstate (array-ref area (modulo (add1 i) cols) (modulo (add1 j) lines))) |
---|
495 | (oldstate (array-ref area i (modulo (+ j -1 lines) lines))) |
---|
496 | (oldstate (array-ref area i (modulo (add1 j) lines))) ) ] ) |
---|
497 | (newstate-set! |
---|
498 | (array-ref area i j) |
---|
499 | (if (and (not (zero? (oldstate (array-ref area i j)))) |
---|
500 | (or (= 2 neighbours) (= 3 neighbours)) ) |
---|
501 | 1 |
---|
502 | (if (and (zero? (oldstate (array-ref area i j))) |
---|
503 | (= 3 neighbours) ) |
---|
504 | 1 |
---|
505 | 0) ) ) ) ) |
---|
506 | |
---|
507 | (define (update-state area startx starty endx endy) |
---|
508 | (do ([i startx (add1 i)]) |
---|
509 | ((>= i endx)) |
---|
510 | (do ([j starty (add1 j)]) |
---|
511 | ((>= j endy)) |
---|
512 | (let ([cell (array-ref area i j)]) |
---|
513 | (oldstate-set! cell (newstate cell)) ) ) ) ) |
---|
514 | |
---|
515 | (define (main) |
---|
516 | (initscr) |
---|
517 | (cbreak) |
---|
518 | (timeout TIME_OUT) |
---|
519 | (keypad (stdscr) #t) |
---|
520 | (curs_set 0) |
---|
521 | (set! cols (COLS)) |
---|
522 | (set! lines (LINES)) |
---|
523 | (set! ENDX (sub1 cols)) |
---|
524 | (set! ENDY (sub1 lines)) |
---|
525 | (let ([workarea (make-array (shape 0 cols 0 lines))]) |
---|
526 | (do ([i 0 (add1 i)]) |
---|
527 | ((>= i cols)) |
---|
528 | (do ([j 0 (add1 j)]) |
---|
529 | ((>= j lines)) |
---|
530 | (array-set! workarea i j (cons 0 0)) ) ) |
---|
531 | (newstate-set! (array-ref workarea 39 15) 1) |
---|
532 | (newstate-set! (array-ref workarea 40 15) 1) |
---|
533 | (newstate-set! (array-ref workarea 41 15) 1) |
---|
534 | (newstate-set! (array-ref workarea 39 16) 1) |
---|
535 | (newstate-set! (array-ref workarea 39 17) 1) |
---|
536 | (newstate-set! (array-ref workarea 41 16) 1) |
---|
537 | (newstate-set! (array-ref workarea 41 17) 1) |
---|
538 | (update-state workarea STARTX STARTY ENDX ENDY) |
---|
539 | (life-display (stdscr) workarea STARTX STARTY ENDX ENDY) |
---|
540 | (let loop () |
---|
541 | (unless (= (char->integer (getch)) (KEY_F 1)) |
---|
542 | (do ([i STARTX (add1 i)]) |
---|
543 | ((>= i ENDX)) |
---|
544 | (do ([j STARTY (add1 j)]) |
---|
545 | ((>= j ENDY)) |
---|
546 | (calc workarea i j) ) ) |
---|
547 | (update-state workarea STARTX STARTY ENDX ENDY) |
---|
548 | (life-display (stdscr) workarea STARTX STARTY ENDX ENDY) |
---|
549 | (loop) ) ) ) |
---|
550 | (endwin) ) |
---|
551 | |
---|
552 | (main) |
---|
553 | </expr> |
---|
554 | </example></examples> |
---|
555 | |
---|
556 | === License |
---|
557 | |
---|
558 | Copyright (c) 2003, Felix L. Winkelmann |
---|
559 | All rights reserved. |
---|
560 | |
---|
561 | Redistribution and use in source and binary forms, with or without |
---|
562 | modification, are permitted provided that the following conditions |
---|
563 | are met: |
---|
564 | |
---|
565 | Redistributions of source code must retain the above copyright |
---|
566 | notice, this list of conditions and the following disclaimer. |
---|
567 | |
---|
568 | Redistributions in binary form must reproduce the above copyright |
---|
569 | notice, this list of conditions and the following disclaimer in the |
---|
570 | documentation and/or other materials provided with the distribution. |
---|
571 | |
---|
572 | Neither the name of the author nor the names of its contributors may |
---|
573 | be used to endorse or promote products derived from this software |
---|
574 | without specific prior written permission. |
---|
575 | |
---|
576 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
577 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
578 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
---|
579 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
---|
580 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
---|
581 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
---|
582 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
---|
583 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
584 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
---|
585 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
586 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
---|
587 | OF THE POSSIBILITY OF SUCH DAMAGE. |
---|