diff --git a/meshterm/ui/widgets.py b/meshterm/ui/widgets.py index f1a3e3e..0ad0d8b 100644 --- a/meshterm/ui/widgets.py +++ b/meshterm/ui/widgets.py @@ -1432,6 +1432,23 @@ _BATTERY_FLASH_PCT = 100 / _BATTERY_STEPS / 2 #: Frames in the charging sweep: empty → four fills → round again (bottom-to-full loop). _CHARGE_FRAMES = 5 +#: A full pack reads ``100``, with no ``%`` — the one charge whose sign is dropped, so the +#: reading is three cells wide exactly as ``99%`` is. +#: +#: Which matters because 99 and 100 are the two numbers a topped-off pack sits *between*: +#: the charger cuts out at full, the pack settles back to 99, the charger restarts, and the +#: companion reports the flip every poll for as long as it is plugged in (JP, 2026-09-09). +#: The gauge is pinned to the header's right edge and the pulse takes what is left, so a +#: number that grew a cell at the top of the range took that cell off the sparkline and +#: redrew the whole activity history at a new scale, twice a minute, on a device sitting +#: still. Every other width change in the range — 9 to 10 on the way down — is a boundary a +#: discharging pack crosses once and never comes back over, so it costs one repaint and +#: needs no answer. +#: +#: A bare ``100`` beside a full block reads as a percentage without being told; ``%`` is +#: doing its work at the readings that could be mistaken for something else. +_BATTERY_FULL = "100" + def _braille_fill(steps: int) -> str: """A single braille cell filled from the bottom by ``steps`` (0–8) half-rows. @@ -1504,7 +1521,9 @@ def battery_cell(percent: int, *, charging: bool = False, frame: int = 0) -> Tex A pack at 100% is drawn as **not charging** whichever way the flag reads: a full cell resting full is the honest picture, and a topped-off charger left plugged in shouldn't - leave the gauge sweeping forever. + leave the gauge sweeping forever. It also drops its ``%`` (:data:`_BATTERY_FULL`), so + that full reading is the same three cells as the 99% it keeps flipping back to and the + header stops resizing under a pack on a charger. Args: percent: State of charge, 0–100 (clamped). @@ -1513,7 +1532,8 @@ def battery_cell(percent: int, *, charging: bool = False, frame: int = 0) -> Tex steadily-incrementing integer animates the two live states. Returns: - A Rich :class:`Text`: the coloured block, a space, and ``NN%`` in muted text — the + A Rich :class:`Text`: the coloured block, a space, and ``NN%`` in muted text — a + full pack's bare ``100`` the one exception (:data:`_BATTERY_FULL`) — with the block's colours on the glyph's span alone, so the ground stops at the cell. """ pct = max(0, min(100, int(percent))) @@ -1530,5 +1550,5 @@ def battery_cell(percent: int, *, charging: bool = False, frame: int = 0) -> Tex # muted percent onto the coloured ground alongside the cell. out = Text() out.append(_braille_fill(steps), style=color) - out.append(f" {pct}%", style="muted") + out.append(f" {_BATTERY_FULL if pct == 100 else f'{pct}%'}", style="muted") return out diff --git a/tests/test_battery.py b/tests/test_battery.py index f27565b..41b4a8a 100644 --- a/tests/test_battery.py +++ b/tests/test_battery.py @@ -77,6 +77,27 @@ def test_battery_cell_shows_the_true_percent() -> None: assert battery_cell(42).plain == chr(0x2800 | 0xE4) + " 42%" +def test_battery_cell_drops_the_sign_at_full_so_the_header_stops_moving() -> None: + """A full pack reads ``100`` — three cells, exactly as ``99%`` is. + + Those two readings are the ones a topped-off pack sits between: the charger cuts out + at full, the pack settles to 99, the charger restarts, and the flip repeats every poll + for as long as it is plugged in. The gauge is pinned to the header's right edge and the + pulse takes what is left, so a fourth cell at the top of the range came off the + sparkline and rescaled the whole activity history, twice a minute, on a device sitting + still. Dropping the one sign that can be inferred costs nothing and settles it. + """ + assert battery_cell(100).plain.endswith(" 100") # no sign — a full block says it + assert battery_cell(99).cell_len == battery_cell(100).cell_len + # Every other reading keeps its sign; the charging sweep and the alarm never touch it. + assert battery_cell(99).plain.endswith(" 99%") and battery_cell(9).plain.endswith(" 9%") + assert { + battery_cell(pct, charging=True, frame=f).plain.endswith("%") + for pct in (5, 99) + for f in range(6) + } == {True} + + def test_battery_cell_colours_by_band_while_the_dots_carry_the_detail() -> None: """Three broad bands over half / over a quarter / below, each a block of its own hue.""" assert _glyph_style(battery_cell(100)) == "batt.full" # light green on green @@ -143,8 +164,8 @@ def test_battery_cell_animates_off_the_frame_counter_alone() -> None: def test_battery_cell_at_full_rests_full_however_the_charging_flag_reads() -> None: """A topped-off pack draws as not charging, so a plugged-in charger stops the sweep.""" - assert battery_cell(100, charging=True, frame=0).plain == "⣿ 100%" - assert {battery_cell(100, charging=True, frame=f).plain for f in range(6)} == {"⣿ 100%"} + assert battery_cell(100, charging=True, frame=0).plain == "⣿ 100" + assert {battery_cell(100, charging=True, frame=f).plain for f in range(6)} == {"⣿ 100"} # One percent short is still filling, and still sweeps. assert battery_cell(99, charging=True, frame=0).plain[0] == chr(0x2800)