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)
| 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`. |
| 16 | func 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 |
no outgoing calls