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 :while (and (string/= str "q") (string/= str "Q"))
27 :do (print-command-and-response str (execute str)))
29 (sb-ext:exit :abort t))
33 (with-output-to-string (*standard-output*)
34 (clnl:run-commands str))
35 (error (e) (format nil "Ok, something went wrong: ~A" e))))
37 ; for ui, we need to do at a minimum:
38 ; - cli, first pass, read things in, bottom of the screen,
39 ; - just use getstr with a limit to be something like screen width - 10 for now
40 ; - print what the user inputted, dont' bomb on error messages, give target for show
41 ; - for overly long printing, go ahead and truncate with "..."
42 ; - for info, this should put out a simple message about the program, maintainer, purpose, links, etc
44 (defun init-interface ()
46 ((cli-height (min 10 (floor (* *lines* .3)))))
47 (setup-info (- *lines* cli-height) *cols*)
48 (setup-cli cli-height *cols* (- *lines* cli-height))))
51 (wmove *cli* (1- (car *cli-dims*)) 0)
52 (whline *cli* (char-code #\Space) (cadr *cli-dims*))
53 (mvwprintw *cli* (1- (car *cli-dims*)) 0 ">")
54 (wmove *cli* (1- (car *cli-dims*)) 2)
57 (defun print-command-and-response (command response)
59 :for i :from 1 :to (- (car *cli-dims*) 3)
61 :do (whline *cli* (char-code #\Space) (cadr *cli-dims*)))
62 (mvwprintw *cli* 1 0 (format nil "> ~A" command))
63 (mvwprintw *cli* 3 0 (format nil "~A" response))
66 (defun setup-cli (height width top)
67 (setf *cli* (newwin height width top 0))
68 (setf *cli-dims* (list height width))
69 (whline *cli* 0 (cadr *cli-dims*))
70 (wmove *cli* (- (car *cli-dims*) 2) 0)
71 (whline *cli* (char-code #\.) (cadr *cli-dims*))
72 (wmove *cli* (1- (car *cli-dims*)) 2)
76 (defun setup-info (num-tall num-wide)
80 / \\ Welcome to CLNL version ~A!
84 CLNL is an experiment at creating an alternate
85 implementation of NetLogo.
87 You can enter in various netlogo commands below,
88 or use q to quit the program.
90 See http://github.com/frankduncan/clnl for more
91 information about CLNL and to keep apprised of
92 any updates that may happen.")
93 (info-height (length (cl-ppcre:split "\\n" info)))
94 (info-width (apply #'max (mapcar #'length (cl-ppcre:split "\\n" info)))))
98 (max 0 (floor (- num-tall info-height) 2))
99 (max 0 (floor (- num-wide info-width) 2))))
100 (mvwprintw *info* 1 0
102 (asdf:component-version (asdf:find-system :clnl))))