Skip to content

Commit 6cfbcd6

Browse files
unhappychoiceclaude
andcommitted
feat(system): emit PixelArt sprites for monitor_battery
Extends `system_monitor_battery` with `Shape::PixelArt`. The battery ratio routes through `sprites::battery_sprite()`, picking one of five buckets and labelling it with the formatted percent + state (`"42% · Discharging"`). Hosts without a battery render the AC-power case as the full-tier sprite labelled `"AC"`. Refs #261. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent f051c72 commit 6cfbcd6

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎src/fetcher/system/mod.rs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,13 @@ mod tests {
696696
assert_realtime_contract(
697697
&SystemMonitorBattery::default(),
698698
"system_monitor_battery",
699-
&[Shape::Ratio, Shape::Text, Shape::Entries, Shape::Badge],
699+
&[
700+
Shape::Ratio,
701+
Shape::Text,
702+
Shape::Entries,
703+
Shape::Badge,
704+
Shape::PixelArt,
705+
],
700706
Shape::Ratio,
701707
Shape::Bars,
702708
2,

‎src/fetcher/system/monitor_battery.rs‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::render::Shape;
1515
use crate::samples;
1616

1717
use super::super::{FetchContext, RealtimeFetcher, Safety};
18+
use super::sprites;
1819
use super::{entry, format_uptime, options_placeholder, parse_options, payload};
1920

2021
const OPTION_SCHEMAS: &[OptionSchema] = &[
@@ -111,7 +112,13 @@ impl RealtimeFetcher for SystemMonitorBattery {
111112
"Charge level and state of the primary (or `index`-selected) battery. `Ratio` drives gauges, `Text` formats a summary line whose field is picked by `kind`, and `Entries` rolls up charge / state / time-left / cycles / health. Hosts without a battery render a steady `\"AC\"` placeholder."
112113
}
113114
fn shapes(&self) -> &[Shape] {
114-
&[Shape::Ratio, Shape::Text, Shape::Entries, Shape::Badge]
115+
&[
116+
Shape::Ratio,
117+
Shape::Text,
118+
Shape::Entries,
119+
Shape::Badge,
120+
Shape::PixelArt,
121+
]
115122
}
116123
fn option_schemas(&self) -> &[OptionSchema] {
117124
OPTION_SCHEMAS
@@ -128,6 +135,7 @@ impl RealtimeFetcher for SystemMonitorBattery {
128135
("health", "97%"),
129136
]),
130137
Shape::Badge => samples::badge(Status::Ok, "87% · Charging"),
138+
Shape::PixelArt => Body::PixelArt(sprites::battery_sprite(0.87, "87% · Charging")),
131139
_ => return None,
132140
})
133141
}
@@ -146,6 +154,10 @@ impl RealtimeFetcher for SystemMonitorBattery {
146154
items: battery_entries(&snap),
147155
})),
148156
(Some(snap), Shape::Badge) => payload(Body::Badge(battery_badge(&snap))),
157+
(Some(snap), Shape::PixelArt) => payload(Body::PixelArt(sprites::battery_sprite(
158+
snap.charge,
159+
&format!("{} · {}", format_percent(snap.charge), snap.state.label()),
160+
))),
149161
(Some(snap), _) => payload(Body::Ratio(RatioData {
150162
value: snap.charge,
151163
label: Some(format!(
@@ -275,6 +287,9 @@ pub(crate) fn no_battery_payload(shape: Shape, kind: BatteryTextKind) -> Payload
275287
status: Status::Ok,
276288
label: "AC".into(),
277289
})),
290+
// Render the AC-power case as a "full" sprite — a host without a battery is, from a
291+
// glance perspective, always topped up.
292+
Shape::PixelArt => payload(Body::PixelArt(sprites::battery_sprite(1.0, "AC"))),
278293
_ => payload(Body::Ratio(RatioData {
279294
value: 1.0,
280295
label: Some("AC".into()),
@@ -327,6 +342,22 @@ mod tests {
327342
Some(Body::Badge(badge))
328343
if badge.status == Status::Ok && badge.label == "87% · Charging"
329344
));
345+
let pixel = fetcher.sample_body(Shape::PixelArt).unwrap();
346+
let Body::PixelArt(d) = pixel else {
347+
panic!("expected PixelArt sample body");
348+
};
349+
assert_eq!(d.pixels.len(), 16);
350+
assert_eq!(d.label.as_deref(), Some("87% · Charging"));
351+
}
352+
353+
#[test]
354+
fn no_battery_payload_pixel_art_returns_full_sprite() {
355+
let payload = no_battery_payload(Shape::PixelArt, BatteryTextKind::Summary);
356+
let Body::PixelArt(d) = payload.body else {
357+
panic!("expected PixelArt body for AC host");
358+
};
359+
assert_eq!(d.label.as_deref(), Some("AC"));
360+
assert_eq!(d.pixels.len(), 16);
330361
}
331362

332363
#[test]

0 commit comments

Comments
 (0)