summaryrefslogtreecommitdiff
path: root/main.lisp
diff options
context:
space:
mode:
authorLogan Hunt <loganhunt@simponic.xyz>2022-05-31 23:23:58 -0700
committerLogan Hunt <loganhunt@simponic.xyz>2022-05-31 23:23:58 -0700
commita76bfbf944d8ac89b7581ed378f4782084aa404a (patch)
tree8bc2267a73c9e2c0c7d35cca304dcf406b376851 /main.lisp
parent10d7a20a79f8e7746d965cfadf1757b3e3799858 (diff)
downloadlispruns-a76bfbf944d8ac89b7581ed378f4782084aa404a.tar.gz
lispruns-a76bfbf944d8ac89b7581ed378f4782084aa404a.zip
User can create new category on the CLI
Diffstat (limited to 'main.lisp')
-rw-r--r--main.lisp46
1 files changed, 27 insertions, 19 deletions
diff --git a/main.lisp b/main.lisp
index cfe5d38..40823cd 100644
--- a/main.lisp
+++ b/main.lisp
@@ -20,7 +20,7 @@
(if (ignore-errors (funcall validator input))
input
(progn
- (format t "E: Invalid input. Try again.")
+ (format t "E: Invalid input. Try again.~%")
(get-input prompt validator)))))
;; Options is an alist with the prompt string as the car and the value as the cdr
@@ -53,6 +53,29 @@
(progn (format t "E: Could not find option that matched query.~%")
(select-option options)))))))
+(defun user-create-new-category ()
+ (let* ((name (get-input "Category Name (e.g. \"SM64\"): " 'empty-p))
+ (percentage (get-input "Percentage (e.g. \"16 Star\"): " 'empty-p))
+ (category (mito:insert-dao (make-instance 'category :name name :percentage percentage)))
+ (splits (do ((spliti 1 (1+ spliti))
+ (inputs '() (push (get-input (format nil "Split Name [~a]~a: " spliti (if (<= spliti 1) " (blank when done adding)" ""))) inputs)))
+ ((equal (car inputs) "")
+ (mapcar (lambda
+ (category-split-name)
+ (mito:insert-dao
+ (make-instance 'category-split
+ :name category-split-name
+ :category category)))
+ (reverse (cdr inputs)))))))))
+
+(defun with-selected-category (f)
+ (let* ((categories (mito:select-dao 'category))
+ (category-alist (mapcar (lambda (category) `(,(format nil "~a - ~a" (category-name category) (category-percentage category)) . ,category)) categories)))
+ (if categories
+ (funcall f (select-option category-alist))
+ (format t "E: There are no categories. Try creating one or importing one"))))
+
+
(defun main ()
(let ((choice (select-option '(("Help" . HELP)
("Import a category" . IMPORT-CATEGORY)
@@ -62,6 +85,7 @@
("Exit" . EXIT)))))
(case choice
('HELP
+ (format t "~%")
(mapcar #'(lambda (x) (format t "~a~%" x)) *lispruns-logo*))
('IMPORT-CATEGORY
(import-category (get-input
@@ -69,25 +93,9 @@
(uiop/os:getcwd))
'probe-file)))
('NEW-CATEGORY
- (let* ((name (get-input "Category Name (e.g. \"SM64\"): " 'not-empty-string))
- (percentage (get-input "Percentage (e.g. \"16 Star\"): " 'not-empty-string))
- (category (mito:insert-dao (make-instance 'category :name name :percentage percentage)))
- (splits (do ((spliti 1 (1+ spliti))
- (inputs '() (push (get-input (format nil "Split [~a]: " spliti)) inputs)))
- ((equal (car inputs) "")
- (mapcar (lambda
- (category-split-name)
- (mito:insert-dao
- (make-instance 'category-split
- :name category-split-name
- :category category)))
- (reverse (cdr inputs)))))))))
+ (user-create-new-category))
('START-SPEEDRUN
- (let* ((categories (mito:select-dao 'category))
- (category-alist (mapcar (lambda (category) `(,(format nil "~a - ~a" (category-name category) (category-percentage category)) . ,category)) categories)))
- (if categories
- (speedrun-ui (select-option category-alist))
- (format t "E: There are no categories. Try creating one or importing one"))))
+ (with-selected-category 'speedrun-ui))
('EXIT
(quit))))
(format t "~%")