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:
@@ -737,6 +737,7 @@ func run(aName, bName string, nsPerM float64) error {
|
|||||||
if disp.holdReset(x, y, down, now) {
|
if disp.holdReset(x, y, down, now) {
|
||||||
start = resetAll(dirs, stats)
|
start = resetAll(dirs, stats)
|
||||||
}
|
}
|
||||||
|
disp.showVersion = down && disp.versionSpot.contains(x, y)
|
||||||
for i, d := range dirs {
|
for i, d := range dirs {
|
||||||
views[i] = d.displayView()
|
views[i] = d.displayView()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
"runtime/debug"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -41,6 +42,8 @@ const (
|
|||||||
btnH = 80
|
btnH = 80
|
||||||
holdDuration = time.Second
|
holdDuration = time.Second
|
||||||
|
|
||||||
|
versionSpotSide = 200
|
||||||
|
|
||||||
chipRadius = spaceTight
|
chipRadius = spaceTight
|
||||||
chipBorder = 2
|
chipBorder = 2
|
||||||
|
|
||||||
@@ -72,6 +75,10 @@ type display struct {
|
|||||||
holdStart time.Time
|
holdStart time.Time
|
||||||
holdFrac float64
|
holdFrac float64
|
||||||
fired bool
|
fired bool
|
||||||
|
|
||||||
|
version string
|
||||||
|
versionSpot rect
|
||||||
|
showVersion bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDisplay() (*display, error) {
|
func newDisplay() (*display, error) {
|
||||||
@@ -79,7 +86,7 @@ func newDisplay() (*display, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
d := &display{fb: fb}
|
d := &display{fb: fb, version: buildVersion()}
|
||||||
for _, spec := range []struct {
|
for _, spec := range []struct {
|
||||||
dst **textFace
|
dst **textFace
|
||||||
bold bool
|
bold bool
|
||||||
@@ -130,6 +137,7 @@ func newDisplay() (*display, error) {
|
|||||||
w: btnW,
|
w: btnW,
|
||||||
h: btnH,
|
h: btnH,
|
||||||
}
|
}
|
||||||
|
d.versionSpot = rect{fb.w - versionSpotSide, 0, versionSpotSide, versionSpotSide}
|
||||||
return d, nil
|
return d, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,14 +196,17 @@ func (d *display) drawResetButton() {
|
|||||||
split += w
|
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
|
lx := r.x + (r.w-len(label)*d.gridB.cellW)/2
|
||||||
ly := r.y + (r.h-d.gridB.lineH)/2 - d.gridB.capTop
|
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
|
// The label straddles the fill, so each glyph takes the colour that reads
|
||||||
// against whatever is behind it.
|
// against whatever is behind it.
|
||||||
for i, c := range label {
|
for i, c := range label {
|
||||||
gx := lx + i*d.gridB.cellW
|
gx := lx + i*d.gridB.cellW
|
||||||
col := uiCyan
|
col := base
|
||||||
if gx+d.gridB.cellW/2 < split {
|
if gx+d.gridB.cellW/2 < split {
|
||||||
col = uiBg
|
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() {
|
func (d *display) close() {
|
||||||
d.fb.close()
|
d.fb.close()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user