summaryrefslogtreecommitdiff
path: root/internal/textutil/human.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-09-08 09:50:38 +0300
committerPaul Buetow <paul@buetow.org>2025-09-08 09:50:38 +0300
commitcead3ebde8f3aee0ef8677158d37f4d04c6629dc (patch)
treeeadf4928c13e4f1fd782e8e0955116a24cef1d27 /internal/textutil/human.go
parent29b0da31acf02816ee9e8f1d5a1b9a0ad5993593 (diff)
tmux: colored LLM status with provider + stats; add start heartbeat for LSP/CLI/TUI; theme support via HEXAI_TMUX_STATUS_THEME and HEXAI_TMUX_STATUS_FG/BG; docs: update tmux options and add Helix+tmux quickstart
Diffstat (limited to 'internal/textutil/human.go')
-rw-r--r--internal/textutil/human.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/internal/textutil/human.go b/internal/textutil/human.go
new file mode 100644
index 0000000..21907c3
--- /dev/null
+++ b/internal/textutil/human.go
@@ -0,0 +1,25 @@
+package textutil
+
+import "fmt"
+
+// HumanBytes renders n in a short human-friendly form using base-1000 units.
+// Examples: 999 -> 999B, 1200 -> 1.2k, 1540000 -> 1.5M
+func HumanBytes(n int64) string {
+ if n < 1000 {
+ return fmt.Sprintf("%dB", n)
+ }
+ const unit = 1000.0
+ v := float64(n)
+ suffix := []string{"k", "M", "G", "T"}
+ i := 0
+ for v >= unit && i < len(suffix)-1 {
+ v /= unit
+ i++
+ }
+ s := fmt.Sprintf("%.1f%s", v, suffix[i])
+ // Strip trailing ".0"
+ if len(s) >= 3 && s[len(s)-2:] == ".0" {
+ s = fmt.Sprintf("%d%s", int(v), suffix[i])
+ }
+ return s
+}