MCPcopy Create free account
hub / github.com/codehamr/codehamr / humanTokens

Function humanTokens

internal/tui/format.go:16–25  ·  view source on GitHub ↗

humanTokens renders a token count compactly: `900 tok`, `1.2k tok`, `1.5M tok`. The k/M ranges always keep one decimal (`2.0k`, not `2k`) so the live counter holds a constant width as it ticks past round thousands: it reads `1.9k → 2.0k → 2.1k`, not a jumpy `1.9k → 2k → 2.1k`.

(n int)

Source from the content-addressed store, hash-verified

14// counter holds a constant width as it ticks past round thousands: it reads
15// `1.9k → 2.0k → 2.1k`, not a jumpy `1.9k → 2k → 2.1k`.
16func humanTokens(n int) string {
17 switch {
18 case n < 1000:
19 return fmt.Sprintf("%d tok", n)
20 case n < 1_000_000:
21 return fmt.Sprintf("%.1fk tok", float64(n)/1000)
22 default:
23 return fmt.Sprintf("%.1fM tok", float64(n)/1_000_000)
24 }
25}
26
27// liveElapsed renders a running wall clock duration for the status bar: whole
28// seconds under a minute (no sub second decimal spinning at the spinner's

Callers 3

finalizeTurnMethod · 0.85
TestHumanTokensFormatFunction · 0.85
renderStatusBarMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestHumanTokensFormatFunction · 0.68