a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
38 lines
684 B
Go
38 lines
684 B
Go
package main
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// humanizeInt renders an integer with thousands separators (1234567 ->
|
|
// "1,234,567"). Shared by the daemon status TUI and other CLI summaries.
|
|
func humanizeInt[T int | int32 | int64 | uint32 | uint64](v T) string {
|
|
s := strconv.FormatInt(int64(v), 10)
|
|
neg := strings.HasPrefix(s, "-")
|
|
if neg {
|
|
s = s[1:]
|
|
}
|
|
if len(s) <= 3 {
|
|
if neg {
|
|
return "-" + s
|
|
}
|
|
return s
|
|
}
|
|
var b strings.Builder
|
|
rem := len(s) % 3
|
|
if rem > 0 {
|
|
b.WriteString(s[:rem])
|
|
}
|
|
for i := rem; i < len(s); i += 3 {
|
|
if b.Len() > 0 {
|
|
b.WriteString(",")
|
|
}
|
|
b.WriteString(s[i : i+3])
|
|
}
|
|
if neg {
|
|
return "-" + b.String()
|
|
}
|
|
return b.String()
|
|
}
|