You are looking at historical revision 14747 of this page. It may differ significantly from its current revision.

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

Variables

All these return an integer value as their result.

These two procedures return a WINDOW object.

Procedures

These two procedures return an integer.

[procedure] (can_change_color)

Returns a boolean.

[procedure] (erasechar)

Returns the erased character.

[procedure] (getbegyx WINDOW)

Returns two integer values.

[procedure] (getch)

Returns a character value.

[procedure] (getmaxyx WINDOW)

Returns two integer values.

[procedure] (getnstr STRING INT)
[procedure] (getparyx WINDOW)

Returns two integer values.

[procedure] (getstr STRING)
[procedure] (getsyx)

Returns two integer values.

[procedure] (getyx WINDOW)

Returns two integer values.

[procedure] (halfdelay INT)

Return a boolean value.

[procedure] (inch)

Returns a character value.

[procedure] (initscr)

Returns an opaque WINDOW object.

[procedure] (insch CHAR)

Returns a character.

Return a boolean value.

[procedure] (keyname INT)

Returns a string value.

[procedure] (longname)

Returns a string value.

Return a char value.

Return a char value

Return an opaque WINDOW object.

[procedure] (pair_content INT)

Returns two integer values.

Return an opaque WINDOW object.

[procedure] (unctrl CHAR)

Returns a string value.

[procedure] (wgetch WINDOW)

Returns a char value.

Return a char value.

Notes:

Example

Examples:

(declare (block) (fixnum) (usual-integrations))

(require '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.