e76a0ad41d1a1a8191208bc8614e6d929bfe84b8
commit e76a0ad41d1a1a8191208bc8614e6d929bfe84b8
Author: Simon Watson <spesk@pm.me>
Date: Fri Aug 11 23:08:44 2023 -0400

Basic config parsing working, need to add dynamic reload

diff --git a/config.toml b/config.toml
new file mode 100644
index 0000000..02c120c
--- /dev/null
+++ b/config.toml
@@ -0,0 +1,3 @@
+[colors]
+fg = [23, 200, 150]
+bg = [0, 0, 0]
\ No newline at end of file
diff --git a/pest.asd b/pest.asd
index 73a14e2..8cc5a8c 100644
--- a/pest.asd
+++ b/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")))
diff --git a/pest.lisp b/pest.lisp
index 8a0d716..2846212 100644
--- a/pest.lisp
+++ b/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))))