From f35fac64f7813ecc93698bfc37449219e121a9f2 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Mon, 16 Sep 2024 11:37:10 -0400 Subject: [PATCH] feat: add examples --- examples/go.mod | 15 +++++++++++++++ examples/go.sum | 12 ++++++++++++ examples/writer/writer.go | 23 +++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 examples/go.mod create mode 100644 examples/go.sum create mode 100644 examples/writer/writer.go diff --git a/examples/go.mod b/examples/go.mod new file mode 100644 index 0000000..b55b762 --- /dev/null +++ b/examples/go.mod @@ -0,0 +1,15 @@ +module examples + +go 1.23.1 + +replace github.com/charmbracelet/colorprofile => ../ + +require ( + github.com/charmbracelet/colorprofile v0.0.0-20240913192632-4a4ff4a5f48a // indirect + github.com/charmbracelet/x/ansi v0.3.1 // indirect + github.com/charmbracelet/x/term v0.2.0 // indirect + github.com/lucasb-eyer/go-colorful v1.2.0 // indirect + github.com/rivo/uniseg v0.4.7 // indirect + github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect + golang.org/x/sys v0.24.0 // indirect +) diff --git a/examples/go.sum b/examples/go.sum new file mode 100644 index 0000000..f44f3ad --- /dev/null +++ b/examples/go.sum @@ -0,0 +1,12 @@ +github.com/charmbracelet/x/ansi v0.3.1 h1:CRO6lc/6HCx2/D6S/GZ87jDvRvk6GtPyFP+IljkNtqI= +github.com/charmbracelet/x/ansi v0.3.1/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= +github.com/charmbracelet/x/term v0.2.0 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4hwm0x0= +github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0= +github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= +github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= +github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= +golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= +golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/examples/writer/writer.go b/examples/writer/writer.go new file mode 100644 index 0000000..151030e --- /dev/null +++ b/examples/writer/writer.go @@ -0,0 +1,23 @@ +// This package provides a writer that can be piped into to degrade the colors +// based on the terminal capabilities and profile. +package main + +import ( + "io" + "log" + "os" + + "github.com/charmbracelet/colorprofile" +) + +func main() { + w := colorprofile.NewWriter(os.Stdout, os.Environ()) + + // Read from stdin and write to stdout + bts, err := io.ReadAll(os.Stdin) + if err != nil { + log.Fatal(err) + } + + _, err = w.Write(bts) +}