Reveal the build's commit hash in place of the reset label while a finger holds the top-right corner, and dev where go run left no stamp

This commit is contained in:
flamingcow
2026-08-05 16:13:20 -07:00
parent 2fcab83756
commit e7c73ca0a9
2 changed files with 43 additions and 3 deletions
+1
View File
@@ -737,6 +737,7 @@ func run(aName, bName string, nsPerM float64) error {
if disp.holdReset(x, y, down, now) {
start = resetAll(dirs, stats)
}
disp.showVersion = down && disp.versionSpot.contains(x, y)
for i, d := range dirs {
views[i] = d.displayView()
}
+42 -3
View File
@@ -3,6 +3,7 @@ package main
import (
"fmt"
"math"
"runtime/debug"
"time"
)
@@ -41,6 +42,8 @@ const (
btnH = 80
holdDuration = time.Second
versionSpotSide = 200
chipRadius = spaceTight
chipBorder = 2
@@ -72,6 +75,10 @@ type display struct {
holdStart time.Time
holdFrac float64
fired bool
version string
versionSpot rect
showVersion bool
}
func newDisplay() (*display, error) {
@@ -79,7 +86,7 @@ func newDisplay() (*display, error) {
if err != nil {
return nil, err
}
d := &display{fb: fb}
d := &display{fb: fb, version: buildVersion()}
for _, spec := range []struct {
dst **textFace
bold bool
@@ -130,6 +137,7 @@ func newDisplay() (*display, error) {
w: btnW,
h: btnH,
}
d.versionSpot = rect{fb.w - versionSpotSide, 0, versionSpotSide, versionSpotSide}
return d, nil
}
@@ -188,14 +196,17 @@ func (d *display) drawResetButton() {
split += w
}
label := "RESET"
label, base := "RESET", uiCyan
if d.showVersion {
label, base = d.version, uiDim
}
lx := r.x + (r.w-len(label)*d.gridB.cellW)/2
ly := r.y + (r.h-d.gridB.lineH)/2 - d.gridB.capTop
// The label straddles the fill, so each glyph takes the colour that reads
// against whatever is behind it.
for i, c := range label {
gx := lx + i*d.gridB.cellW
col := uiCyan
col := base
if gx+d.gridB.cellW/2 < split {
col = uiBg
}
@@ -203,6 +214,34 @@ func (d *display) drawResetButton() {
}
}
// go run never stamps VCS info, so dev builds have no revision to show.
func buildVersion() string {
info, ok := debug.ReadBuildInfo()
if !ok {
return "dev"
}
var rev string
var dirty bool
for _, s := range info.Settings {
switch s.Key {
case "vcs.revision":
rev = s.Value
case "vcs.modified":
dirty = s.Value == "true"
}
}
if rev == "" {
return "dev"
}
if len(rev) > 9 {
rev = rev[:9]
}
if dirty {
rev += "+"
}
return rev
}
func (d *display) close() {
d.fb.close()
}