Skip to content

Turn a ~$5 AliExpress clock into a physical AI usage dashboard (Claude, Codex, multi-account). No firmware flashing.

Rename Dual to Pixel Retro Dual; keep every window and the card frame

Oleksii Kalentiev139157975c28
diff --git a/tests/test_retro_dual.py b/tests/test_retro_dual.py
new file mode 100644
index 0000000..c767a3d
--- /dev/null
+++ b/tests/test_retro_dual.py
@@ -0,0 +1,53 @@
+import time
+import unittest
+
+from token_tv.sample import D, H, snapshot
+from token_tv.themes import ACCENT, render_retro_dual, rgb
+
+
+def data(*accounts):
+ return snapshot(time.time(), list(accounts))
+
+
+def second_line(image, top):
+ # One account renders one full card; its second window line sits from y+81 to y+110.
+ return image.crop((0, top + 81, 240, top + 111)).tobytes()
+
+
+class RetroDualTests(unittest.TestCase):
+ def test_every_window_shape_renders_a_clock_frame(self):
+ cases = [
+ [('claude_a', 'CLAUDE A', 'claude', [('5H', 41, 2 * H), ('WEEK', 86, 3 * D)])],
+ [('claude_a', 'CLAUDE A', 'claude', [('5H', 41, 2 * H)])],
+ [('codex_a', 'CODEX A', 'codex', [('WINDOW', 30, 6 * D), ('WINDOW', 95, 3 * D)])],
+ [('grok_a', 'GROK A', 'grok', [])],
+ ]
+ for accounts in cases:
+ with self.subTest(accounts=accounts):
+ self.assertEqual(render_retro_dual(data(*accounts)).size, (240, 240))
+
+ def test_a_second_reported_window_is_drawn_not_dashed(self):
+ # Codex labels windows that are neither 5 hours nor a week as WINDOW; both must reach the screen.
+ both = render_retro_dual(data(('codex_a', 'CODEX A', 'codex', [('WINDOW', 30, 6 * D), ('WINDOW', 95, 3 * D)])))
+ first = render_retro_dual(data(('codex_a', 'CODEX A', 'codex', [('WINDOW', 30, 6 * D)])))
+ top = (240 - 116) // 2
+ self.assertNotEqual(second_line(both, top), second_line(first, top))
+
+ def test_bars_leave_the_card_frame_intact(self):
+ full = [('5H', 100, 2 * H), ('WEEK', 100, 3 * D)]
+ layouts = (([('claude_a', 'CLAUDE A', 'claude', full)], 116, 4),
+ ([('claude_a', 'CLAUDE A', 'claude', full), ('codex_a', 'CODEX A', 'codex', full),
+ ('grok_a', 'GROK A', 'grok', full)], 76, 4))
+ for accounts, card_h, gap in layouts:
+ image = render_retro_dual(data(*accounts))
+ top = (240 - len(accounts) * card_h - (len(accounts) - 1) * gap) // 2
+ for index, (_, _, provider, _) in enumerate(accounts):
+ y = top + index * (card_h + gap)
+ accent = rgb(ACCENT['retro'][provider][0])
+ for row in (y + card_h - 4, y + card_h - 3): # the 2 px accent outline at the card's bottom
+ with self.subTest(card_h=card_h, provider=provider, row=row):
+ self.assertEqual({image.getpixel((x, row)) for x in range(14, 226, 7)}, {accent})
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/token_tv/display.py b/token_tv/display.py
index 8f845b8..a4c77d4 100644
--- a/token_tv/display.py
+++ b/token_tv/display.py
@@ -23,7 +23,7 @@ PROVIDER_INK = {'claude': '#d68e68', 'codex': '#a799e5', 'grok': '#cbd1d7'}
ICON_PAPER = PROVIDER_INK['grok']
FONT_MAIN = '/usr/share/fonts/truetype/dejavu/DejaVuSans'
FONT_NUMBERS = '/usr/share/fonts/truetype/dejavu/DejaVuSansMono'
-STYLES = ('pixel', 'digital', 'neon', 'retro', 'hud', 'space', 'gameboy', 'dual')
+STYLES = ('pixel', 'digital', 'neon', 'retro', 'hud', 'space', 'gameboy', 'retro-dual')
# Gauge-only levels; labels/percentages always use TEXT, logos retain provider ink.
GAUGE_LEVELS = ((50, '#76a99a'), (80, '#93c9b9'), (90, '#d1b275'), (101, '#d8877e'))
STATUS = {'loading': 'WAIT', 'auth_required': 'LOGIN', 'identity_mismatch': 'CHECK',
@@ -342,7 +342,7 @@ function el(tag,text,cls){const e=document.createElement(tag);if(text!==undefine
function reset(value){if(!value)return '--';let m=Math.max(0,Math.ceil((value-Date.now()/1000)/60));return m>=1440?Math.floor(m/1440)+'d '+Math.floor(m%1440/60)+'h':Math.floor(m/60)+'h '+m%60+'m'}
let selectedStyle=null,displayInfo=null,busy=false,localError=false;
const styles=['pixel','clean','arcade','columns','orbit','digital','neon','retro','modern','sakura'];
-const styleName=s=>s==='retro'?'Pixel Retro':s?s.charAt(0).toUpperCase()+s.slice(1):'Pixel';
+const styleName=s=>s==='retro'?'Pixel Retro':s==='retro-dual'?'Pixel Retro Dual':s?s.charAt(0).toUpperCase()+s.slice(1):'Pixel';
function paintStyle(){
const choice=selectedStyle||'pixel';
for(const s of styles){const b=document.querySelector('#'+s);b.setAttribute('aria-pressed',String(s===choice));b.disabled=busy}
diff --git a/token_tv/themes.py b/token_tv/themes.py
index ed9287e..af8fde4 100644
--- a/token_tv/themes.py
+++ b/token_tv/themes.py
@@ -454,7 +454,7 @@ def render_retro(snapshot):
return cv.finish()
-def render_dual(snapshot):
+def render_retro_dual(snapshot):
"""Pixel Retro cards with both the 5-hour and the weekly window per account, not just the more used one."""
outline_ink, cream, dim, old_ink = '#0a0d26', '#fff3d6', '#b9d2ff', '#ff9a9a'
ground = {'claude': '#371428', 'codex': '#05201a', 'grok': '#120c33'}
@@ -483,16 +483,18 @@ def render_dual(snapshot):
if row['provider'] == 'grok':
cv.draw.rectangle((16, y + 13, 45, y + 42), fill='#d9ccff')
mascot(cv.ink, row['provider'], (7, y + 4), pixel=True, size=32)
- label_xy, first, pitch = (57, y + 12), y + 51, 32
+ label_xy, first, pitch = (57, y + 12), y + 50, 31
cv.text(label_xy, account_label(row), title(8), cream, stroke_width=1, stroke_fill=outline_ink)
- # Always two lines: the 5-hour window (or the service's only other window, e.g. a Grok budget), then the
- # weekly one. A window the service did not report is a dash and an empty bar, never a guess.
+ # Always a 5-hour and a weekly line. A window of another length (Codex `WINDOW`, a Grok budget) fills
+ # whichever line is empty, so a reported value is never dropped; a line nobody reported is a dash.
windows = {w['label']: w for w in row['windows']}
- short = windows.get('5H') or next((w for w in row['windows'] if w['label'] != 'WEEK'), None)
+ rest = [w for w in row['windows'] if w['label'] not in ('5H', 'WEEK')]
+ short = windows.get('5H') or (rest.pop(0) if rest else None)
+ long = windows.get('WEEK') or (rest.pop(0) if rest else None)
old = row['status'] != 'ok'
if not row['windows']: # LOGIN, WAIT, NO DATA ...: say why both lines are empty
cv.text((229, label_xy[1]), reading(row)[1], title(8), old_ink, anchor='ra', stroke_width=1, stroke_fill=outline_ink)
- for k, w in enumerate((short, windows.get('WEEK'))):
+ for k, w in enumerate((short, long)):
used = max(0, min(100, w['used_percent'])) if w else None
reset = time_left(w.get('resets_at')).upper() if w else ''
by = first + k * pitch
@@ -585,4 +587,4 @@ def render_gameboy(data):
-RENDERERS = {'dual': render_dual, 'digital': render_digital, 'neon': render_neon, 'retro': render_retro, 'hud': render_hud, 'gameboy': render_gameboy}
+RENDERERS = {'digital': render_digital, 'neon': render_neon, 'retro': render_retro, 'hud': render_hud, 'gameboy': render_gameboy, 'retro-dual': render_retro_dual}
diff --git a/token_tv/web/app.js b/token_tv/web/app.js
index 8d8fe4e..44042f6 100644
--- a/token_tv/web/app.js
+++ b/token_tv/web/app.js
@@ -241,7 +241,7 @@ function paintClock(forceImage = false) {
$('#display-state').textContent = DEMO ? 'Demo · install TokenTV to drive a real clock' : clockError ? 'Could not apply. Please retry.' : !displayInfo ? 'Clock status unavailable' : style !== displayInfo.style ? 'Preview only · Apply to send' : displayInfo.status === 'queued' ? 'Sending image…' : displayInfo.status === 'error' ? 'Clock upload failed. Please retry.' : displayInfo.status === 'preview_only' ? 'Preview only · No clock connected' : 'Image sent · ' + styleName(displayInfo.applied_style);
if (style && !$('#clock-panel').hidden && (forceImage || style !== lastImageStyle || Date.now() - lastImageAt > 30000)) {lastImageStyle = style; lastImageAt = Date.now(); $('#frame').src = DEMO ? displayInfo.frames?.[style] || `/frames/${encodeURIComponent(style)}.jpg` : '/frame/0.jpg?style=' + encodeURIComponent(style) + '&t=' + lastImageAt; $('#frame').alt = styleName(style) + ' live clock preview'}
}
-const styleName = s => s === 'retro' ? 'Pixel Retro' : s === 'hud' ? 'Sci-Fi HUD' : s ? s[0].toUpperCase() + s.slice(1) : 'Unknown';
+const styleName = s => s === 'retro' ? 'Pixel Retro' : s === 'retro-dual' ? 'Pixel Retro Dual' : s === 'hud' ? 'Sci-Fi HUD' : s ? s[0].toUpperCase() + s.slice(1) : 'Unknown';
let displayPolling = false;
async function refreshDisplay(forceImage = false) {if (displayPolling) return; displayPolling = true; try {const r = await fetch(DEMO ? '/demo-display.json' : '/display', {cache:'no-store'}); if (!r.ok) throw Error(); const data = await r.json(); const dirty = displayInfo && clockChoice !== displayInfo.style; displayInfo = data; if (!clockChoice || !dirty) clockChoice = data.style; const select = $('#clock-style'); if (!select.options.length) for (const s of data.styles) {const o = el('option', styleName(s)); o.value = s; select.append(o)} select.value = clockChoice; paintClock(forceImage); if (DEMO && themeData && !lastThumbFrames) {lastThumbFrames = true; paintThemes()}} catch {$('#display-state').textContent = 'Clock status unavailable'} finally {displayPolling = false}}
$('#clock-style').onchange = e => {clockChoice = e.target.value; clockError = false; paintClock(true); paintThemes()};