aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/now.lua
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-10-18 14:31:39 +0200
committerDanilo M. <danix@danix.xyz>2026-10-18 14:31:39 +0200
commit28a3edc57047c2d8176e1cc726308c70f34ebc2e (patch)
treeb4783aa6b042f317af2331b3330d667406506438 /widgets/now.lua
parent719e1d98d61aa0614db86a9cab79402b304c4852 (diff)
downloadconky-theme-udt-28a3edc57047c2d8176e1cc726308c70f34ebc2e.tar.gz
conky-theme-udt-28a3edc57047c2d8176e1cc726308c70f34ebc2e.zip
feat(now): current-conditions card replaces the OWM weather card
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Diffstat (limited to 'widgets/now.lua')
-rw-r--r--widgets/now.lua51
1 files changed, 51 insertions, 0 deletions
diff --git a/widgets/now.lua b/widgets/now.lua
new file mode 100644
index 0000000..8fc6843
--- /dev/null
+++ b/widgets/now.lua
@@ -0,0 +1,51 @@
+-- Now: the current conditions. Replaces the OpenWeatherMap weather card; the
+-- daylight arc it carried moved to the sky card.
+--
+-- One of the forecast cards adapted from the Conky-Mirage theme by
+-- alexsson-xexpanderx (see lib/weather.lua).
+
+local card = require 'lib.card'
+local data = require 'lib.data'
+local weather = require 'lib.weather'
+
+local M = {}
+
+function M.draw(cr, rect, colors)
+ local inner = card.card(cr, rect, colors)
+ local w = weather.parse(data.slurp(weather.CACHE))
+ if not w then
+ -- Closed explicitly: this branch reruns every frame until a fetch lands,
+ -- so an unclosed handle would accumulate one per draw.
+ local envf = io.open((os.getenv('HOME') or '') .. '/.config/udt/weather.env', 'r')
+ local hint = 'set ~/.config/udt/weather.env'
+ if envf then
+ envf:close()
+ hint = 'bin/weather-fetch.sh'
+ end
+ card.notice(cr, inner, colors, 'WEATHER', 'no weather data', hint)
+ return
+ end
+
+ local c, today, now = w.current, w.days[1] or {}, os.time()
+ local rows = {
+ { 'FEELS LIKE', weather.deg(c.feels) },
+ { 'HIGH / LOW', weather.deg(today.max) .. ' / ' .. weather.deg(today.min) },
+ { 'RAIN', weather.num(today.precip, '%') },
+ { 'UPDATED', weather.age_str(c.dt, now),
+ weather.is_stale(c.dt, now) and colors.warning or nil },
+ }
+ local y, S = card.standard(cr, inner, colors, {
+ icon = weather.icon(c.code, c.is_day), title = 'WEATHER',
+ big = weather.deg(c.temp), rows = rows, share = 0.85,
+ })
+
+ -- The condition in words, in the prose face, in what the rows left.
+ local size = S * 0.36
+ if y + size * 1.4 <= inner.y + inner.h then
+ card.font(cr, card.FONT_UI, size, false)
+ card.rgba(cr, colors.body)
+ card.text(cr, inner.x, y + size * 1.4, weather.describe(c.code))
+ end
+end
+
+return M