cursing curses in clisp

Discussion of Common Lisp
Post Reply
punchcard
Posts: 16
Joined: Fri Sep 26, 2014 5:50 pm

cursing curses in clisp

Post by punchcard » Fri Oct 03, 2014 7:11 am

I use quicklisp to install the libraries cl-ncurses and also

But i keep getting these errors.

Code: Select all

;; Loading file /home/zimzom/.clisprc.lisp ...
;;  Loading file /home/zimzom/quicklisp/setup.lisp ...
;;  Loaded file /home/zimzom/quicklisp/setup.lisp
;; Loaded file /home/zimzom/.clisprc.lisp
[1]> (ql:quickload "cl-ncurses")
To load "cl-ncurses":
  Load 1 ASDF system:
    cl-ncurses
; Loading "cl-ncurses"
To load "uffi":
  Install 1 Quicklisp release:
    uffi
; Loading "uffi"

*** - Component "uffi" not found
The following restarts are available:
REINITIALIZE-SOURCE-REGISTRY-AND-RETRY :R1 Retry finding system uffi after reinitializing the source-registry.
ABORT          :R2      Give up on "uffi"
ABORT          :R3      Give up on "cl-ncurses"
ABORT          :R4      Abort main loop
Do I need to reinstall clisp? Is there an easy way to do curses in lisp. Strikes me as odd that a language used to develop the first guis seems to have no way to do GUI stuff...

*update*

I found the ltk library and it works just fine. However its still a shame as I would like to use curses for some things.
On the other hand - been having a blast porting my python and crusty c programs. I still and stunned just how flexable clisp is. If I could just get it to play nice with a graphics framework - even somthing basic would do the job like curses it would be great. So many years wasted when I could have been programming the right way. :lol:

logxor
Posts: 20
Joined: Tue May 27, 2014 10:56 am
Location: Portland, OR

Re: cursing curses in clisp

Post by logxor » Fri Oct 03, 2014 11:29 am

Judging from the online documentation, UFFI doesn't support CLISP. That page suggests using the "cffi-uffi-compat" component of CFFI. Or you could investigate this project I just saw: cl-charms, which is a newer curses interface built with CFFI instead of UFFI.

Also—it looks like there's a simple built-in screen interface in CLISP.

punchcard
Posts: 16
Joined: Fri Sep 26, 2014 5:50 pm

Re: cursing curses in clisp

Post by punchcard » Fri Oct 03, 2014 7:35 pm

logxor wrote:Judging from the online documentation, UFFI doesn't support CLISP. That page suggests using the "cffi-uffi-compat" component of CFFI. Or you could investigate this project I just saw: cl-charms, which is a newer curses interface built with CFFI instead of UFFI.

Also—it looks like there's a simple built-in screen interface in CLISP.
I found this forum post and while the code runs it does not seem to execute the getch function as keyboard input does not seem to be being handled properly.

Code: Select all

(ql:quickload "cl-charms")

(defconstant +map+ #2A(
  ("#" "#" "#" "#" "#" "#" "#" "#" "#" "#" "#" "#" "#" "#" "#")
  ("#" " " " " " " " " " " " " "#" " " " " " " " " " " " " "#")
  ("#" " " " " " " " " " " " " " " " " " " " " " " " " " " "#")
  ("#" " " " " " " " " " " " " "#" "#" "#" " " "#" "#" "#" "#")
  ("#" "#" "#" "#" " " "#" "#" "#" " " " " " " "#" " " " " "#")
  ("#" " " " " " " " " " " " " " " " " " " " " "#" " " " " "#")
  ("#" " " " " " " " " " " " " " " " " " " " " "#" " " " " "#")
  ("#" " " " " " " " " " " " " " " " " " " " " " " " " " " "#")
  ("#" " " " " " " " " " " " " " " " " " " " " "#" " " " " "#")
  ("#" "#" "#" "#" "#" "#" "#" "#" "#" "#" "#" "#" "#" "#" "#")))

(defun move ()
  (cl-charms:keypad (cl-charms:initscr) 1)
  (cl-charms:curs-set 0)

  (let ((y 1) (x 1) c)
    (loop while (not (eq c 113)) do
      ;; printing map                                                       
      (loop for yy from 0 to 9 do
        (loop for xx from 0 to 14 do
          (cl-charms:mvaddstr yy xx (aref +map+ yy xx))))
      (if (and (eq c 107) (equal (aref +map+ (1- y) x) " "))
        (incf y -1))
      (if (and (eq c 106) (equal (aref +map+ (1+ y) x) " "))
        (incf y))
      (if (and (eq c 104) (equal (aref +map+ y (1- x)) " "))
        (incf x -1))
      (if (and (eq c 108) (equal (aref +map+ y (1+ x)) " "))
        (incf x))
      (if (and (eq c 98) (equal (aref +map+ (1+ y) (1- x)) " "))
        (progn (incf y) (incf x -1)))
      (if (and (eq c 121) (equal (aref +map+ (1- y) (1- x)) " "))
        (progn (incf y -1) (incf x -1)))
      (if (and (eq c 117) (equal (aref +map+ (1- y) (1+ x)) " "))
        (progn (incf y -1) (incf x)))
      (if (and (eq c 110) (equal (aref +map+ (1+ y) (1+ x)) " "))
        (progn (incf y) (incf x)))

    (cl-charms:mvaddstr y x "@")
    (setf c (cl-charms:getch))))

  (cl-charms:endwin))

(defun main ()
  (move)
  (exit))
Thanks for the advice, I loaded cl-charms. The libary loads - but there is no documentation on how to test it or make sure its working properly. The example files do not run. Like a lot of the libaries there is next to no documenation or support. I am starting to see some of the problems with using lisp.. :? I know its probably somthing wrong with my system but whos to know...

*update*

I found one example of cl-charms and it appears to work just fine. mmmmmm will need to have a play and perhaps document it.

Code: Select all

(defun clock ()
  (charms:initscr)
  (charms:clear)
  (charms:curs-set 0)
  (loop with start = (get-universal-time)
        do (multiple-value-bind (s m h) (get-decoded-time)
             (charms:mvaddstr 10 35 (format nil "~2,'0d:~2,'0d:~2,'0d" h m s)))
           (charms:refresh)
        until (>= (- (get-universal-time) start) 10))
  (charms:endwin))
There were some pretty good curses and ncurses tutorials for python and c... will see how easy it is to port them.

Is there any kind of examples of using the simple built-in interface?

logxor
Posts: 20
Joined: Tue May 27, 2014 10:56 am
Location: Portland, OR

Re: cursing curses in clisp

Post by logxor » Sat Oct 04, 2014 2:44 pm

This old thread from the CLISP mailing list has a snippet involving SCREEN and keyboard input.

On this German site there's a peg solitaire thing using CLISP's built-in screen interface. I have no idea if it works or not, but I'm just pasting the source file here:

Code: Select all

(defun ChooseVariant()
  (screen:clear-window screen)
  (format t "Please choose your Game.~%~%")
  (format t "1 = English Peg Solitaire~%")
  (format t "2 = French Peg Solitaire~%")
  (ext:with-keyboard
      (loop for char = (read-char ext:*keyboard-input*)
            for key = (or (ext:char-key char) (character char))
            do (case key
                 (#\1
                  (setq variant 1)
                  (return-from ChooseVariant variant))
                 (#\2
                  (setq variant 2)
                  (return-from ChooseVariant variant))))))

(defun InitPlayfield(variant)
  (let ((playfield (make-array '(9 9))))
    (dotimes (x 9)
      (dotimes (y 9)
        (setf (aref playfield x y) -1)))
    (dotimes (y 3)
      (dotimes (x 7)
        (setf (aref playfield (+ x 1) (+ y 3)) 1)))
    (dotimes (x 3)
      (dotimes (y 7)
        (setf (aref playfield (+ x 3) (+ y 1)) 1)))
    (setf (aref playfield 4 4) 2)
    (if (= variant 2)
        (progn
          (setf (aref playfield 2 2) 1)
          (setf (aref playfield 6 2) 1)
          (setf (aref playfield 2 6) 1)
          (setf (aref playfield 6 6) 1)))
    (return-from InitPlayfield playfield)))
	
(defun DrawPlayfield(playfield variant pegs)
  (screen:set-window-cursor-position screen 0 0)
  (princ "+")
  (dotimes (x 18)
    (princ "-"))
  (princ "+")
  (screen:set-window-cursor-position screen 1 0)
  (princ "|")
  (screen:set-window-cursor-position screen 1 11)
  (princ "|")
  (dotimes (y 9)
    (screen:set-window-cursor-position screen (+ y 1) 0)
    (princ "|")
    (dotimes (x 9)
      (screen:set-window-cursor-position screen (+ y 1) x)
      (if (= (aref playfield x y) -1)(princ  " "))
      (if (= (aref playfield x y) 1)(princ "X"))
      (if (= (aref playfield x y) 2)(princ  "O"))
      (if (= (aref playfield x y) 3)(princ  "*")))
    (screen:set-window-cursor-position screen (+ y 1) 9)
    (princ "|"))
  (screen:set-window-cursor-position screen 10 0)
  (princ "+")
  (dotimes (x 18)
    (princ "-"))
  (princ "+")		
  (screen:set-window-cursor-position screen 0 22)
  (if (= variant 1)
      (format t "English Board")
      (format t "French Board"))
  (screen:set-window-cursor-position screen 2 22)
  (format t "Pegs removed: ~d" pegs)
  (screen:set-window-cursor-position screen 12 0)
  (format t "<A> = Left  <D> = Right  <W> = Up  <S> = Down~%")
  (screen:set-window-cursor-position screen 14 0)
  (format t "<Space> = Select")
  (screen:set-window-cursor-position screen 16 0)
  (format t "<R> = Reset Table")
  (screen:set-window-cursor-position screen 18 0)
  (format t "<Q> = Quit"))
	
(defun PlayfieldCleared(playfield)
  (dotimes (x 9)
    (dotimes (y 9)
      (if (= (aref playfield x y) 1) 
          (progn
            (if (= (aref playfield x (- y 1)) 1)
                (if (= (aref playfield x (- y 2)) 2)
                    (return-from PlayfieldCleared nil)))
            (if (= (aref playfield x (+ y 1)) 1)
                (if (= (aref playfield x (+ y 2)) 2)
                    (return-from PlayfieldCleared nil)))
            (if (= (aref playfield (- x 1) y) 1)
                (if (= (aref playfield (- x 2) y) 2)
                    (return-from PlayfieldCleared nil)))
            (if (= (aref playfield (+ x 1) y) 1)
                (if (= (aref playfield (+ x 2) y) 2)
                    (return-from PlayfieldCleared nil)))))))
  (return-from PlayfieldCleared 1))
	
(defun Play()
  (let ((variant (ChooseVariant))
        (playfield (InitPlayfield variant))
        (posx 3)
        (posy 1)
        (marked nil)
        (pegs 0)
        (gameover nil))
    (screen:clear-window screen)
    (Drawplayfield playfield variant pegs)
    (screen:set-window-cursor-position screen (+ posy 1) (+ (* posx 2) 1))
    (ext:with-keyboard
        (loop for char = (read-char ext:*keyboard-input*)
              for key = (or (ext:char-key char) (character char))
              do (case key
                   (#\r
                    (setq variant (ChooseVariant))
                    (setq playfield (Initplayfield variant))
                    (setq posx 3)
                    (setq posy 1)
                    (setq pegs 0)
                    (setq gameover nil)
                    (screen:clear-window screen))
                   (#\w 
                    (if (or (= (aref playfield posx (- posy 1)) 1) (= (aref playfield posx (- posy 1)) 2))
                        (setq posy (- posy 1))))
							
                   (#\a 
                    (if (or (= (aref playfield (- posx 1) posy) 1) (= (aref playfield (- posx 1) posy) 2))
                        (setq posx (- posx 1))))
							
                   (#\s 
                    (if (or (= (aref playfield posx (+ posy 1)) 1) (= (aref playfield posx (+ posy 1)) 2))
                        (setq posy (+ posy 1))))
							
                   (#\d 
                    (if (or (= (aref playfield (+ posx 1) posy) 1) (= (aref playfield (+ posx 1) posy) 2))
                        (setq posx (+ posx 1))))
                   (#\Space
                    (if (not marked)
                        (progn
                          (if (= (aref playfield posx posy) 1)
                              (progn
                                (if (= (aref playfield posx (- posy 1)) 1)
                                    (if (= (aref playfield posx (- posy 2)) 2)
                                        (progn
                                          (setf (aref playfield posx posy) 3)
                                          (setq marked 1))))
                                (if (= (aref playfield posx (+ posy 1)) 1)
                                    (if (= (aref playfield posx (+ posy 2)) 2)
                                        (progn
                                          (setf (aref playfield posx posy) 3)
                                          (setq marked 1))))
                                (if (= (aref playfield (- posx 1) posy) 1)
                                    (if (= (aref playfield (- posx 2) posy) 2)
                                        (progn 
                                          (setf (aref playfield posx posy) 3)
                                          (setq marked 1))))
                                (if (= (aref playfield (+ posx 1) posy) 1)
                                    (if (= (aref playfield (+ posx 2) posy) 2)
                                        (progn
                                          (setf (aref playfield posx posy) 3)
                                          (setq marked 1)))))))
                        (progn
                          (if (= (aref playfield posx posy) 2)
                              (progn
                                (if (= (aref playfield posx (- posy 1)) 1)
                                    (if (= (aref playfield posx (- posy 2)) 3)
                                        (progn
                                          (setf (aref playfield posx posy) 1)
                                          (setf (aref playfield posx (- posy 1)) 2)
                                          (setf (aref playfield posx (- posy 2)) 2)
                                          (setq marked nil)
                                          (incf pegs)
                                          (setq gameover (Playfieldcleared playfield))
                                          (Drawplayfield playfield variant pegs))))
                                (if (= (aref playfield posx (+ posy 1)) 1)
                                    (if (= (aref playfield posx (+ posy 2)) 3)
                                        (progn
                                          (setf (aref playfield posx posy) 1)
                                          (setf (aref playfield posx (+ posy 1)) 2)
                                          (setf (aref playfield posx (+ posy 2)) 2)
                                          (setq marked nil)
                                          (incf pegs)
                                          (setq gameover (Playfieldcleared playfield))
                                          (Drawplayfield playfield variant pegs))))
                                (if (= (aref playfield (- posx 1) posy) 1)
                                    (if (= (aref playfield (- posx 2) posy) 3)
                                        (progn 
                                          (setf (aref playfield posx posy) 1)
                                          (setf (aref playfield (- posx 1) posy) 2)
                                          (setf (aref playfield (- posx 2) posy) 2)
                                          (setq marked nil)
                                          (incf pegs)
                                          (setq gameover (Playfieldcleared playfield))
                                          (Drawplayfield playfield variant pegs))))
                                (if (= (aref playfield (+ posx 1) posy) 1)
                                    (if (= (aref playfield (+ posx 2) posy) 3)
                                        (progn
                                          (setf (aref playfield posx posy) 1)
                                          (setf (aref playfield (+ posx 1) posy) 2) 
                                          (setf (aref playfield (+ posx 2) posy) 2)
                                          (setq marked nil)
                                          (incf pegs)
                                          (setq gameover (Playfieldcleared playfield))
                                          (Drawplayfield playfield variant pegs))))))))))
              (Drawplayfield playfield variant pegs)
              (if gameover
                  (if (or (and (= variant 1) (= pegs 31)) (and (= variant 2) (= pegs 35)))
                      (progn
                        (screen:set-window-cursor-position screen 4 22)
                        (format t "Congratulations! You got it."))
                      (progn
                        (screen:set-window-cursor-position screen 4 22)
                        (format t "No more moves possible!"))))
              (screen:set-window-cursor-position screen (+ posy 1) (+ (* posx 2) 1))
              when (eql key #\q) return()))))

(setq screen (screen:make-window))
(Play)

punchcard
Posts: 16
Joined: Fri Sep 26, 2014 5:50 pm

Re: cursing curses in clisp

Post by punchcard » Sat Oct 04, 2014 10:21 pm

Thanks I will have a play with that today.

punchcard
Posts: 16
Joined: Fri Sep 26, 2014 5:50 pm

Re: cursing curses in clisp

Post by punchcard » Tue Oct 14, 2014 9:01 am

quick update,

I have been expermenting with the graphics libraries in clisp and to be honest it strikes me as suffering from a lack of documentation and seems very fragile.

But aside from the gui, vecto is a great little library - was able to write a poster generator and get another program that prepaired my mail merge letters. So while I lost with the gui I won with the vector library. trying to get my head round ch-image.

Part of the problem with the libraries is lack fo documentation and examples. Its a shame because its like vecto has a decent amount of documentation and examples to make it simple to get started.

Post Reply