#!/usr/bin/env -S sbcl --script
;; -*-lisp-*-
(require "uiop")
(defparameter output
  (with-output-to-string (out)
    (run-program "hyprctl"
                 '("getoption" "cursor:zoom_factor")
                 :search "/run/current-system/sw/bin/"
                 :output out)
    out))

(defun parse-string-to-float (string)
  (let ((*read-eval* nil))
    (with-input-from-string (stream string)
      (loop for number = (read stream nil nil)
            while number collect number))))

(defparameter zoom
  (car (parse-string-to-float
        (subseq output (+ (search "float: " output) 7) (+ (search "float: " output) 13)))))

(defparameter increment (+ zoom 0.3))
(defparameter decrement (- zoom 0.3))

(if (member "in" (uiop:command-line-arguments) :test #'string=)
    (run-program "hyprctl" `("keyword" "cursor:zoom_factor" ,(write-to-string increment))
                 :search "/run/current-system/sw/bin/"
                 :output *standard-output*)
    (if (member "out" (uiop:command-line-arguments) :test #'string=)
        (run-program "hyprctl" `("keyword" "cursor:zoom_factor" ,(write-to-string decrement))
                     :search "/run/current-system/sw/bin/"
                     :output *standard-output*)))
