Outdated egg!
This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.
If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.
ncurses
TOC »
Description
Provides text-mode and terminal operations for text-based user interfaces.
Author
Requirements
Documentation
The following definitions are provided (full documentation can be found in your system's man pages):
Constants
- A_ALTCHARSETconstant
- A_ATTRIBUTESconstant
- A_BLINKconstant
- A_BOLDconstant
- A_CHARTEXTconstant
- A_COLORconstant
- A_DIMconstant
- A_INVISconstant
- A_LEFTconstant
- A_LOWconstant
- A_NORMALconstant
- A_PROTECTconstant
- A_REVERSEconstant
- A_RIGHTconstant
- A_STANDOUTconstant
- A_TOPconstant
- A_UNDERLINEconstant
- A_VERTICALconstant
- COLOR_BLACKconstant
- COLOR_BLUEconstant
- COLOR_CYANconstant
- COLOR_GREENconstant
- COLOR_MAGENTAconstant
- COLOR_PAIRconstant
- COLOR_REDconstant
- COLOR_WHITEconstant
- COLOR_YELLOWconstant
- KEY_A1constant
- KEY_A3constant
- KEY_B2constant
- KEY_BACKSPACEconstant
- KEY_BEGconstant
- KEY_BREAKconstant
- KEY_BTABconstant
- KEY_C1constant
- KEY_C3constant
- KEY_CANCELconstant
- KEY_CATABconstant
- KEY_CLEARconstant
- KEY_CLOSEconstant
- KEY_CODE_YESconstant
- KEY_COMMANDconstant
- KEY_COPYconstant
- KEY_CREATEconstant
- KEY_CTABconstant
- KEY_DCconstant
- KEY_DLconstant
- KEY_DOWNconstant
- KEY_EICconstant
- KEY_ENDconstant
- KEY_ENTERconstant
- KEY_EOLconstant
- KEY_EOSconstant
- KEY_EXITconstant
- KEY_F0constant
- KEY_FINDconstant
- KEY_HELPconstant
- KEY_HOMEconstant
- KEY_ICconstant
- KEY_ILconstant
- KEY_LEFTconstant
- KEY_LLconstant
- KEY_MARKconstant
- KEY_MESSAGEconstant
- KEY_MINconstant
- KEY_MOUSEconstant
- KEY_MOVEconstant
- KEY_NEXTconstant
- KEY_NPAGEconstant
- KEY_OPENconstant
- KEY_OPTIONSconstant
- KEY_PPAGEconstant
- KEY_PREVIOUSconstant
- KEY_PRINTconstant
- KEY_REDOconstant
- KEY_REFERENCEconstant
- KEY_REFRESHconstant
- KEY_REPLACEconstant
- KEY_RESETconstant
- KEY_RESIZEconstant
- KEY_RESTARTconstant
- KEY_RESUMEconstant
- KEY_RIGHTconstant
- KEY_SAVEconstant
- KEY_SBEGconstant
- KEY_SCANCELconstant
- KEY_SCOMMANDconstant
- KEY_SCOPYconstant
- KEY_SCREATEconstant
- KEY_SDCconstant
- KEY_SDLconstant
- KEY_SELECTconstant
- KEY_SENDconstant
- KEY_SEOLconstant
- KEY_SEXITconstant
- KEY_SFconstant
- KEY_SFINDconstant
- KEY_SHELPconstant
- KEY_SHOMEconstant
- KEY_SICconstant
- KEY_SLEFTconstant
- KEY_SMESSAGEconstant
- KEY_SMOVEconstant
- KEY_SNEXTconstant
- KEY_SOPTIONSconstant
- KEY_SPREVIOUSconstant
- KEY_SPRINTconstant
- KEY_SRconstant
- KEY_SREDOconstant
- KEY_SREPLACEconstant
- KEY_SRESETconstant
- KEY_SRIGHTconstant
- KEY_SRSUMEconstant
- KEY_SSAVEconstant
- KEY_SSUSPENDconstant
- KEY_STABconstant
- KEY_SUNDOconstant
- KEY_SUSPENDconstant
- KEY_UNDOconstant
- KEY_UPconstant
Variables
- ACS_BLOCKprocedure
- ACS_BTEEprocedure
- ACS_BULLETprocedure
- ACS_CKBOARDprocedure
- ACS_DARROWprocedure
- ACS_DEGREEprocedure
- ACS_DIAMONDprocedure
- ACS_HLINEprocedure
- ACS_LANTERNprocedure
- ACS_LARROWprocedure
- ACS_LLCORNERprocedure
- ACS_LRCORNERprocedure
- ACS_LTEEprocedure
- ACS_PLMINUSprocedure
- ACS_PLUSprocedure
- ACS_RARROWprocedure
- ACS_RTEEprocedure
- ACS_S1procedure
- ACS_S9procedure
- ACS_TTEEprocedure
- ACS_UARROWprocedure
- ACS_ULCORNERprocedure
- ACS_URCORNERprocedure
- ACS_VLINEprocedure
- COLORSprocedure
- COLOR_PAIRSprocedure
- LINESprocedure
- COLSprocedure
All these return an integer value as their result.
Procedures
- KEY_F INTprocedure
- PAIR_NUMBER INTprocedure
These two procedures return an integer.
- addch CHARprocedure
- addnstr STRING INTprocedure
- addstr STRINGprocedure
- attroff INTprocedure
- attron INTprocedure
- attrset INTprocedure
- beepprocedure
- border CHAR CHAR CHAR CHAR CHAR CHAR CHAR CHARprocedure
- box WINDOW CHAR CHARprocedure
- can_change_colorprocedure
Returns a boolean.
- cbreakprocedure
- clearprocedure
- clearok WINDOW BOOLprocedure
- clrtobotprocedure
- clrtoeolprocedure
- copywin WINDOW WINDOW INT INT INT INT INT INT BOOLprocedure
- curs_set INTprocedure
- def_prog_modeprocedure
- def_shell_modeprocedure
- delay_output INTprocedure
- delchprocedure
- deletelnprocedure
- delwin WINDOWprocedure
- derwin WINDOW INT INT INT INTprocedure
- doupdateprocedure
- echoprocedure
- echochar WINDOW CHARprocedure
- endwinprocedure
- eraseprocedure
- erasecharprocedure
Returns the erased character.
- getbegyx WINDOWprocedure
Returns two integer values.
- getchprocedure
Returns a character value.
- getmaxyx WINDOWprocedure
Returns two integer values.
- getnstr STRING INTprocedure
- getparyx WINDOWprocedure
Returns two integer values.
- getstr STRINGprocedure
- getsyxprocedure
Returns two integer values.
- getyx WINDOWprocedure
Returns two integer values.
- halfdelay INTprocedure
- has_colorsprocedure
- has_icprocedure
- has_ilprocedure
Return a boolean value.
- hline CHAR INTprocedure
- idlok WINDOW BOOLprocedure
- inchprocedure
Returns a character value.
- init_color INT INT INT INTprocedure
- init_pair INT INT INTprocedure
- initscrprocedure
Returns an opaque WINDOW object.
- insch CHARprocedure
Returns a character.
- insertlnprocedure
- intrflush WINDOW BOOLprocedure
- is_linetouched WINDOW INTprocedure
- is_wintouched WINDOWprocedure
- isendwinprocedure
Return a boolean value.
- keyname INTprocedure
Returns a string value.
- keypad WINDOW BOOLprocedure
- killchar CHARprocedure
- leaveok WINDOW BOOLprocedure
- longnameprocedure
Returns a string value.
- meta WINDOW BOOLprocedure
- move INT INTprocedure
- mvaddch INT INT CHARprocedure
- mvaddnstr INT INT STRING INTprocedure
- mvaddstr INT INT STRINGprocedure
- mvcur INT INT INT INTprocedure
- mvdelch INT INTprocedure
- mvgetnstr INT INT STRING INTprocedure
- mvgetstr INT INT STRINGprocedure
- mvhline INT INT CHAR INTprocedure
- mvinch INT INTprocedure
- mvinsch INT INT CHARprocedure
Return a char value.
- mvprintw INT INT FORMATSTRING ARG ...procedure
- mvvline INT INT CHAR INTprocedure
- mvwaddch INT INT CHARprocedure
- mvwaddnstr WINDOW INT INT STRING INTprocedure
- mvwaddstr WINDOW INT INT STRINGprocedure
- mvwdelch WINDOW INT INTprocedure
- mvwgetnstr WINDOW INT INT STRING INTprocedure
- mvwgetstr WINDOW INT INT STRINGprocedure
- mvwhline WINDOW INT INT CHAR INTprocedure
- mvwin WINDOW INT INTprocedure
- mvwinch WINDOW INT INTprocedure
- mvwinsch WINDOW INT INT CHARprocedure
Return a char value
- newpad INT INTprocedure
- newwin INT INT INT INTprocedure
Return an opaque WINDOW object.
- nlprocedure
- nocbreakprocedure
- nodelay WINDOW BOOLprocedure
- noechoprocedure
- nonlprocedure
- norawprocedure
- notimeout WINDOW BOOLprocedure
- overlay WINDOW WINDOWprocedure
- overwrite WINDOW WINDOWprocedure
- pair_content INTprocedure
Returns two integer values.
- pnoutrefresh WINDOW INT INT INT INT INT INTprocedure
- prefresh WINDOW INT INT INT INT INT INTprocedure
- printw FORMATSTRING ARG ...procedure
- rawprocedure
- refreshprocedure
- reset_prog_modeprocedure
- reset_shell_modeprocedure
- resettyprocedure
- savettyprocedure
- scr_dump STRINGprocedure
- scr_init STRINGprocedure
- scr_restore STRINGprocedure
- scr_set STRINGprocedure
- scrl INTprocedure
- scroll WINDOWprocedure
- scrollok WINDOW BOOLprocedure
- setscrreg INT INTprocedure
- setsyx INT INTprocedure
- standendprocedure
- standoutprocedure
- start_colorprocedure
- subpad WINDOW INT INT INT INTprocedure
- subwin WINDOW INT INT INT INTprocedure
Return an opaque WINDOW object.
- timeout INTprocedure
- touchline WINDOW INT INTprocedure
- touchwin WINDOWprocedure
- unctrl CHARprocedure
Returns a string value.
- ungetch INTprocedure
- untouchwin WINDOWprocedure
- vline CHAR INTprocedure
- waddch WINDOW CHARprocedure
- waddnstr WINDOW STRING INTprocedure
- waddstr WINDOW STRINGprocedure
- wattroff WINDOW INTprocedure
- wattron WINDOW INTprocedure
- wattrset WINDOW INTprocedure
- wborder WINDOW CHAR CHAR CHAR CHAR CHAR CHAR CHAR CHARprocedure
- wclear WINDOWprocedure
- wclrtobot WINDOWprocedure
- wclrtoeol WINDOWprocedure
- wdelch WINDOWprocedure
- wdeleteln WINDOWprocedure
- wechochar WINDOW CHARprocedure
- werase WINDOWprocedure
- wgetch WINDOWprocedure
Returns a char value.
- wgetnstr WINDOW STRING INTprocedure
- whline WINDOW CHAR INTprocedure
- winch WINDOWprocedure
- winsch WINDOW CHARprocedure
Return a char value.
- winsertln WINDOWprocedure
- wvline WINDOW CHAR INTprocedure
- wmove WINDOW INT INTprocedure
- wnoutrefresh WINDOWprocedure
- wprintw WINDOW FORMATSTRING ARG ...procedure
- wrefresh WINDOWprocedure
- wscrl WINDOW INTprocedure
- wsetscrreg WINDOW INT INTprocedure
- wstandend WINDOWprocedure
- wstandout WINDOWprocedure
- wtimeout WINDOW INTprocedure
- wtouchln WINDOW INT INT BOOLprocedure
Notes:
- Arguments of type CHAR may be either characters or integers (the caracter code)
- Procedures that normally return an error code are checked, and a condition of the kind (exn curses) is raised.
- The ...printw procedures accept printf style format-strings (not the C printf, but the printf in Chicken's extras library unit).
Example
(declare (block) (fixnum) (usual-integrations)) (use ncurses srfi-25) ;;;; 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)
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.