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_ALTCHARSET constant
- A_ATTRIBUTES constant
- A_BLINK constant
- A_BOLD constant
- A_CHARTEXT constant
- A_COLOR constant
- A_DIM constant
- A_INVIS constant
- A_LEFT constant
- A_LOW constant
- A_NORMAL constant
- A_PROTECT constant
- A_REVERSE constant
- A_RIGHT constant
- A_STANDOUT constant
- A_TOP constant
- A_UNDERLINE constant
- A_VERTICAL constant
- COLOR_BLACK constant
- COLOR_BLUE constant
- COLOR_CYAN constant
- COLOR_GREEN constant
- COLOR_MAGENTA constant
- COLOR_PAIR constant
- COLOR_RED constant
- COLOR_WHITE constant
- COLOR_YELLOW constant
- KEY_A1 constant
- KEY_A3 constant
- KEY_B2 constant
- KEY_BACKSPACE constant
- KEY_BEG constant
- KEY_BREAK constant
- KEY_BTAB constant
- KEY_C1 constant
- KEY_C3 constant
- KEY_CANCEL constant
- KEY_CATAB constant
- KEY_CLEAR constant
- KEY_CLOSE constant
- KEY_CODE_YES constant
- KEY_COMMAND constant
- KEY_COPY constant
- KEY_CREATE constant
- KEY_CTAB constant
- KEY_DC constant
- KEY_DL constant
- KEY_DOWN constant
- KEY_EIC constant
- KEY_END constant
- KEY_ENTER constant
- KEY_EOL constant
- KEY_EOS constant
- KEY_EXIT constant
- KEY_F0 constant
- KEY_FIND constant
- KEY_HELP constant
- KEY_HOME constant
- KEY_IC constant
- KEY_IL constant
- KEY_LEFT constant
- KEY_LL constant
- KEY_MARK constant
- KEY_MESSAGE constant
- KEY_MIN constant
- KEY_MOUSE constant
- KEY_MOVE constant
- KEY_NEXT constant
- KEY_NPAGE constant
- KEY_OPEN constant
- KEY_OPTIONS constant
- KEY_PPAGE constant
- KEY_PREVIOUS constant
- KEY_PRINT constant
- KEY_REDO constant
- KEY_REFERENCE constant
- KEY_REFRESH constant
- KEY_REPLACE constant
- KEY_RESET constant
- KEY_RESIZE constant
- KEY_RESTART constant
- KEY_RESUME constant
- KEY_RIGHT constant
- KEY_SAVE constant
- KEY_SBEG constant
- KEY_SCANCEL constant
- KEY_SCOMMAND constant
- KEY_SCOPY constant
- KEY_SCREATE constant
- KEY_SDC constant
- KEY_SDL constant
- KEY_SELECT constant
- KEY_SEND constant
- KEY_SEOL constant
- KEY_SEXIT constant
- KEY_SF constant
- KEY_SFIND constant
- KEY_SHELP constant
- KEY_SHOME constant
- KEY_SIC constant
- KEY_SLEFT constant
- KEY_SMESSAGE constant
- KEY_SMOVE constant
- KEY_SNEXT constant
- KEY_SOPTIONS constant
- KEY_SPREVIOUS constant
- KEY_SPRINT constant
- KEY_SR constant
- KEY_SREDO constant
- KEY_SREPLACE constant
- KEY_SRESET constant
- KEY_SRIGHT constant
- KEY_SRSUME constant
- KEY_SSAVE constant
- KEY_SSUSPEND constant
- KEY_STAB constant
- KEY_SUNDO constant
- KEY_SUSPEND constant
- KEY_UNDO constant
- KEY_UP constant
Variables
- (ACS_BLOCK) procedure
- (ACS_BTEE) procedure
- (ACS_BULLET) procedure
- (ACS_CKBOARD) procedure
- (ACS_DARROW) procedure
- (ACS_DEGREE) procedure
- (ACS_DIAMOND) procedure
- (ACS_HLINE) procedure
- (ACS_LANTERN) procedure
- (ACS_LARROW) procedure
- (ACS_LLCORNER) procedure
- (ACS_LRCORNER) procedure
- (ACS_LTEE) procedure
- (ACS_PLMINUS) procedure
- (ACS_PLUS) procedure
- (ACS_RARROW) procedure
- (ACS_RTEE) procedure
- (ACS_S1) procedure
- (ACS_S9) procedure
- (ACS_TTEE) procedure
- (ACS_UARROW) procedure
- (ACS_ULCORNER) procedure
- (ACS_URCORNER) procedure
- (ACS_VLINE) procedure
- (COLORS) procedure
- (COLOR_PAIRS) procedure
- (LINES) procedure
- (COLS) procedure
All these return an integer value as their result.
Procedures
- (KEY_F INT) procedure
- (PAIR_NUMBER INT) procedure
These two procedures return an integer.
- (addch CHAR) procedure
- (addnstr STRING INT) procedure
- (addstr STRING) procedure
- (attroff INT) procedure
- (attron INT) procedure
- (attrset INT) procedure
- (beep) procedure
- (border CHAR CHAR CHAR CHAR CHAR CHAR CHAR CHAR) procedure
- (box WINDOW CHAR CHAR) procedure
- (can_change_color) procedure
Returns a boolean.
- (cbreak) procedure
- (clear) procedure
- (clearok WINDOW BOOL) procedure
- (clrtobot) procedure
- (clrtoeol) procedure
- (copywin WINDOW WINDOW INT INT INT INT INT INT BOOL) procedure
- (curs_set INT) procedure
- (def_prog_mode) procedure
- (def_shell_mode) procedure
- (delay_output INT) procedure
- (delch) procedure
- (deleteln) procedure
- (delwin WINDOW) procedure
- (derwin WINDOW INT INT INT INT) procedure
- (doupdate) procedure
- (echo) procedure
- (echochar WINDOW CHAR) procedure
- (endwin) procedure
- (erase) procedure
- (erasechar) procedure
Returns the erased character.
- (flash) procedure
- (flushinp) procedure
- (getbegyx WINDOW) procedure
Returns two integer values.
- (getch) procedure
Returns a character value.
- (getmaxyx WINDOW) procedure
Returns two integer values.
- (getnstr STRING INT) procedure
- (getparyx WINDOW) procedure
Returns two integer values.
- (getstr STRING) procedure
- (getsyx) procedure
Returns two integer values.
- (getyx WINDOW) procedure
Returns two integer values.
- (halfdelay INT) procedure
- (has_colors) procedure
- (has_ic) procedure
- (has_il) procedure
Return a boolean value.
- (hline CHAR INT) procedure
- (idlok WINDOW BOOL) procedure
- (inch) procedure
Returns a character value.
- (init_color INT INT INT INT) procedure
- (init_pair INT INT INT) procedure
- (initscr) procedure
Returns an opaque WINDOW object.
- (insch CHAR) procedure
Returns a character.
- (insertln) procedure
- (intrflush WINDOW BOOL) procedure
- (is_linetouched WINDOW INT) procedure
- (is_wintouched WINDOW) procedure
- (isendwin) procedure
Return a boolean value.
- (keyname INT) procedure
Returns a string value.
- (keypad WINDOW BOOL) procedure
- (killchar CHAR) procedure
- (leaveok WINDOW BOOL) procedure
- (longname) procedure
Returns a string value.
- (meta WINDOW BOOL) procedure
- (move INT INT) procedure
- (mvaddch INT INT CHAR) procedure
- (mvaddnstr INT INT STRING INT) procedure
- (mvaddstr INT INT STRING) procedure
- (mvcur INT INT INT INT) procedure
- (mvdelch INT INT) procedure
- (mvgetnstr INT INT STRING INT) procedure
- (mvgetstr INT INT STRING) procedure
- (mvhline INT INT CHAR INT) procedure
- (mvinch INT INT) procedure
- (mvinsch INT INT CHAR) procedure
Return a char value.
- (mvprintw INT INT FORMATSTRING ARG ...) procedure
- (mvvline INT INT CHAR INT) procedure
- (mvwaddch INT INT CHAR) procedure
- (mvwaddnstr WINDOW INT INT STRING INT) procedure
- (mvwaddstr WINDOW INT INT STRING) procedure
- (mvwdelch WINDOW INT INT) procedure
- (mvwgetnstr WINDOW INT INT STRING INT) procedure
- (mvwgetstr WINDOW INT INT STRING) procedure
- (mvwhline WINDOW INT INT CHAR INT) procedure
- (mvwin WINDOW INT INT) procedure
- (mvwinch WINDOW INT INT) procedure
- (mvwinsch WINDOW INT INT CHAR) procedure
Return a char value
- (mvwprintw WINDOW INT INT FORMATSTRING ARG ...) procedure
- (mvwvline WINDOW INT INT CHAR INT) procedure
- (newpad INT INT) procedure
- (newwin INT INT INT INT) procedure
Return an opaque WINDOW object.
- (nl) procedure
- (nocbreak) procedure
- (nodelay WINDOW BOOL) procedure
- (noecho) procedure
- (nonl) procedure
- (noraw) procedure
- (notimeout WINDOW BOOL) procedure
- (overlay WINDOW WINDOW) procedure
- (overwrite WINDOW WINDOW) procedure
- (pair_content INT) procedure
Returns two integer values.
- (pnoutrefresh WINDOW INT INT INT INT INT INT) procedure
- (prefresh WINDOW INT INT INT INT INT INT) procedure
- (printw FORMATSTRING ARG ...) procedure
- (raw) procedure
- (refresh) procedure
- (reset_prog_mode) procedure
- (reset_shell_mode) procedure
- (resetty) procedure
- (savetty) procedure
- (scr_dump STRING) procedure
- (scr_init STRING) procedure
- (scr_restore STRING) procedure
- (scr_set STRING) procedure
- (scrl INT) procedure
- (scroll WINDOW) procedure
- (scrollok WINDOW BOOL) procedure
- (setscrreg INT INT) procedure
- (setsyx INT INT) procedure
- (standend) procedure
- (standout) procedure
- (start_color) procedure
- (subpad WINDOW INT INT INT INT) procedure
- (subwin WINDOW INT INT INT INT) procedure
Return an opaque WINDOW object.
- (timeout INT) procedure
- (touchline WINDOW INT INT) procedure
- (touchwin WINDOW) procedure
- (unctrl CHAR) procedure
Returns a string value.
- (ungetch INT) procedure
- (untouchwin WINDOW) procedure
- (vline CHAR INT) procedure
- (waddch WINDOW CHAR) procedure
- (waddnstr WINDOW STRING INT) procedure
- (waddstr WINDOW STRING) procedure
- (wattroff WINDOW INT) procedure
- (wattron WINDOW INT) procedure
- (wattrset WINDOW INT) procedure
- (wborder WINDOW CHAR CHAR CHAR CHAR CHAR CHAR CHAR CHAR) procedure
- (wclear WINDOW) procedure
- (wclrtobot WINDOW) procedure
- (wclrtoeol WINDOW) procedure
- (wdelch WINDOW) procedure
- (wdeleteln WINDOW) procedure
- (wechochar WINDOW CHAR) procedure
- (werase WINDOW) procedure
- (wgetch WINDOW) procedure
Returns a char value.
- (wgetnstr WINDOW STRING INT) procedure
- (whline WINDOW CHAR INT) procedure
- (winch WINDOW) procedure
- (winsch WINDOW CHAR) procedure
Return a char value.
- (winsertln WINDOW) procedure
- (wvline WINDOW CHAR INT) procedure
- (wmove WINDOW INT INT) procedure
- (wnoutrefresh WINDOW) procedure
- (wprintw WINDOW FORMATSTRING ARG ...) procedure
- (wrefresh WINDOW) procedure
- (wscrl WINDOW INT) procedure
- (wsetscrreg WINDOW INT INT) procedure
- (wstandend WINDOW) procedure
- (wstandout WINDOW) procedure
- (wtimeout WINDOW INT) procedure
- (wtouchln WINDOW INT INT BOOL) procedure
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.