1 (in-package #:clnl-cli)
4 (defvar *cli-dims* (list 0 0))
13 RESULT: undefined, should never get here
17 RUN runs the command line interface in the running terminal.
19 This should become the main REPL for a CLNL program. If you want to use you're
20 own REPL, you should use the rest of the functions in CLNL to recreate it."
24 :for str := (cffi:with-foreign-pointer-as-string (str 255) (wgetnstr *cli* str 255))
26 :do (print-command-and-response str (execute str)))
28 (sb-ext:exit :abort t))
32 (with-output-to-string (*standard-output*)
33 (clnl:run-commands str))
34 (error (e) (format nil "Ok, something went wrong: ~A" e))))
36 ; for ui, we need to do at a minimum:
37 ; - cli, first pass, read things in, bottom of the screen,
38 ; - just use getstr with a limit to be something like screen width - 10 for now
39 ; - print what the user inputted, dont' bomb on error messages, give target for show
40 ; - for overly long printing, go ahead and truncate with "..."
41 ; - for info, this should put out a simple message about the program, maintainer, purpose, links, etc
43 (defun init-interface ()
45 ((cli-height (min 10 (floor (* *lines* .3)))))
46 (setup-info (- *lines* cli-height) *cols*)
47 (setup-cli cli-height *cols* (- *lines* cli-height))))
50 (wmove *cli* (1- (car *cli-dims*)) 0)
51 (whline *cli* (char-code #\Space) (cadr *cli-dims*))
52 (mvwprintw *cli* (1- (car *cli-dims*)) 0 ">")
53 (wmove *cli* (1- (car *cli-dims*)) 2)
56 (defun print-command-and-response (command response)
58 :for i :from 1 :to (- (car *cli-dims*) 3)
60 :do (whline *cli* (char-code #\Space) (cadr *cli-dims*)))
61 (mvwprintw *cli* 1 0 (format nil "> ~A" command))
62 (mvwprintw *cli* 3 0 (format nil "~A" response))
65 (defun setup-cli (height width top)
66 (setf *cli* (newwin height width top 0))
67 (setf *cli-dims* (list height width))
68 (whline *cli* 0 (cadr *cli-dims*))
69 (wmove *cli* (- (car *cli-dims*) 2) 0)
70 (whline *cli* (char-code #\.) (cadr *cli-dims*))
71 (wmove *cli* (1- (car *cli-dims*)) 2)
75 (defun setup-info (num-tall num-wide)
79 / \\ Welcome to CLNL version ~A!
83 CLNL is an experiment at creating an alternate
84 implementation of NetLogo.
86 You can enter in various netlogo commands below,
87 or use :q to quit the program.
89 See http://github.com/frankduncan/clnl for more
90 information about CLNL and to keep apprised of
91 any updates that may happen.")
92 (info-height (length (cl-ppcre:split "\\n" info)))
93 (info-width (apply #'max (mapcar #'length (cl-ppcre:split "\\n" info)))))
97 (max 0 (floor (- num-tall info-height) 2))
98 (max 0 (floor (- num-wide info-width) 2))))
101 (asdf:component-version (asdf:find-system :clnl))))