Note: This is taken from the Chicken Wiki, where a more recent version could be available.

ncurses

Description

Provides text-mode and terminal operations for text-based user interfaces.

Author

felix winkelmann

Requirements

easyffi

Download

ncurses.egg

Documentation

The following definitions are provided (full documentation can be found in your system's man pages):

Constants

<constant>A_ALTCHARSET</constant> <constant>A_ATTRIBUTES</constant> <constant>A_BLINK</constant> <constant>A_BOLD</constant> <constant>A_CHARTEXT</constant> <constant>A_COLOR</constant> <constant>A_DIM</constant> <constant>A_INVIS</constant> <constant>A_LEFT</constant> <constant>A_LOW</constant> <constant>A_NORMAL</constant> <constant>A_PROTECT</constant> <constant>A_REVERSE</constant> <constant>A_RIGHT</constant> <constant>A_STANDOUT</constant> <constant>A_TOP</constant> <constant>A_UNDERLINE</constant> <constant>A_VERTICAL</constant> <constant>COLOR_BLACK</constant> <constant>COLOR_BLUE</constant> <constant>COLOR_CYAN</constant> <constant>COLOR_GREEN</constant> <constant>COLOR_MAGENTA</constant> <constant>COLOR_PAIR</constant> <constant>COLOR_RED</constant> <constant>COLOR_WHITE</constant> <constant>COLOR_YELLOW</constant> <constant>KEY_A1</constant> <constant>KEY_A3</constant> <constant>KEY_B2</constant> <constant>KEY_BACKSPACE</constant> <constant>KEY_BEG</constant> <constant>KEY_BREAK</constant> <constant>KEY_BTAB</constant> <constant>KEY_C1</constant> <constant>KEY_C3</constant> <constant>KEY_CANCEL</constant> <constant>KEY_CATAB</constant> <constant>KEY_CLEAR</constant> <constant>KEY_CLOSE</constant> <constant>KEY_CODE_YES</constant> <constant>KEY_COMMAND</constant> <constant>KEY_COPY</constant> <constant>KEY_CREATE</constant> <constant>KEY_CTAB</constant> <constant>KEY_DC</constant> <constant>KEY_DL</constant> <constant>KEY_DOWN</constant> <constant>KEY_EIC</constant> <constant>KEY_END</constant> <constant>KEY_ENTER</constant> <constant>KEY_EOL</constant> <constant>KEY_EOS</constant> <constant>KEY_EXIT</constant> <constant>KEY_F0</constant> <constant>KEY_FIND</constant> <constant>KEY_HELP</constant> <constant>KEY_HOME</constant> <constant>KEY_IC</constant> <constant>KEY_IL</constant> <constant>KEY_LEFT</constant> <constant>KEY_LL</constant> <constant>KEY_MARK</constant> <constant>KEY_MESSAGE</constant> <constant>KEY_MIN</constant> <constant>KEY_MOUSE</constant> <constant>KEY_MOVE</constant> <constant>KEY_NEXT</constant> <constant>KEY_NPAGE</constant> <constant>KEY_OPEN</constant> <constant>KEY_OPTIONS</constant> <constant>KEY_PPAGE</constant> <constant>KEY_PREVIOUS</constant> <constant>KEY_PRINT</constant> <constant>KEY_REDO</constant> <constant>KEY_REFERENCE</constant> <constant>KEY_REFRESH</constant> <constant>KEY_REPLACE</constant> <constant>KEY_RESET</constant> <constant>KEY_RESIZE</constant> <constant>KEY_RESTART</constant> <constant>KEY_RESUME</constant> <constant>KEY_RIGHT</constant> <constant>KEY_SAVE</constant> <constant>KEY_SBEG</constant> <constant>KEY_SCANCEL</constant> <constant>KEY_SCOMMAND</constant> <constant>KEY_SCOPY</constant> <constant>KEY_SCREATE</constant> <constant>KEY_SDC</constant> <constant>KEY_SDL</constant> <constant>KEY_SELECT</constant> <constant>KEY_SEND</constant> <constant>KEY_SEOL</constant> <constant>KEY_SEXIT</constant> <constant>KEY_SF</constant> <constant>KEY_SFIND</constant> <constant>KEY_SHELP</constant> <constant>KEY_SHOME</constant> <constant>KEY_SIC</constant> <constant>KEY_SLEFT</constant> <constant>KEY_SMESSAGE</constant> <constant>KEY_SMOVE</constant> <constant>KEY_SNEXT</constant> <constant>KEY_SOPTIONS</constant> <constant>KEY_SPREVIOUS</constant> <constant>KEY_SPRINT</constant> <constant>KEY_SR</constant> <constant>KEY_SREDO</constant> <constant>KEY_SREPLACE</constant> <constant>KEY_SRESET</constant> <constant>KEY_SRIGHT</constant> <constant>KEY_SRSUME</constant> <constant>KEY_SSAVE</constant> <constant>KEY_SSUSPEND</constant> <constant>KEY_STAB</constant> <constant>KEY_SUNDO</constant> <constant>KEY_SUSPEND</constant> <constant>KEY_UNDO</constant> <constant>KEY_UP</constant>

Variables

<procedure>(ACS_BLOCK)</procedure> <procedure>(ACS_BTEE)</procedure> <procedure>(ACS_BULLET)</procedure> <procedure>(ACS_CKBOARD)</procedure> <procedure>(ACS_DARROW)</procedure> <procedure>(ACS_DEGREE)</procedure> <procedure>(ACS_DIAMOND)</procedure> <procedure>(ACS_HLINE)</procedure> <procedure>(ACS_LANTERN)</procedure> <procedure>(ACS_LARROW)</procedure> <procedure>(ACS_LLCORNER)</procedure> <procedure>(ACS_LRCORNER)</procedure> <procedure>(ACS_LTEE)</procedure> <procedure>(ACS_PLMINUS)</procedure> <procedure>(ACS_PLUS)</procedure> <procedure>(ACS_RARROW)</procedure> <procedure>(ACS_RTEE)</procedure> <procedure>(ACS_S1)</procedure> <procedure>(ACS_S9)</procedure> <procedure>(ACS_TTEE)</procedure> <procedure>(ACS_UARROW)</procedure> <procedure>(ACS_ULCORNER)</procedure> <procedure>(ACS_URCORNER)</procedure> <procedure>(ACS_VLINE)</procedure> <procedure>(COLORS)</procedure> <procedure>(COLOR_PAIRS)</procedure> <procedure>(LINES)</procedure> <procedure>(COLS)</procedure>

All these return an integer value as their result.

<procedure>(stdscr)</procedure> <procedure>(curscr)</procedure>

These two procedures return a WINDOW object.

Procedures

<procedure>(KEY_F INT)</procedure> <procedure>(PAIR_NUMBER INT)</procedure>

These two procedures return an integer.

<procedure>(addch CHAR)</procedure> <procedure>(addnstr STRING INT)</procedure> <procedure>(addstr STRING)</procedure> <procedure>(attroff INT)</procedure> <procedure>(attron INT)</procedure> <procedure>(attrset INT)</procedure> <procedure>(beep)</procedure> <procedure>(border CHAR CHAR CHAR CHAR CHAR CHAR CHAR CHAR)</procedure> <procedure>(box WINDOW CHAR CHAR)</procedure>

<procedure>(can_change_color)</procedure>

Returns a boolean.

<procedure>(cbreak)</procedure> <procedure>(clear)</procedure> <procedure>(clearok WINDOW BOOL)</procedure> <procedure>(clrtobot)</procedure> <procedure>(clrtoeol)</procedure> <procedure>(copywin WINDOW WINDOW INT INT INT INT INT INT BOOL)</procedure> <procedure>(curs_set INT)</procedure> <procedure>(def_prog_mode)</procedure> <procedure>(def_shell_mode)</procedure> <procedure>(delay_output INT)</procedure> <procedure>(delch)</procedure> <procedure>(deleteln)</procedure> <procedure>(delwin WINDOW)</procedure> <procedure>(derwin WINDOW INT INT INT INT)</procedure> <procedure>(doupdate)</procedure> <procedure>(echo)</procedure> <procedure>(echochar WINDOW CHAR)</procedure> <procedure>(endwin)</procedure> <procedure>(erase)</procedure>

<procedure>(erasechar)</procedure>

Returns the erased character.

<procedure>(flash)</procedure> <procedure>(flushinp)</procedure>

<procedure>(getbegyx WINDOW)</procedure>

Returns two integer values.

<procedure>(getch)</procedure>

Returns a character value.

<procedure>(getmaxyx WINDOW)</procedure>

Returns two integer values.

<procedure>(getnstr STRING INT)</procedure>

<procedure>(getparyx WINDOW)</procedure>

Returns two integer values.

<procedure>(getstr STRING)</procedure>

<procedure>(getsyx)</procedure>

Returns two integer values.

<procedure>(getyx WINDOW)</procedure>

Returns two integer values.

<procedure>(halfdelay INT)</procedure>

<procedure>(has_colors)</procedure> <procedure>(has_ic)</procedure> <procedure>(has_il)</procedure>

Return a boolean value.

<procedure>(hline CHAR INT)</procedure> <procedure>(idlok WINDOW BOOL)</procedure>

<procedure>(inch)</procedure>

Returns a character value.

<procedure>(init_color INT INT INT INT)</procedure> <procedure>(init_pair INT INT INT)</procedure>

<procedure>(initscr)</procedure>

Returns an opaque WINDOW object.

<procedure>(insch CHAR)</procedure>

Returns a character.

<procedure>(insertln)</procedure> <procedure>(intrflush WINDOW BOOL)</procedure>

<procedure>(is_linetouched WINDOW INT)</procedure> <procedure>(is_wintouched WINDOW)</procedure> <procedure>(isendwin)</procedure>

Return a boolean value.

<procedure>(keyname INT)</procedure>

Returns a string value.

<procedure>(keypad WINDOW BOOL)</procedure> <procedure>(killchar CHAR)</procedure> <procedure>(leaveok WINDOW BOOL)</procedure>

<procedure>(longname)</procedure>

Returns a string value.

<procedure>(meta WINDOW BOOL)</procedure> <procedure>(move INT INT)</procedure> <procedure>(mvaddch INT INT CHAR)</procedure> <procedure>(mvaddnstr INT INT STRING INT)</procedure> <procedure>(mvaddstr INT INT STRING)</procedure> <procedure>(mvcur INT INT INT INT)</procedure> <procedure>(mvdelch INT INT)</procedure> <procedure>(mvgetnstr INT INT STRING INT)</procedure> <procedure>(mvgetstr INT INT STRING)</procedure> <procedure>(mvhline INT INT CHAR INT)</procedure>

<procedure>(mvinch INT INT)</procedure> <procedure>(mvinsch INT INT CHAR)</procedure>

Return a char value.

<procedure>(mvprintw INT INT FORMATSTRING ARG ...)</procedure> <procedure>(mvvline INT INT CHAR INT)</procedure> <procedure>(mvwaddch INT INT CHAR)</procedure> <procedure>(mvwaddnstr WINDOW INT INT STRING INT)</procedure> <procedure>(mvwaddstr WINDOW INT INT STRING)</procedure> <procedure>(mvwdelch WINDOW INT INT)</procedure> <procedure>(mvwgetnstr WINDOW INT INT STRING INT)</procedure> <procedure>(mvwgetstr WINDOW INT INT STRING)</procedure> <procedure>(mvwhline WINDOW INT INT CHAR INT)</procedure> <procedure>(mvwin WINDOW INT INT)</procedure>

<procedure>(mvwinch WINDOW INT INT)</procedure> <procedure>(mvwinsch WINDOW INT INT CHAR)</procedure>

Return a char value

<procedure>(mvwprintw WINDOW INT INT FORMATSTRING ARG ...)</procedure> <procedure>(mvwvline WINDOW INT INT CHAR INT)</procedure>

<procedure>(newpad INT INT)</procedure> <procedure>(newwin INT INT INT INT)</procedure>

Return an opaque WINDOW object.

<procedure>(nl)</procedure> <procedure>(nocbreak)</procedure> <procedure>(nodelay WINDOW BOOL)</procedure> <procedure>(noecho)</procedure> <procedure>(nonl)</procedure> <procedure>(noraw)</procedure> <procedure>(notimeout WINDOW BOOL)</procedure> <procedure>(overlay WINDOW WINDOW)</procedure> <procedure>(overwrite WINDOW WINDOW)</procedure>

<procedure>(pair_content INT)</procedure>

Returns two integer values.

<procedure>(pnoutrefresh WINDOW INT INT INT INT INT INT)</procedure> <procedure>(prefresh WINDOW INT INT INT INT INT INT)</procedure> <procedure>(printw FORMATSTRING ARG ...)</procedure> <procedure>(raw)</procedure> <procedure>(refresh)</procedure> <procedure>(reset_prog_mode)</procedure> <procedure>(reset_shell_mode)</procedure> <procedure>(resetty)</procedure> <procedure>(savetty)</procedure> <procedure>(scr_dump STRING)</procedure> <procedure>(scr_init STRING)</procedure> <procedure>(scr_restore STRING)</procedure> <procedure>(scr_set STRING)</procedure> <procedure>(scrl INT)</procedure> <procedure>(scroll WINDOW)</procedure> <procedure>(scrollok WINDOW BOOL)</procedure> <procedure>(setscrreg INT INT)</procedure> <procedure>(setsyx INT INT)</procedure> <procedure>(standend)</procedure> <procedure>(standout)</procedure> <procedure>(start_color)</procedure>

<procedure>(subpad WINDOW INT INT INT INT)</procedure> <procedure>(subwin WINDOW INT INT INT INT)</procedure>

Return an opaque WINDOW object.

<procedure>(timeout INT)</procedure> <procedure>(touchline WINDOW INT INT)</procedure> <procedure>(touchwin WINDOW)</procedure>

<procedure>(unctrl CHAR)</procedure>

Returns a string value.

<procedure>(ungetch INT)</procedure> <procedure>(untouchwin WINDOW)</procedure> <procedure>(vline CHAR INT)</procedure> <procedure>(waddch WINDOW CHAR)</procedure> <procedure>(waddnstr WINDOW STRING INT)</procedure> <procedure>(waddstr WINDOW STRING)</procedure> <procedure>(wattroff WINDOW INT)</procedure> <procedure>(wattron WINDOW INT)</procedure> <procedure>(wattrset WINDOW INT)</procedure> <procedure>(wborder WINDOW CHAR CHAR CHAR CHAR CHAR CHAR CHAR CHAR)</procedure> <procedure>(wclear WINDOW)</procedure> <procedure>(wclrtobot WINDOW)</procedure> <procedure>(wclrtoeol WINDOW)</procedure> <procedure>(wdelch WINDOW)</procedure> <procedure>(wdeleteln WINDOW)</procedure> <procedure>(wechochar WINDOW CHAR)</procedure> <procedure>(werase WINDOW)</procedure>

<procedure>(wgetch WINDOW)</procedure>

Returns a char value.

<procedure>(wgetnstr WINDOW STRING INT)</procedure> <procedure>(whline WINDOW CHAR INT)</procedure>

<procedure>(winch WINDOW)</procedure> <procedure>(winsch WINDOW CHAR)</procedure>

Return a char value.

<procedure>(winsertln WINDOW)</procedure> <procedure>(wvline WINDOW CHAR INT)</procedure> <procedure>(wmove WINDOW INT INT)</procedure> <procedure>(wnoutrefresh WINDOW)</procedure> <procedure>(wprintw WINDOW FORMATSTRING ARG ...)</procedure> <procedure>(wrefresh WINDOW)</procedure> <procedure>(wscrl WINDOW INT)</procedure> <procedure>(wsetscrreg WINDOW INT INT)</procedure> <procedure>(wstandend WINDOW)</procedure> <procedure>(wstandout WINDOW)</procedure> <procedure>(wtimeout WINDOW INT)</procedure> <procedure>(wtouchln WINDOW INT INT BOOL)</procedure>

Notes:

Example

<example> <init> (declare (block) (fixnum) (usual-integrations))

(require 'ncurses 'srfi-25) </init> <expr> ;;;; life

(define STARTX 0) (define STARTY 0) (define ENDX 79) (define ENDY 24)

(define CELL_CHAR #\#) (define TIME_OUT 300)

(define oldstate car) (define newstate cdr) (define oldstate-set! set-car!) (define newstate-set! set-cdr!)

(define cols #f) (define lines #f)

(define (life-display win area startx starty endx endy)

 (wclear win)
 (do ([i startx (add1 i)])
     ((>= i endx))
   (do ([j starty (add1 j)])

((>= j endy))

     (unless (zero? (newstate (array-ref area i j)))

(mvwaddch win j i CELL_CHAR) ) ) )

 (wrefresh win) )

(define (calc area i j)

 (let ([neighbours 

(+ (oldstate (array-ref area (modulo (+ i -1 cols) cols) j)) (oldstate (array-ref area (modulo (+ i -1 cols) cols) (modulo (+ j -1 lines) lines))) (oldstate (array-ref area (modulo (+ i -1 cols) cols) (modulo (add1 j) lines))) (oldstate (array-ref area (modulo (add1 i) cols) j)) (oldstate (array-ref area (modulo (add1 i) cols) (modulo (+ j -1 lines) lines))) (oldstate (array-ref area (modulo (add1 i) cols) (modulo (add1 j) lines))) (oldstate (array-ref area i (modulo (+ j -1 lines) lines))) (oldstate (array-ref area i (modulo (add1 j) lines))) ) ] )

   (newstate-set!
    (array-ref area i j)
    (if (and (not (zero? (oldstate (array-ref area i j))))

(or (= 2 neighbours) (= 3 neighbours)) ) 1 (if (and (zero? (oldstate (array-ref area i j))) (= 3 neighbours) ) 1 0) ) ) ) )

(define (update-state area startx starty endx endy)

 (do ([i startx (add1 i)])
     ((>= i endx))
   (do ([j starty (add1 j)])

((>= j endy))

     (let ([cell (array-ref area i j)])

(oldstate-set! cell (newstate cell)) ) ) ) )

(define (main)

 (initscr)
 (cbreak)
 (timeout TIME_OUT)
 (keypad (stdscr) #t)
 (curs_set 0)
 (set! cols (COLS))
 (set! lines (LINES))
 (set! ENDX (sub1 cols))
 (set! ENDY (sub1 lines))
 (let ([workarea (make-array (shape 0 cols 0 lines))])
   (do ([i 0 (add1 i)])

((>= i cols))

     (do ([j 0 (add1 j)])

((>= j lines)) (array-set! workarea i j (cons 0 0)) ) )

   (newstate-set! (array-ref workarea 39 15) 1)
   (newstate-set! (array-ref workarea 40 15) 1)
   (newstate-set! (array-ref workarea 41 15) 1)
   (newstate-set! (array-ref workarea 39 16) 1)
   (newstate-set! (array-ref workarea 39 17) 1)
   (newstate-set! (array-ref workarea 41 16) 1)
   (newstate-set! (array-ref workarea 41 17) 1)
   (update-state workarea STARTX STARTY ENDX ENDY)
   (life-display (stdscr) workarea STARTX STARTY ENDX ENDY)
   (let loop ()
     (unless (= (char->integer (getch)) (KEY_F 1))

(do ([i STARTX (add1 i)]) ((>= i ENDX)) (do ([j STARTY (add1 j)]) ((>= j ENDY)) (calc workarea i j) ) ) (update-state workarea STARTX STARTY ENDX ENDY) (life-display (stdscr) workarea STARTX STARTY ENDX ENDY) (loop) ) ) )

 (endwin) )

(main) </expr> </example>

License

 Copyright (c) 2003, Felix L. Winkelmann
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
 conditions are met:
 
   Redistributions of source code must retain the above copyright notice, this list of conditions and the following
     disclaimer. 
   Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
     disclaimer in the documentation and/or other materials provided with the distribution. 
   Neither the name of the author nor the names of its contributors may be used to endorse or promote
     products derived from this software without specific prior written permission. 
 
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGE.