Stop EWW network statistics changing width

This commit is contained in:
Michael Bradley 2025-06-22 14:59:23 -04:00
parent abbd3df78b
commit 3630cc2bf5
Signed by: MichaelBradley
SSH key fingerprint: SHA256:BKO2eI2LPsCbQS3n3i5SdwZTAIV3F1lHezR07qP+Ob0
2 changed files with 6 additions and 4 deletions

View file

@ -1,4 +1,4 @@
#!/bin/env sh
# EWW doesn't seem to like listening to Python scripts directly, but this wrapper seems to work fine
"$(dirname "$0")"/network-statistics "$@"
python -OO "$(dirname "$0")"/network_statistics.py "$@"

View file

@ -35,10 +35,12 @@ class Status:
def format_4_significant_digits(num: float) -> str:
if num < 100:
return f"{num:#.3g}"
assert num >= 1.0, "Doesn't properly handle numbers below 1"
if num < 999:
return f"{num:04.3g}"
if num < 1000:
return f" {num:.3g}"
# Above doesn't nicely handle the special case in [999.5 1000)
return "0999"
return f"{num:.4g}"