From: Frank Duncan Date: Fri, 19 Jun 2015 15:54:20 +0000 (-0500) Subject: Add simple ncurses command center X-Git-Tag: v0.0.0~4 X-Git-Url: https://code.consxy.com/gitweb/?a=commitdiff_plain;h=fe712aa779be8210646dd5a74a665644232de3cb;p=clnl Add simple ncurses command center --- diff --git a/.travis.yml b/.travis.yml index 0f8766c..58afb74 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ addons: before_install: - export DISPLAY=:99.0 - /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x24 - - wget http://frank.kank.net/travissbcl/clnl/ee78f42/$(git rev-parse HEAD)/travissbcl + - wget http://frank.kank.net/travissbcl/clnl/076c72b/$(git rev-parse HEAD)/travissbcl - chmod +x travissbcl script: - ./travissbcl --script bin/travis.lisp diff --git a/README.md b/README.md index 9b39225..5d79c7d 100644 --- a/README.md +++ b/README.md @@ -10,36 +10,48 @@ If you'd like to build it, you're going to need a few things: * An implementation of sbcl with threads enabled * The following common lisp libraries (included in deps/tarpit folder) - * cl-opengl * alexandria * babel * cffi + * cl-charms + * cl-opengl + * cl-ppcre + * docgen * ironclad * mt19937 * nibbles * trivial-features * style-checker - * docgen * rlwrap -# Running +# Running as a program -bin/nl has been added for convenience to run the netlogo instance. Currently it bombs if you try to do anything to expressive with it. A good test is +bin/nl has been added for convenience to run the netlogo instance. It boots up the ncurses command line with an opengl view. Not very many commands are implemented, but it should alert you to that. A good test is ``` crt 10 ask turtles [ fd 1 ] show random 5 +ask turtles [ fd 5 ] ``` +# Running in a common lisp instance + If you'd like to run using your own sbcl instance, you can attach the clnl.asd file wherever you link asd files, and then use: ```lisp (asdf:load-system :clnl) -(sb-thread:make-thread #'clnl-interface:run) (clnl:run) ``` +To view the opengl view, you'll want to open up the interface: + +```lisp +(sb-thread:make-thread #'clnl-interface:run) +``` + +(On OSX, the interface should be the main thread) + # Testing If you'd like to see the tests go on your system, there's a number of utilities to look at: diff --git a/bin/buildtravisexec.sh b/bin/buildtravisexec.sh index 3185576..f61938a 100755 --- a/bin/buildtravisexec.sh +++ b/bin/buildtravisexec.sh @@ -20,6 +20,7 @@ mkdir -p tmp/deps/ tar zxf ../../deps/tarpit/mt19937-latest.tar.gz && tar zxf ../../deps/tarpit/nibbles-v0.12.tar.gz && tar zxf ../../deps/tarpit/trivial-features_0.8.tar.gz && + tar zxf ../../deps/tarpit/cl-charms-9bb94ef.tar.gz && tar zxf ../../deps/tarpit/style-checker_0.1.tar.gz && tar zxf ../../deps/tarpit/docgen_0.1.tar.gz && ln -s cl-ppcre-2.0.10/cl-ppcre.asd . && @@ -37,8 +38,9 @@ mkdir -p tmp/deps/ ln -s cffi_0.15.0/cffi-grovel.asd . && ln -s cffi_0.15.0/cffi-uffi-compat.asd . && ln -s trivial-features_0.8/trivial-features.asd . && + ln -s cl-charms/cl-charms.asd . && ln -s style-checker_0.1/style-checker.asd . && - ln -s docgen_0.1/docgenasd . + ln -s docgen_0.1/docgen.asd . ) @@ -50,6 +52,7 @@ SBCL_HOME="" tmp/sbcl/bin/sbcl --core tmp/sbcl/lib/sbcl/sbcl.core \ --eval "(asdf:load-system :ironclad)" \ --eval "(asdf:load-system :cl-opengl)" \ --eval "(asdf:load-system :cl-glut)" \ + --eval "(asdf:load-system :cl-charms)" \ --eval "(asdf:load-system :style-checker)" \ --eval "(asdf:load-system :docgen)" \ --eval "(asdf:clear-output-translations)" \ diff --git a/bin/nl b/bin/nl index c14aa97..2751c5e 100755 --- a/bin/nl +++ b/bin/nl @@ -1,3 +1,3 @@ #!/bin/bash -rlwrap sbcl --script bin/run.lisp +sbcl --script bin/run.lisp diff --git a/bin/run.lisp b/bin/run.lisp index 8b46a2a..4aa55dd 100644 --- a/bin/run.lisp +++ b/bin/run.lisp @@ -3,4 +3,4 @@ (push #p"deps/" asdf:*central-registry*) (asdf:load-system :clnl) (sb-thread:make-thread #'clnl-interface:run) -(clnl:run) +(clnl-cli:run) diff --git a/bin/travis.lisp b/bin/travis.lisp index 153e1c5..511cbc7 100644 --- a/bin/travis.lisp +++ b/bin/travis.lisp @@ -17,7 +17,7 @@ (format t "~%~c[1;33mChecking Docs~c[0m~%" #\Esc #\Esc) (when (not (docgen:pretty-print-validate-packages - :clnl :clnl-parser :clnl-random :clnl-transpiler :clnl-nvm :clnl-lexer :clnl-interface)) + :clnl :clnl-parser :clnl-random :clnl-transpiler :clnl-nvm :clnl-lexer :clnl-interface :clnl-cli)) (format t "~c[1;31mFailed doc check!~c[0m~%" #\Esc #\Esc) (sb-ext:exit :code 1)) (format t "~c[1;32m- Doc Check Passed!~c[0m~%" #\Esc #\Esc) diff --git a/deps/tarpit/cl-charms-9bb94ef.tar.gz b/deps/tarpit/cl-charms-9bb94ef.tar.gz new file mode 100644 index 0000000..4134340 Binary files /dev/null and b/deps/tarpit/cl-charms-9bb94ef.tar.gz differ diff --git a/src/main/cli.lisp b/src/main/cli.lisp new file mode 100644 index 0000000..dc3e312 --- /dev/null +++ b/src/main/cli.lisp @@ -0,0 +1,98 @@ +(in-package #:clnl-cli) + +(defvar *cli* nil) +(defvar *cli-dims* (list 0 0)) + +(defvar *info* nil) + +(defun run () + "RUN => RESULT + +ARGUMENTS AND VALUES: + + RESULT: undefined, should never get here + +DESCRIPTION: + + RUN runs the command line interface in the running terminal. + + This should become the main REPL for a CLNL program. If you want to use you're + own REPL, you should use the rest of the functions in CLNL to recreate it." + (initscr) + (init-interface) + (loop + :for str := (cffi:with-foreign-pointer-as-string (str 255) (wgetnstr *cli* str 255)) + :while str + :while (and (string/= str "q") (string/= str "Q")) + :do (print-command-and-response str (execute str))) + (endwin) + (sb-ext:exit :abort t)) + +(defun execute (str) + (handler-case + (with-output-to-string (*standard-output*) + (clnl:run-commands str)) + (error (e) (format nil "Ok, something went wrong: ~A" e)))) + +; for ui, we need to do at a minimum: +; - cli, first pass, read things in, bottom of the screen, +; - just use getstr with a limit to be something like screen width - 10 for now +; - print what the user inputted, dont' bomb on error messages, give target for show +; - for overly long printing, go ahead and truncate with "..." +; - for info, this should put out a simple message about the program, maintainer, purpose, links, etc + +(defun init-interface () + (let + ((cli-height (min 10 (floor (* *lines* .3))))) + (setup-info (- *lines* cli-height) *cols*) + (setup-cli cli-height *cols* (- *lines* cli-height)))) + +(defun refresh-cli () + (wmove *cli* (1- (car *cli-dims*)) 0) + (whline *cli* (char-code #\Space) (cadr *cli-dims*)) + (mvwprintw *cli* (1- (car *cli-dims*)) 0 ">") + (wmove *cli* (1- (car *cli-dims*)) 2) + (wrefresh *cli*)) + +(defun print-command-and-response (command response) + (loop + :for i :from 1 :to (- (car *cli-dims*) 3) + :do (wmove *cli* i 0) + :do (whline *cli* (char-code #\Space) (cadr *cli-dims*))) + (mvwprintw *cli* 1 0 (format nil "> ~A" command)) + (mvwprintw *cli* 3 0 (format nil "~A" response)) + (refresh-cli)) + +(defun setup-cli (height width top) + (setf *cli* (newwin height width top 0)) + (setf *cli-dims* (list height width)) + (whline *cli* 0 (cadr *cli-dims*)) + (wmove *cli* (- (car *cli-dims*) 2) 0) + (whline *cli* (char-code #\.) (cadr *cli-dims*)) + (wmove *cli* (1- (car *cli-dims*)) 2) + (wrefresh *cli*) + (refresh-cli)) + +(defun setup-info (num-tall num-wide) + (setf *info* (newwin 20 60 (floor (- num-tall 20) 2) (floor (- num-wide 60) 2))) + (mvwprintw *info* 1 1 + (format nil + " + . + / \\ + / \\ Welcome to CLNL version ~A! + / \\ + /_______\\ + + CLNL is an experiment at creating an alternate + implementation of NetLogo. + + You can enter in various netlogo commands below, + or use q to quit the program. + + See http://github.com/frankduncan/clnl for more + information about CLNL and to keep apprised of + any updates that may happen." + (asdf:component-version (asdf:find-system :clnl)))) + (box *info* 0 0) + (wrefresh *info*)) diff --git a/src/main/clnl.asd b/src/main/clnl.asd index 91fdf1e..096427b 100644 --- a/src/main/clnl.asd +++ b/src/main/clnl.asd @@ -16,6 +16,7 @@ (:file "transpile") (:file "random") (:file "interface") + (:file "cli") (:file "main"))) (asdf:defsystem clnl @@ -23,4 +24,4 @@ :version "0.0.1" :maintainer "Frank Duncan (frank@kank.com)" :author "Frank Duncan (frank@kank.com)" - :depends-on (:cl-ppcre :mt19937 :cl-opengl :cl-glut :clnl.internal)) + :depends-on (:cl-ppcre :mt19937 :cl-opengl :cl-glut :cl-charms :clnl.internal)) diff --git a/src/main/interface.lisp b/src/main/interface.lisp index 92f292a..b2c359e 100644 --- a/src/main/interface.lisp +++ b/src/main/interface.lisp @@ -60,7 +60,7 @@ (cl-glut:post-redisplay)) (defun close-func () - (sb-ext:exit)) + (sb-ext:exit :abort t)) (defun reshape (width height) (when (and (/= 0 width) (/= 0 height)) diff --git a/src/main/nvm.lisp b/src/main/nvm.lisp index bf8981a..41f47b2 100644 --- a/src/main/nvm.lisp +++ b/src/main/nvm.lisp @@ -22,6 +22,9 @@ DESCRIPTION: See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#show" (format t "Showing: ~A~%" (dump-object value))) +(defun world-dimensions () + (list :xmin -10 :xmax 10 :ymin -10 :ymax 10)) + (defun create-turtle () (setf *turtles* diff --git a/src/main/package.lisp b/src/main/package.lisp index 111aa9e..e745926 100644 --- a/src/main/package.lisp +++ b/src/main/package.lisp @@ -79,3 +79,13 @@ The primary code responsible for tokenizing NetLogo code.")) The NetLogo view interface using opengl. This is responsible for taking the current state of the enging and displaying it. Will not house any interface components.")) + +(defpackage #:clnl-cli + (:use :common-lisp :cl-charms/low-level) + (:export :run) + (:documentation + "CLNL CLI + +The main NetLogo interface for interacting with the program. Since CLNL is +a command line interface program with a view for display purposes only, this +is where all the features that the traditional NetLogo UI lives."))