chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] Termbox using


From: frad
Subject: [Chicken-users] Termbox using
Date: Sat, 02 May 2015 12:34:55 +0000
User-agent: Roundcube Webmail/0.9.5

Hi,

(Sorry for my English)

Newbie with Scheme, i try to use the termbox egg.
It seems me a very nice and cool library and the documentation helps me a lot.
I am learning Scheme and appreciate Chicken implementation.
Here a little piece of code to print a simple text menu.
But this code isn't in the functionnal way (very iterative).

----
(use termbox)
(init)

(define running (make-parameter #t))
(define choice 1)

(define (menu x y lst)
  (let loop ()
    (if (> choice (length lst)) (set! choice 1))
    (if (< choice 1) (set! choice (length lst)))
    (do ((i 0 (+ i 1)))
        ((= i (length lst)))
        (if (= choice (+ i 1))
(bprintf x (+ y i) (style black) (style white) (list-ref lst i)) (bprintf x (+ y i) (style white) (style black) (list-ref lst i))))
    (present)
    (poll (lambda (mod key ch)
                  (cond
                    ((eq? key key-arrow-down) (set! choice (+ choice 1)))
                    ((eq? key key-arrow-up) (set! choice (- choice 1)))
                    ((eq? key key-enter) (running #f))))
          (lambda (w h) (loop)))
    (when (running) (loop))))

;; an example
(menu 5 8 '("Choice 1" "Choice 2" "Choice 3" "Other"))

(shutdown)

(printf "Your choice: ~a\n" choice)
----

Maybe, someone could give me some advices or corrections to make it better.

Regards,
  frad

http://blog.indexi.net








reply via email to

[Prev in Thread] Current Thread [Next in Thread]