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