Many small changes, reducing redundancy and cleaning up the look

master
Brady McDonough 3 years ago
parent e5207ef018
commit 3c05b13940

@ -53,7 +53,7 @@
;; ERROR: mapconcat doesn't seem to respect lexical binding which leaves me unable to use a closure for a ticker
;; For now the code which relies on this will be noop'd
;; ERROR: tacc-tick is returning a (wrong-number-of-arguments) error.
;; ERROR: timer displays current time just fine, countdown is inverted, tag doesn't print
;; ERROR: tag doesn't print, countdown is ???
;; Optional
(require 'icicles nil t)
@ -265,7 +265,7 @@ registered" sym-name)
(define-derived-mode tacc-timer-mode
special-mode tacc-buffer-name
"Major mode for the tacc timer"
(setq-local lexical-binding t
(setq-local show-trailing-whitespace nil
tacc-locs `((clock-start . ,(copy-marker 0))
(clock-end . ,(copy-marker 0))
(graph-start . ,(copy-marker 0))
@ -321,8 +321,8 @@ Note, if there is no tacc-buffer then you shouldn't be touching tacc-info"
(defun tacc-chime-p (countdown-ts)
"Should I play a chime on this second?"
(if (time-less-p countdown-ts 0)
(mod (time-to-seconds countdown-ts)
tacc-chime-interval)))
(= 0 (mod (time-to-seconds countdown-ts)
tacc-chime-interval))))
(defun tacc-work-period (cycle)
"How long is the current work period?"
@ -341,9 +341,10 @@ Note, if there is no tacc-buffer then you shouldn't be touching tacc-info"
(defun tacc-est-ts (state cycle work-ts break-ts)
"Given the state and cycle, how long is the current time segment?"
(let ((start-ts (tacc-start-ts state work-ts break-ts)))
(time-add start-ts
(if (eq state 'work)
(tacc-work-period cycle)
(tacc-break-period cycle))))
(tacc-break-period cycle)))))
;; 05.3 State manipulation
@ -351,14 +352,14 @@ Note, if there is no tacc-buffer then you shouldn't be touching tacc-info"
"Time marches on. Called every second while a tacc timer is running"
(let* ((now (current-time))
(state (alist-get 'state tacc-info))
(cycle (funcall (alist-get 'cycle tacc-info)))
(cycle (funcall (alist-get 'cycle tacc-info) 't))
(work-ts (alist-get 'work-ts tacc-info))
(break-ts (alist-get 'break-ts tacc-info))
(start-ts (tacc-start-ts state work-ts break-ts))
(est (tacc-est-ts state cycle work-ts break-ts))
(countdown (time-subtract est now)))
(tacc-timer-buffer-update state now ) ;; HERE
(if tacc-play-sound-file
(tacc-timer-buffer-update state start-ts est countdown now)
(if (functionp tacc-play-sound-file)
(cond ((tacc-chime-p countdown)
(funcall tacc-play-sound-file tacc-sound-chime))
(t (funcall tacc-play-sound-file tacc-sound-tick))))))
@ -491,7 +492,7 @@ Note, if there is no tacc-buffer then you shouldn't be touching tacc-info"
(set-marker .graph-end (point-max))
(tacc-insert-between
.graph-start .graph-end
"Tag:\n"
"Tag: \n"
(tacc-graph-bar-render width 0.0 0.0 1.0)))))))
@ -502,12 +503,9 @@ Note, if there is no tacc-buffer then you shouldn't be touching tacc-info"
((eq state 'pause) tacc-pause-glyph)
((eq state 'stop) tacc-pause-glyph))))
(defun tacc-clock-render (state start est now)
(defun tacc-clock-render (state start countdown now)
"Draw the clock"
(let* ((elapsed (time-subtract now start))
(overwork (time-less-p elapsed est))
(countdown (if overwork (time-subtract elapsed est)
(time-subtract est elapsed)))
(let* ((overwork (time-less-p countdown 0))
(count-fmt (if overwork "+%M:%S" "-%M:%S"))
(count-face (cond (overwork 'tacc-overwork)
((eq state 'pause) 'tacc-clock-pause)
@ -517,17 +515,12 @@ Note, if there is no tacc-buffer then you shouldn't be touching tacc-info"
(propertize (format-time-string count-fmt countdown) 'face count-face)
(propertize (tacc-clock-glyph state) 'face 'tacc-clock))))
(defun tacc-current-tag-render ()
"Draw the tag name"
(concat "Tag: " (propertize (alist-get 'tag tacc-info "<None>")
'face 'tacc-tag)))
(defun tacc-graph-bar-render (width work break void)
"Return a graph bar width characters wide with the given proportions as \
float"
(let ((width (- width 2)))
(let ((width (- width 5)))
(concat
""
" "
(propertize (make-string (round (* width work)) tacc-graph-char)
'face 'tacc-graph-work)
(propertize (make-string (round (* width break)) tacc-graph-char)
@ -536,23 +529,26 @@ float"
'face 'tacc-graph-void)
" \n")))
(defun tacc-timer-buffer-update (state now)
(defun tacc-timer-buffer-update (state start-ts est-ts countdown now)
"Update the timer buffer rendering"
(tacc-render-with-buffer
(tacc-insert-between
.clock-start .clock-end
(let-alist tacc-info
(tacc-clock-render state .work-ts .end-ts now)))
(tacc-clock-render state start-ts countdown now)))
(tacc-insert-between
.graph-start .graph-end
(tacc-current-tag-render)
(let-alist tacc-info
(let* ((end (if (> now .end-ts) now .end-ts))
(concat
" Tag: " (propertize (if (string= .tag "") "<None>" .tag)
'face 'tacc-tag)
"\n"
(let* ((end (if (> now est-ts) now est-ts))
(total (- end .work-ts))
(work-prop (/ (- (if .break-ts .break-ts now) .work-ts) total))
(break-prop (/ (if .break-ts (- now .break-ts) 0) total))
(void-prop (- 1 (+ work-prop break-prop))))
(tacc-graph-bar-render width work-prop break-prop void-prop))))))
(tacc-graph-bar-render width work-prop break-prop void-prop)))))))
(defun tacc-new-graph-bar-render ()
(tacc-render-with-buffer

Loading…
Cancel
Save