Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

TTY styles for Go

License

NotificationsYou must be signed in to change notification settings

coder/pretty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Go Reference

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.

Basic Usage

errorStyle:= pretty.Style{pretty.FgColor(termenv.RGBColor("#ff0000")),pretty.BgColor(termenv.RGBColor("#000000")),pretty.WrapCSI(termenv.BoldSeq),}errorStyle.Printf("something bad")

Color

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),}

Performance

$ 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.921s

pretty 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

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp