Sure! Here's a fun, Charm-style README for your metric package, with a balance of charm and clarity:
A delightful way to render key-value metrics in your TUI, one line at a time.
Inspired by the elegance of Charm tools and the expressive power of lipgloss, metric lets you compose tiny text widgets like stats, tags, or info blocks with rich styles and direction-aware layouts.
- 📐 Horizontal or vertical stacking
- 🎨 Multiple layout presets (card, tag, list)
- ✂️ Gaps or smart borders
- 🔁 Dynamic updates to metric values
- 🧩 Extendable and composable
import "github.com/ortizalec/bubbles/metric"m := metric.New(
metric.WithMetrics([]metric.Metric{
{Title: "Author", Value: "Alec Ortiz"},
{Title: "Published", Value: "05/02/2025"},
{Title: "Title", Value: "A Way Forward"},
}),
)Render it in your Bubbletea View() like this:
func (m model) View() string {
return m.metric.View()
}Define the title/value blocks to show.
Use one of the built-in layouts:
metric.CardLayout // stacked title and value
metric.TagLayout // colored inline tags
metric.ListLayout // simple list-styleStack metrics horizontally like tags or vertically like cards.
Wraps each metric with an intelligent, connected border. Looks great in a list.
Add spacing between metrics when borders are off. Good for padding out lists.
You can update metrics dynamically:
msg := metric.UpdateValueMsg{Index: 1, Value: "Updated!"}Handle it inside your model's Update():
case metric.UpdateValueMsg:
m.metric, _ = m.metric.Update(msg)You’re not stuck with presets! You can roll your own Layout to control how the title and value are styled and stacked.
myLayout := metric.Layout{
Title: lipgloss.NewStyle().
Foreground(lipgloss.Color("#ff79c6")).
Bold(true),
Value: lipgloss.NewStyle().
Foreground(lipgloss.Color("#bd93f9")),
Direction: metric.Horizontal,
}
m := metric.New(
metric.WithLayout(myLayout),
metric.WithMetrics([]metric.Metric{
{Title: "Magic", Value: "42"},
{Title: "Luck", Value: "7"},
}),
metric.WithDirection(metric.Vertical),
metric.WithBorder(true),
)Built with love by Alec Ortiz, powered by lipgloss and bubbletea.
MIT. Do what you will, but please keep it magical.
