Explorar o código

Basic config parsing working, need to add dynamic reload

Simon Watson hai 1 ano
pai
achega
e76a0ad41d
Modificáronse 3 ficheiros con 32 adicións e 2 borrados
  1. 3 0
      config.toml
  2. 1 1
      pest.asd
  3. 28 1
      pest.lisp

+ 3 - 0
config.toml

@@ -0,0 +1,3 @@
+[colors]
+fg = [23, 200, 150]
+bg = [0, 0, 0]

+ 1 - 1
pest.asd

@@ -2,5 +2,5 @@
   :version "0.0.1"
   :author "Simon Watson <swatson@casanacare.com>"
   :license "GPL"
-  :depends-on ("uiop" "cl-ppcre")
+  :depends-on ("uiop" "cl-ppcre" "chlorophyll" "clop")
   :components ((:file "pest")))

+ 28 - 1
pest.lisp

@@ -1,11 +1,38 @@
 
 ;; PROMPT_COMMAND='export PS1="$(pest)"'
 
+(defun config-parse (&optional path)
+  (let ((config-path (if path path (concatenate 'string (uiop:getenv "HOME") "/.config/pest/config.toml"))))
+    (if (probe-file config-path)
+	(with-open-file (fh config-path :direction :input)
+			   (let ((file-content (with-output-to-string (out)
+						 (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))))
+			   
+(defvar *config* (config-parse "/home/swatson/Repos/cl-pest/config.toml"))
+
+;; 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
+		 :bold NIL
+		 :foreground *fg*
+		 :background *bg*))
+
 ;; Regex Scanners
+;; TODO $HOME rendered as /home/user as opposed to ~
 (defvar *home-scan* (ppcre:create-scanner (concatenate 'string "^" (format NIL "~a" (user-homedir-pathname)))))
 
 (defun pwd ()
   (ppcre:regex-replace *home-scan* (uiop:getenv "PWD") "~/"))
 
 (defun main ()
-  (format T "~a ~%λ " (pwd)))
+  (setf *config* (config-parse "/home/swatson/Repos/cl-pest/config.toml"))
+  (format T "~a λ " (chlorophyll:stylize *style* (pwd))))