Repository navigation
Description
Summary
Add the mechanism and the control that let a user pick the visual theme of the dashboard. The choice is stored per browser, applied before the first paint, independent of the light/dark mode, and defaults to the theme "Clear" from #217. This issue delivers the infrastructure and the selector; the additional themes "Console" and "Berry" are separate issues in this milestone and plug into what is built here.
Problem
v1.5.0 brings three designs for the dashboard. All three should ship, and each user should be able to choose the one they prefer, with "Clear" as the default. Today the dashboard has exactly one look and only a light/dark switch; there is no place to register a second design, no storage for the choice and no control to make it.
Terminology
- Mode — light or dark. Existing behaviour:
pimonitor-themeinlocalStorage,data-themeon<html>, the header toggle, followingprefers-color-schemewhen nothing is stored. Unchanged by this issue. - Theme — the visual design. Ids and display names:
| Id | Display name | Issue |
|---|---|---|
clear |
Clear | #217 (default) |
console |
Console | separate issue in this milestone |
berry |
Berry | separate issue in this milestone |
Every theme exists in both modes, so the user has theme × mode = up to six appearances.
Because the existing storage key and attribute for the mode are already called "theme", the new key and attribute need a different name. Proposed: localStorage key pimonitor-style and attribute data-style on <html>. The existing key pimonitor-theme must keep its name and meaning, otherwise every user loses the stored mode on upgrade. If the spec picks other names, the reasons go into the decision record.
Specification
1. Theme registry
- There is one list of known themes with id and display name, in display order, default first. It is the single source for the selector and for validating a stored value.
theme-init.jsruns beforeapp.jsand before first paint and needs to validate the stored id too. If that means a second copy of the id list, a test must keep the two lists identical (the same approach as the fallback threshold keys, seethresholds_test.go).- Adding a theme must be possible by adding its registry entry and its style rules, without touching the selection logic.
2. Applying a theme
- The active theme is expressed as
data-style="<id>"on<html>. The default theme may be expressed either asdata-style="clear"or as the absence of the attribute; the spec decides, the rules below hold either way. - A theme is implemented as CSS overrides of custom properties and rules scoped to its
data-stylevalue. The page has one DOM for all themes;index.htmldoes not contain per-theme markup variants, andapp.jshas no per-theme rendering branches for HTML content. - Canvas widgets (
chart.js,gauge.js) cannot be restyled by CSS. Where a theme needs a different drawing (line width, cap style, stepped vs straight line, arc vs ring, fill opacity), the renderer reads declared custom properties from the computed style of the document, the waydrawSparklinealready reads--accentanddrawGaugereads the track and level colours. This issue establishes that pattern and documents the properties that exist after [Dashboard] Refresh the default look: theme "Clear" (light and dark) #217 (colours, line width, track); the Console and Berry issues add the properties they need. Unknown or missing values fall back to the Clear drawing. - Mode and theme are orthogonal. Each theme provides its light values, its dark values for
[data-theme="dark"]and the same dark values for@media (prefers-color-scheme: dark)with:root:not([data-theme]). A test keeps the token key sets of all blocks of all themes identical, so a theme cannot forget a token and silently inherit a colour from another theme. - How the stylesheet is organised — one file, or one file per theme, all linked statically — is the plan's decision. Additional files are served like every other asset (
internal/web/embed.go:no-cache, per-fileETag) and must be covered by the asset tests. Loading a theme's stylesheet on demand is not required and must not cause a flash.
3. Storage
- The choice is stored in
localStorageunderpimonitor-stylewith the theme id as value. - On load,
theme-init.jsreads the key and applies the theme before the first paint, next to the stored mode, so the page never flashes the default theme first. - A missing key, an unknown id (for example after a downgrade, or a theme that was removed) or unreadable storage means the default theme
clear. An unknown stored value is ignored, not deleted, and not treated as an error. - When storage is unavailable (private browsing, blocked storage) the selector still works for the current page; nothing is stored and no error is shown — the same rule the mode and the layout follow today.
- After this issue the dashboard stores exactly four
localStorageentries:pimonitor-api-key,pimonitor-theme,pimonitor-layout,pimonitor-style. - There is no server-side theme setting: no configuration option, no API field. The choice is per browser, like mode and layout.
4. The selector
- The selector lives in the existing "Customize dashboard" dialog (
#layout-modal), in a new section "Theme" above the card list. The dialog is already the place for per-browser appearance preferences, so no new header button is needed and the header stays as it is. - It is a group of radio inputs, one per registered theme, inside a
<fieldset>with a<legend>; each option shows the display name. It is fully operable by keyboard and announced as a radio group by assistive technology. - Selecting an option applies the theme immediately, without a reload and without closing the dialog, and stores it. Charts and gauges are redrawn at once in the new theme, exactly as on a mode switch (
applyTheme()already repaints the canvas widgets; reuse that path). - The selected option reflects the active theme whenever the dialog opens, including after a reload.
- The header's light/dark button keeps working in every theme and is not affected by the selection.
- While only one theme is registered, the "Theme" section is not shown. This lets this issue be merged on its own after [Dashboard] Refresh the default look: theme "Clear" (light and dark) #217; the section appears with the first additional theme. The tests for the selector use more than one registered theme regardless of what the shipped registry holds at that time. If the plan prefers to deliver this issue together with the Console theme in one pull request, that is fine as long as the acceptance criteria of both issues hold.
- "Reset to default" in the dialog resets the card layout only, as its hint text says today. Whether it should also reset the theme is an open question (see below); the default answer is no.
5. Optional preview hint
Each option may show a small static swatch (for example the theme's background, card and accent colour) next to its name so the choice is not blind. This is a nice-to-have; if it is built, the swatch colours come from the theme's own tokens, not from a second hard-coded list.
Constraints
- Content-Security-Policy:
style-src 'self'; script-src 'self'— no inline styles or scripts;theme-init.jsstays an external, synchronous script in<head>. innerHTML: the selector is built from static markup or withdocument.createElement+textContent;app.jsnever assigns non-empty content toinnerHTML(internal/web/xss_test.go).- No external resources, no build step, no web fonts.
- No API or configuration change.
- The stored mode (
pimonitor-theme), the stored layout (pimonitor-layout) and the stored API key keep their keys, formats and behaviour. - Dialog behaviour (modal, focus moves in and back, Escape / outside click / close button) is unchanged (
dialog_test.go).
Out of scope
- The visual design of Console and Berry (their own issues).
- A server-side default theme or a theme option in
config.yaml. - A control to return the mode to "follow the operating system" (noted as missing in
docs/areas/dashboard.md; can become its own issue). - Syncing the choice across open tabs.
- User-defined themes or colour pickers.
Acceptance criteria
- AC1 — With no stored choice the dashboard shows the theme
clear. - AC2 — A stored, known theme id is applied before the first paint; the page does not render in the default theme first.
- AC3 — A stored value that is not a registered theme id results in the theme
clear, without an error and without removing the stored value. - AC4 — With more than one registered theme, the "Customize dashboard" dialog shows a "Theme" radio group with one option per registered theme in registry order, and the option of the active theme is checked whenever the dialog opens.
- AC5 — Choosing an option applies the theme immediately without a reload, keeps the dialog open, stores the id under
pimonitor-style, and redraws sparklines, gauges and an open detail chart in the new theme. - AC6 — With exactly one registered theme the "Theme" section is not rendered.
- AC7 — Theme and mode are independent: switching the mode keeps the theme, choosing a theme keeps the mode, and with no stored mode the page keeps following
prefers-color-schemelive in every theme. - AC8 — When
localStorageis unavailable, choosing a theme works for the current page, nothing is stored and nothing throws. - AC9 — The id list used before first paint and the registry used by the selector are identical.
- AC10 — Every registered theme defines the same set of palette tokens in its light block and in both of its dark blocks.
- AC11 — The selector is a
<fieldset>with a<legend>and native radio inputs, reachable and operable by keyboard alone. - AC12 — The dashboard stores no
localStorageentry other thanpimonitor-api-key,pimonitor-theme,pimonitor-layoutandpimonitor-style. - AC13 — "Reset to default" restores the default card layout and leaves the chosen theme as it is.
- AC14 —
index.htmlstill has no inline style or script, andapp.jsstill assigns no non-emptyinnerHTML.
Testing notes
Follow the existing pattern of Go tests over the embedded assets in internal/web: registry/id-list equality (AC9), token key sets per theme and block (AC10), presence and structure of the selector markup or of the code that builds it (AC4, AC11), the storage key set (AC12), and the CSP/innerHTML guards (AC14). Where behaviour can only be shown by running the script (AC2, AC3, AC5–AC8, AC13), use whatever the repository's tests already do for script behaviour (polling_test.go, history_test.go); if a criterion cannot be covered that way, the plan says how it is verified.
Documentation
docs/areas/dashboard.md: split the Theme section into mode and theme, describe selection, storage, default and fallback; update Browser storage (four entries) and Card layout (the dialog now also holds the theme selection).README.md: mention the selectable themes in the feature list.- Decision records: the name of the storage key and attribute; "a theme is CSS overrides plus declared canvas properties, one DOM"; "per browser, no server-side setting".
Open questions for the spec
- Should "Reset to default" also reset the theme? (Default answer: no — AC13.)
- Default theme as an explicit
data-style="clear"or as the absence of the attribute? - One stylesheet or one file per theme?
- Should the selector show swatches (section 5)?
Activity
LarsLaskowski commentedon Nov 13, 2026
Design mockups
The three themes the selection chooses between, each shown in light mode; the dark variants are in the repository at
docs/design/v1.5.0/onmain. Sample data. The selector itself is not shown in the mockups; its specification is in the issue text.Clear (default)
Console
Berry
LarsLaskowski commentedon Nov 28, 2026
Squad working record
Verification matrix of feature-218-theme-selection on
7432d83TestThemeInit_DefaultLeavesNoAttribute_AC1(setsdataset.styleonly for a registered id other thanPIMONITOR_THEMES[0].id;<html>inindex.htmlhas nodata-style); manual M17432d83: internal/web/theme_test.goTestThemeInit_AppliesStoredThemeBeforePaint_AC2(readspimonitor-style;theme-init.jsstays sync in<head>before<body>; registry parser on a two-entry fixture); manual M27432d83: internal/web/theme_test.goTestThemeInit_UnknownValueIsKept_AC3(exact===match, notoLowerCase/trimon the value, noremoveItemofSTYLE_KEYanywhere); manual M37432d83: internal/web/theme_test.goTestAppJS_StylePickerFromRegistry_AC4(buildStylePickeriteratesPIMONITOR_THEMES, checks the option whose id isactiveStyle(), is called fromopenLayoutModal;#style-pickerprecedes.layout-hint); manual M47432d83: internal/web/theme_test.goTestAppJS_SelectStyleAppliesAndStores_AC5(selectStylestores viasetItem(STYLE_KEY,thenapplyStyle;applyStylecallsrepaintCanvases(); no.close()in the picker code); adaptedcheckApplyThemeRedraws; manual M57432d83: internal/web/theme_test.goTestStylePicker_HiddenWithOneTheme_AC6(staticclass="style-picker hidden"on#style-picker;buildStylePickertoggles thehiddenclass fromPIMONITOR_THEMES.length < 2); manual M67432d83: internal/web/theme_test.goTestAppJS_ModeAndThemeIndependent_AC7(applyStylenever writesdataset.theme,applyTheme/toggleThemeneverdataset.style); AC10's block test for the OS-dark selector of every theme; manual M77432d83: internal/web/theme_test.goTestAppJS_StyleStorageFailureIsCaught_AC8(both storage calls intry;activeStylereads the attribute, not storage); manual M87432d83: internal/web/theme_test.goTestThemeRegistry_SingleSource_AC9(ids parsed fromtheme-init.jsunique, defaultclearfirst;app.jsholds no{ id: '…', name:entry and no registered id as a literal; parser on a two-entry fixture)7432d83: internal/web/theme_test.goTestStyleCSS_ThemeTokenSets_AC10(for each registered id its three blocks — Clear's unscoped — share one key set; each property passed tothemeColor/themeNumberinchart.js,gauge.js,app.jsis in it; checker run on a fixture with a probe theme missing a token reports it)7432d83: internal/web/theme_test.goTestIndexHTML_StylePickerIsRadioGroup_AC11(<fieldset id="style-picker">with<legend>Theme</legend>;buildStylePickercreatesinputwithtype = 'radio'andname = 'style-choice'inside alabel); existingdialog_test.gounchanged; manual M107432d83: internal/web/theme_test.goTestAssets_StorageKeys_AC12(everypimonitor-…string literal in the JS assets is one of the five keys, all five occur)7432d83: internal/web/theme_test.goTestAppJS_ResetLayoutKeepsTheme_AC13(resetLayoutbody mentions noSTYLE_KEY/applyStyle/selectStyle); manual M117432d83: internal/web/theme_test.golook_test.go(AC11 tests) andxss_test.go, unchanged;TestThemeInit_AppliesStoredThemeBeforePaint_AC2for the sync script7432d83: internal/web/look_test.go, internal/web/xss_test.gocheckUpdateThemeToggle('Switch to light mode' : 'Switch to dark mode');TestIndexHTML_ModeButtonLabel_AC15(staticaria-label="Toggle mode"; noaria-labelinindex.htmlorapp.jscontains "theme")7432d83: internal/web/icons_test.go, internal/web/theme_test.goTestIndexHTML_ThemesLoadedStatically_AC16(onlystyle.cssis linked, no<link>or stylesheet created by script: nocreateElement('link'), noinsertRule); existingembed_test.gocache/ETag tests7432d83: internal/web/theme_test.goTestThemeInit_DrawingFallbacks_AC17(keys ofDRAWING_FALLBACKSequal the set of properties read; each value equals Clear's light block;themeNumberchecksNumber.isFiniteand the range, no\|\|default; nogetPropertyValue(left inchart.js/gauge.js/app.js); manual M97432d83: internal/web/theme_test.golog.md
Squad run metrics
Template: LarsLaskowski/Squad-Spec-Repository-Template v2026.11.15 (commit 96342d9fa5f8)
Tokens per kind and their weighted figure (every token at its list price, in tokens of Sonnet input:
.squad/tools/session-usage.py):Session usage
Tokens per model (the session and all its subagents; Claude Code's own background calls are not in the transcripts, so this is a lower bound):
Subagents:
Orchestrator (this session without its subagents): 2,117,456 weighted, 38 % of the total, on claude-sonnet-5-5.
Weighted: every token at its list price, in tokens of Sonnet input (
PRICESin.squad/tools/session-usage.py); a model of no listed family has none (–).Generated by Claude Code