Browse Source

Basic config reloader

Simon Watson 8 months ago
parent
commit
49cc7588b0
1 changed files with 19 additions and 12 deletions
  1. 19 12
      pest.lisp

+ 19 - 12
pest.lisp

@@ -9,22 +9,29 @@
 						 (loop for line = (read-line fh nil)
 						       while line
 						       do (format out "~a~%" line)))))
-			     (clop:parse file-content)))
-	(format T "~A: File not found" config-path))))
+			     (clop:parse file-content))))))
 			   
-(defvar *config* (config-parse "/home/swatson/Repos/cl-pest/config.toml"))
+(defvar *config* NIL)
 
 ;; Colors
-(defvar *fg* (progn
-	       (if *config*
-		   (destructuring-bind (r g b) (subseq (assoc "fg" (cdr (assoc "colors" *config* :test #'equal)) :test #'equal) (- 4 3))
-		     (chlorophyll:create-rgb-color r g b))
-		   (chlorophyll:create-rgb-color 255 255 255))))
-(defvar *bg* (chlorophyll:create-rgb-color 0 0 0))
-(defvar *style* (chlorophyll:new-style
+(defvar *fg* NIL) 
+(defvar *bg* NIL) 
+(defvar *style* NIL)
+
+(defun reload-config ()
+  (setf *config* (config-parse "~/Repos/cl-pest/config.toml"))
+  (setf *fg* (if *config*
+		 (destructuring-bind (r g b) (subseq (assoc "fg" (cdr (assoc "colors" *config* :test #'equal)) :test #'equal) (- 4 3))
+		   (chlorophyll:create-rgb-color r g b))
+		 (chlorophyll:create-rgb-color 255 255 255)))
+  (setf *bg* (if *config*
+		 (destructuring-bind (r g b) (subseq (assoc "bg" (cdr (assoc "colors" *config* :test #'equal)) :test #'equal) (- 4 3))
+		   (chlorophyll:create-rgb-color r g b))
+		 (chlorophyll:create-rgb-color 0 0 0)))
+  (setf *style* (chlorophyll:new-style
 		 :bold NIL
 		 :foreground *fg*
-		 :background *bg*))
+		 :background *bg*)))
 
 ;; Regex Scanners
 ;; TODO $HOME rendered as /home/user as opposed to ~
@@ -34,5 +41,5 @@
   (ppcre:regex-replace *home-scan* (uiop:getenv "PWD") "~/"))
 
 (defun main ()
-  (setf *config* (config-parse "/home/swatson/Repos/cl-pest/config.toml"))
+  (reload-config)
   (format T "~a λ " (chlorophyll:stylize *style* (pwd))))