summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/test-wttrin--mode-line-update-display.el26
-rw-r--r--wttrin.el10
2 files changed, 36 insertions, 0 deletions
diff --git a/tests/test-wttrin--mode-line-update-display.el b/tests/test-wttrin--mode-line-update-display.el
index 81fbded..0635b5f 100644
--- a/tests/test-wttrin--mode-line-update-display.el
+++ b/tests/test-wttrin--mode-line-update-display.el
@@ -210,6 +210,32 @@
(should-not wttrin-mode-line-string))
(test-wttrin--mode-line-update-display-teardown)))
+(ert-deftest test-wttrin--mode-line-update-display-stale-emoji-dims-on-hover-transition ()
+ "When data crosses the stale threshold between refreshes, hovering should
+trigger an emoji re-render so dimming matches the tooltip's staleness state."
+ (test-wttrin--mode-line-update-display-setup)
+ (unwind-protect
+ (let ((wttrin-mode-line-refresh-interval 900)
+ (wttrin-mode-line-emoji-font nil))
+ ;; Initial render: data is fresh (age=200, threshold=1800)
+ (cl-letf (((symbol-function 'float-time) (lambda () 1200.0)))
+ (setq wttrin--mode-line-cache (cons 1000.0 "Paris: X +61°F Clear"))
+ (wttrin--mode-line-update-display)
+ ;; Emoji should NOT be dimmed
+ (let ((face (get-text-property 1 'face wttrin-mode-line-string)))
+ (should-not (and face (equal (plist-get face :foreground) "gray60")))))
+
+ ;; Time passes: data is now stale (age=2001, threshold=1800)
+ ;; Invoke the tooltip (simulating a hover) — this should trigger a re-render
+ (cl-letf (((symbol-function 'float-time) (lambda () 3001.0)))
+ (let ((help-echo-fn (get-text-property 0 'help-echo wttrin-mode-line-string)))
+ (funcall help-echo-fn nil nil nil))
+ ;; After hover detected staleness transition, emoji should now be dimmed
+ (let ((face (get-text-property 1 'face wttrin-mode-line-string)))
+ (should face)
+ (should (equal (plist-get face :foreground) "gray60")))))
+ (test-wttrin--mode-line-update-display-teardown)))
+
;;; --------------------------------------------------------------------------
;;; wttrin--mode-line-fetch-weather
;;; --------------------------------------------------------------------------
diff --git a/wttrin.el b/wttrin.el
index c2cb74d..e584d3c 100644
--- a/wttrin.el
+++ b/wttrin.el
@@ -200,6 +200,9 @@ Set this to t BEFORE loading wttrin, typically in your init file:
When non-nil, car is the `float-time' when data was fetched,
and cdr is the weather string from the API.")
+(defvar wttrin--mode-line-rendered-stale nil
+ "Whether the mode-line emoji is currently rendered as stale (dimmed).")
+
(defvar wttrin--mode-line-map
(let ((map (make-sparse-keymap)))
(define-key map [mode-line mouse-1] 'wttrin-mode-line-click)
@@ -594,6 +597,8 @@ On failure with no cache, shows error placeholder."
(defun wttrin--mode-line-tooltip (&optional _window _object _pos)
"Compute tooltip text from `wttrin--mode-line-cache'.
Calculates age at call time so the tooltip is always current.
+If staleness has changed since the last render, triggers a re-render
+so the emoji dimming matches.
Optional arguments are ignored (required by `help-echo' function protocol)."
(when wttrin--mode-line-cache
(let* ((timestamp (car wttrin--mode-line-cache))
@@ -601,6 +606,9 @@ Optional arguments are ignored (required by `help-echo' function protocol)."
(age (- (float-time) timestamp))
(stale-p (> age (* 2 wttrin-mode-line-refresh-interval)))
(age-str (wttrin--format-age age)))
+ ;; Re-render emoji if staleness state has changed
+ (unless (eq stale-p wttrin--mode-line-rendered-stale)
+ (wttrin--mode-line-update-display))
(if stale-p
(format "%s\nStale: updated %s — fetch failed, will retry"
weather-string age-str)
@@ -623,6 +631,7 @@ shows staleness info in tooltip."
"?")))
(wttrin--debug-log "mode-line-display: Extracted emoji = %S, stale = %s"
emoji stale-p)
+ (setq wttrin--mode-line-rendered-stale stale-p)
(setq wttrin-mode-line-string
(propertize (concat " " (wttrin--make-emoji-icon emoji (when stale-p "gray60")))
'help-echo #'wttrin--mode-line-tooltip
@@ -708,6 +717,7 @@ opens the weather buffer."
(setq wttrin--buffer-refresh-timer nil))
(setq wttrin-mode-line-string nil)
(setq wttrin--mode-line-cache nil)
+ (setq wttrin--mode-line-rendered-stale nil)
(force-mode-line-update t))
;;;###autoload