cpu.lisp 798 B

123456789101112131415161718192021
  1. (in-package :stumpwm)
  2. (defun temp-current ()
  3. "Returns CPU temperature."
  4. (with-open-file (file #P"/sys/devices/virtual/thermal/thermal_zone0/temp" :if-does-not-exist nil)
  5. (let ((temp (read-line file)))
  6. (parse-integer
  7. (cond ((equal (car (coerce temp 'list)) #\1)
  8. (subseq temp 0 (length "000")))
  9. ((uiop/utility:string-suffix-p temp "000")
  10. (subseq temp 0 (- (length "000") 1)))
  11. (t temp))))))
  12. (defun fmt-temp-current (temp &optional color)
  13. "Returns a string representing the current CPU temperature."
  14. (if color
  15. (cond ((> temp 80) (format nil "^[^B^1*TEMP: ~D^]" temp))
  16. ((> temp 60) (format nil "^[^B^3*TEMP: ~D^]" temp))
  17. (t (format nil "TEMP: ~D" temp)))
  18. (format nil "TEMP: ~D" temp)))