- Notifications
You must be signed in to change notification settings - Fork3
coder/pretty
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
pretty is a performant Terminal pretty printer for Go. We built it afterusing lipgloss and experiencing significant performance issues.
pretty doesn't implement escape sequences and should be used alongsidetermenv.
errorStyle:= pretty.Style{pretty.FgColor(termenv.RGBColor("#ff0000")),pretty.BgColor(termenv.RGBColor("#000000")),pretty.WrapCSI(termenv.BoldSeq),}errorStyle.Printf("something bad")
You can usetermenv to adapt the colors to the terminal's color palette:
profile:=termenv.NewOutput(os.Stdout,termenv.WithColorCache(true)).ColorProfile()errorStyle:= pretty.Style{pretty.FgColor(profile.Color("#ff0000")),pretty.BgColor(profile.Color("#000000")),pretty.WrapCSI(termenv.BoldSeq),}
$ go test -bench=.goos: darwingoarch: arm64pkg: github.com/coder/pretty/benchBenchmarkPretty-10 5142177 232.6 ns/op 55.88 MB/s 272 B/op 8 allocs/opBenchmarkLipgloss-10 280276 4157 ns/op 3.13 MB/s 896 B/op 72 allocs/opPASSok github.com/coder/pretty/bench 2.921spretty remains fast even through dozens of transformations due to its linked-listbased intermediate representation of text. In general, operations scale withthe number of links rather than the length of the text. For example, coloringa 1000 character string green is just as fast as wrapping a 1 character string.
Eventually we could reap even more gains by replacing the linked-list with arope.
About
TTY styles for Go
Resources
License
Code of conduct
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.