From 439c06fae64d2f53261b692fcfcbe464d8e18d89 Mon Sep 17 00:00:00 2001 From: Maas Lalani Date: Tue, 5 Mar 2024 10:35:45 -0500 Subject: [PATCH] docs(table): ANSI-aware cell example --- examples/go.mod | 2 +- examples/go.sum | 4 ++-- examples/table/ansi/main.go | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 examples/table/ansi/main.go diff --git a/examples/go.mod b/examples/go.mod index f2c72a3b..b93aef15 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -23,7 +23,7 @@ require ( github.com/mattn/go-runewidth v0.0.15 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/muesli/reflow v0.3.0 // indirect - github.com/rivo/uniseg v0.4.6 // indirect + github.com/rivo/uniseg v0.4.7 // indirect golang.org/x/crypto v0.1.0 // indirect golang.org/x/sys v0.12.0 // indirect ) diff --git a/examples/go.sum b/examples/go.sum index 73db3cf8..d16930bd 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -72,8 +72,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/rivo/uniseg v0.4.6 h1:Sovz9sDSwbOz9tgUy8JpT+KgCkPYJEN/oYzlJiYTNLg= -github.com/rivo/uniseg v0.4.6/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= +github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/examples/table/ansi/main.go b/examples/table/ansi/main.go new file mode 100644 index 00000000..66d457d5 --- /dev/null +++ b/examples/table/ansi/main.go @@ -0,0 +1,18 @@ +package main + +import ( + "fmt" + + "github.com/charmbracelet/lipgloss" + "github.com/charmbracelet/lipgloss/table" +) + +func main() { + s := lipgloss.NewStyle().Foreground(lipgloss.Color("240")).Render + + t := table.New() + t.Row("Bubble Tea", s("Milky")) + t.Row("Milk Tea", s("Also milky")) + t.Row("Actual milk", s("Milky as well")) + fmt.Println(t.Render()) +}