From e6fe31daef40bec71e962c502f3a17ff9fa59d31 Mon Sep 17 00:00:00 2001 From: Logan Hunt Date: Tue, 31 May 2022 10:31:37 -0700 Subject: [PATCH] Add some more helpful error messages, fix CLI (some features still need implementation), add category selection for starting speedrun --- main.lisp | 25 +++++++++++++------------ ui.lisp | 40 ++++++++++++++++++++++++++++------------ 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/main.lisp b/main.lisp index 8d0d704..57a1d29 100644 --- a/main.lisp +++ b/main.lisp @@ -19,7 +19,9 @@ (let ((input (read-line))) (if (ignore-errors (funcall validator input)) input - (get-input prompt validator)))) + (progn + (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 (defun select-option (options) @@ -49,8 +51,7 @@ (format t "That search came up with multiple results:") (select-option filtered))) (progn (format t "E: Could not find option that matched query.~%") - (select-option options)))))) - (format t "~%")) + (select-option options))))))) (defun main () (let ((choice (select-option '(("Help" . HELP) @@ -59,23 +60,23 @@ ("Start a speedrun" . START-SPEEDRUN) ("Statistics" . LIST-CATEGORIES) ("Exit" . EXIT))))) - (format t "~a~%" choice) (case choice ('HELP (mapcar #'(lambda (x) (format t "~a~%" x)) *lispruns-logo*)) ('IMPORT-CATEGORY - (import-category (get-input (format nil "Relative or absolute path to configuration file [~a]: " (uiop/os:getcwd)) 'probe-file))) + (import-category (get-input + (format nil "Relative or absolute path to configuration file [~a]: " + (uiop/os:getcwd)) + 'probe-file))) ('NEW-CATEGORY (format t "NEW CATEGORY~%")) ('START-SPEEDRUN - (speedrun-ui (car (mito:select-dao 'category)))) + (let* ((categories (mito:select-dao 'category)) + (category-alist (mapcar (lambda (category) `(,(category-name category) . ,category)) categories))) + (if categories + (speedrun-ui (select-option category-alist)) + (format t "E: There are no categories. Try creating one or importing one")))) ('EXIT (quit)))) (format t "~%") (main)) - - -;; (let ((options (opts:get-opts))) -;; (when-option (options :import) -;; (import-config (getf options :import))) -;; (run-ui (car (mito:select-dao 'category))))) diff --git a/ui.lisp b/ui.lisp index 938e857..697b9ee 100644 --- a/ui.lisp +++ b/ui.lisp @@ -96,28 +96,38 @@ ('TITLE (if (member 'title-instance redraws) (croatoan:clear scr) - (let* ((padding 3) - (width (+ (* 2 padding) (max-length *lispruns-logo*))) - (height (+ (* 2 padding) (length *lispruns-logo*))) + (let* ((padding 4) + (title (append *lispruns-logo* '("" "CONTROLS" " SPACE to start or continue to the next split" " Q to quit"))) + (width (+ (* 2 padding) (max-length title))) + (height (+ (* 2 padding) (length title))) (logo-centered (center-box scr width height)) (logo-box (make-instance 'croatoan:window :border t :width width :height height :position logo-centered))) - (write-horizontal-slice-list logo-box `(,padding ,padding) *lispruns-logo*) - (croatoan:refresh logo-box)))) + (if (< (croatoan:width scr) width) + (progn + (croatoan:add scr "Please increase width of your terminal" :position '(0 0)) + (croatoan:refresh scr)) + (progn + (write-horizontal-slice-list logo-box `(,padding ,padding) title) + (croatoan:refresh logo-box)))))) ('RUNNING - (update-time speedrun) + (if (eq (speedrun-state speedrun) 'RUNNING) + (update-time speedrun)) (if (member 'timer-instance redraws) (croatoan:clear scr)) (if (zerop (mod frame 4)) - (let* ((screen-thirds (floor (/ (croatoan:width scr) 3))) + (let* ((max-width (min 90 (croatoan:width scr))) + (centered-x (cadr (center-box scr max-width 0))) + (timer-height 8) + (splits-height (- (croatoan:height scr) timer-height)) (split-list (make-instance 'highlight-list :scroll-i scroll :current-element-index (if (eq (speedrun-state speedrun) 'STOPPED) (1- (length (speedrun-splits speedrun))) (speedrun-current-split-index speedrun)) - :height (croatoan:height scr) - :width screen-thirds + :height splits-height + :width max-width :elements (mapcar #'category-split-name csplits))) ;; :elements `((("FIRST SPLIT IS EPIC" . ,(/ 4 12)) ("" . ,(/ 1 12)) ("10:10:00.22" . ,(/ 3 12)) ("" . ,(/ 1 12)) ("20:00.00" . ,(/ 3 12)))))) - (splits-instance (highlight-list-window split-list '(0 0))) - (timer-instance (timer-window speedrun `(0 ,screen-thirds) (* 2 screen-thirds) 8))) + (splits-instance (highlight-list-window split-list `(0 ,centered-x))) + (timer-instance (timer-window speedrun `(,splits-height ,centered-x) max-width timer-height))) (croatoan:refresh splits-instance) (croatoan:refresh timer-instance))))) (setf redraws '() @@ -134,5 +144,11 @@ (setf redraws '(timer-instance)) (setf state 'RUNNING)) ('RUNNING (next-split speedrun)))) - (:resize (render)) + (:resize + (case state + ('TITLE + (setf redraws '(title-instance))) + ('RUNNING + (croatoan:clear scr))) + (render)) ((nil) (render)))))))