Panel cleanup: chip padding up a step and a tighter chip line gap, corrected/SNR numbers neutral until amber or red, dB margin casing, compound elapsed units (1m39s) ending the minutes/metres m collision, noise chip shows presence only

This commit is contained in:
flamingcow
2026-08-14 23:47:45 -07:00
parent 9f2b074c4a
commit 6a1a860548
3 changed files with 32 additions and 33 deletions
+7 -6
View File
@@ -101,15 +101,16 @@ func scaleCount(v uint64) string {
// The same shape for time, whose magnitudes are sixties and twenty-fours.
func scaleTime(d time.Duration) string {
s := int(d.Seconds())
switch {
case d < time.Minute:
return fmt.Sprintf("%.2f s", d.Seconds())
return fmt.Sprintf("%ds", s)
case d < time.Hour:
return fmt.Sprintf("%.2f m", d.Minutes())
return fmt.Sprintf("%dm%02ds", s/60, s%60)
case d < 24*time.Hour:
return fmt.Sprintf("%.2f h", d.Hours())
return fmt.Sprintf("%dh%02dm", s/3600, (s/60)%60)
}
return fmt.Sprintf("%.2f d", d.Hours()/24)
return fmt.Sprintf("%dd%02dh", s/86400, (s/3600)%24)
}
type colSpec struct {
@@ -282,7 +283,7 @@ func snrCell(phy phyDisplay) string {
s := fmt.Sprintf("%+.1f", phy.worstMargin)
switch snrClass(phy.worstMargin) {
case clsGood:
return paint(s, cGreen)
return s
case clsWarn:
return paint(s, cYellow)
default:
@@ -292,7 +293,7 @@ func snrCell(phy phyDisplay) string {
func correctedCell(v uint64) string {
if v == 0 {
return paint("0", cGreen)
return "0"
}
return paint(commas(v), cYellow)
}
+4 -4
View File
@@ -45,10 +45,10 @@ func TestScaleTime(t *testing.T) {
in time.Duration
want string
}{
{1500 * time.Millisecond, "1.50 s"},
{90 * time.Second, "1.50 m"},
{90 * time.Minute, "1.50 h"},
{36 * time.Hour, "1.50 d"},
{1500 * time.Millisecond, "1s"},
{90 * time.Second, "1m30s"},
{90 * time.Minute, "1h30m"},
{36 * time.Hour, "1d12h"},
} {
if got := scaleTime(c.in); got != c.want {
t.Errorf("scaleTime(%v) = %q, want %q", c.in, got, c.want)
+21 -23
View File
@@ -60,10 +60,11 @@ const (
chipRadius = spaceTight
chipBorder = 2
gridCols = 2
chipPadY = step * 3
chipGap = spaceTight
statRowGap = spaceRow
gridCols = 2
chipPadY = step * 4
chipLineGap = step * 3
chipGap = spaceTight
statRowGap = spaceRow
)
type rect struct {
@@ -267,10 +268,11 @@ func (d *display) close() {
}
// y is the top of the line as read, not the top of the cell, so text and a
// bordered box placed the same distance apart look it.
// bordered box placed the same distance apart look it. Returns the top of the
// next line, gapless — the caller owns the spacing below.
func (d *display) centerIn(f *textFace, x, w, y int, s string, col rgb) int {
f.draw(d.fb, x+(w-len([]rune(s))*f.cellW)/2, y-f.capTop, s, col)
return y + f.lineH + pairGap
return y + f.lineH
}
type statCell struct {
@@ -306,7 +308,7 @@ func (d *display) stats(vf *textFace, x, w, y int, cells []statCell) int {
}
cx, cw := gridCell(i, len(cells), gridCols, x, w)
cy := y + (i/gridCols)*(d.statPairH(vf)+statRowGap)
ly := d.centerIn(vf, cx, cw, cy, c.value, c.col)
ly := d.centerIn(vf, cx, cw, cy, c.value, c.col) + pairGap
d.centerIn(d.grid, cx, cw, ly, c.label, uiDim)
}
return y + d.statsH(vf, len(cells))
@@ -324,7 +326,7 @@ var errRows = []struct {
func (d *display) chipH() int { return d.grid.lineH + 2*chipPadY }
func (d *display) countChipH() int { return d.chipH() + d.gridB.lineH + pairGap }
func (d *display) countChipH() int { return d.chipH() + d.gridB.lineH + chipLineGap }
// The error chips plus corrected and the noise cable's, which share their
// row grid.
@@ -350,8 +352,8 @@ func (d *display) chipAt(i, n, cols, x, w, y, h int, c rgb) (int, int, int) {
// Whether rather than how many: over a window this short a count changes faster
// than it can be read. The noise chip rides along at the end, presence rather
// than health: red is the cable missing, not the cable failing, and a present
// cable names its cycle phase in green.
// than health: red is the cable missing, not the cable failing. The cycle
// phase stays off the panel (the console column still carries it).
func (d *display) errChips(x, w, y int, e errs, recentCorrected uint64, nv noiseView) int {
n := len(errRows) + 2
for i, r := range errRows {
@@ -366,15 +368,8 @@ func (d *display) errChips(x, w, y int, e errs, recentCorrected uint64, nv noise
cx, cw, cy := d.chipAt(len(errRows), n, gridCols, x, w, y, d.chipH(), c)
d.centerIn(d.grid, cx, cw, cy+chipPadY, "corrected", c)
c = errColor(nv.missing)
label := "noise"
if nv.missing == 0 {
label = "noise off"
if nv.on {
label = "noise on"
}
}
cx, cw, cy = d.chipAt(len(errRows)+1, n, gridCols, x, w, y, d.chipH(), c)
d.centerIn(d.grid, cx, cw, cy+chipPadY, label, c)
d.centerIn(d.grid, cx, cw, cy+chipPadY, "noise", c)
return y + d.chipsH()
}
@@ -383,7 +378,7 @@ func (d *display) errCounts(x, w, y int, e errs) int {
n := r.get(e)
c := errColor(n)
cx, cw, cy := d.chipAt(i, len(errRows), gridCols, x, w, y, d.countChipH(), c)
ty := d.centerIn(d.gridB, cx, cw, cy+chipPadY, scaleCount(n), c)
ty := d.centerIn(d.gridB, cx, cw, cy+chipPadY, scaleCount(n), c) + chipLineGap
d.centerIn(d.grid, cx, cw, ty, r.label, c)
}
return y + d.countsH()
@@ -419,14 +414,17 @@ func errColor(n uint64) rgb {
func snrStat(phy phyDisplay) statCell {
if !phy.haveSNR {
return statCell{"-", "db margin", uiDim}
return statCell{"-", "dB margin", uiDim}
}
return statCell{fmt.Sprintf("%+.1f", phy.worstMargin), "db margin",
classColor(snrClass(phy.worstMargin))}
col := uiFg
if c := snrClass(phy.worstMargin); c != clsGood {
col = classColor(c)
}
return statCell{fmt.Sprintf("%+.1f", phy.worstMargin), "dB margin", col}
}
func correctedStat(v uint64) statCell {
col := uiGreen
col := uiFg
if v > 0 {
col = uiAmber
}