فهرست منبع

Basic config reloader

Simon Watson 1 سال پیش
والد
کامیت
49cc7588b0
1فایلهای تغییر یافته به همراه19 افزوده شده و 12 حذف شده
  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))))