This commit is contained in:
jjanzen 2025-03-17 11:09:42 -05:00
parent 925d09422d
commit ca655aef50

View file

@ -80,42 +80,22 @@
(defun pomodoro-get-status-string ()
"Get the status string for the pomodoro timer. May update the state if necessary."
(let ((curr-time) ;; the current Unix time
(symbol) ;; the symbol to be displayed
(delta) ;; the difference in time
(max-time) ;; the maximum time that can be represented in the current state
(minutes) ;; the number of minutes to display
(seconds)) ;; the number of seconds to display
;; check how far into the countdown we are
(setq curr-time (floor (float-time)))
(setq delta (- curr-time pomodoro-start-time))
(cond ((equal pomodoro-state 'working)
(setq symbol pomodoro-work-symbol)
(setq max-time pomodoro-work-time))
((equal pomodoro-state 'break)
(setq symbol pomodoro-break-symbol)
(setq max-time pomodoro-break-time))
(t
(setq symbol "")
(setq max-time 0)))
(if (>= delta max-time)
(setq delta max-time))
(setq delta (- max-time delta))
;; Get the time in minutes and seconds
(setq minutes (/ delta 60))
(setq seconds (% delta 60))
;; Changing state here kinda violates the single-responsibility principle,
;; but this also prevents me from needing to work with timers which might
;; just be worse that a function that does more than one thing.
(if (<= delta 0)
(progn
(setq delta 0)
(pomodoro-toggle-state)))
(let* ((curr-time (floor (float-time)))
(delta (- curr-time pomodoro-start-time))
(symbol (if (equal pomodoro-state 'working)
pomodoro-work-symbol
pomodoro-break-symbol))
(max-time (if (equal pomodoro-state 'working)
pomodoro-work-time
pomodoro-break-time))
(delta-trunc (if (>= delta max-time)
max-time
delta))
(time-value (- max-time delta-trunc))
(minutes (/ time-value 60))
(seconds (% time-value 60)))
(if (<= time-value 0)
(pomodoro-toggle-state))
(format " %s (%02d:%02d)" symbol minutes seconds)))
(define-minor-mode pomodoro-local-mode