Releases: charmbracelet/colorprofile
v0.1.9
Changelog
Bug fixes
- 2b0f69a: fix: minor typo in grayscale conversion (#17) (@CannibalVox)
Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or on Discord.
v0.1.8
Changelog
Bug fixes
- d632863: fix: properly handle missing SGR parameters (@aymanbagabas)
Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or on Discord.
v0.1.6
Changelog
New Features
- 71c737f: feat: windows has colors support (@aymanbagabas)
Bug fixes
- 5de2f41: fix: windows terminal tests (@aymanbagabas)
Other work
- 4a6ae41: refactor: tidy up envColorProfile (@aymanbagabas)
Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or on Discord.
v0.1.5
Changelog
Bug fixes
- efbe4af: fix: windows terminal supports truecolor (@aymanbagabas)
Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or on Discord.
v0.1.4
Changelog
New Features
- 9dc35d3: feat(ci): add lint-sync workflow (@aymanbagabas)
Bug fixes
- 480949a: fix(ci): add permissions to lint-sync.yml (@aymanbagabas)
- 6118ca4: fix: ensure we're extracting the value from the Param (@aymanbagabas)
- 85a93f2: fix: tidy and refactor writer.go (@aymanbagabas)
Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or on Discord.
v0.1.3
Changelog
Bug fixes
- 539a7e6: fix: extract color param from ansi.Param (#5) (@aymanbagabas)
Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or on Discord.
v0.1.2
Changelog
New Features
- 09dc63f: feat(ci): use shared workflows (#4) (@aymanbagabas)
Documentation updates
- 7cb9a31: docs: add license (@aymanbagabas)
Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or on Discord.
v0.1.1
Changelog
New Features
- 274a6e8: feat: use go1.18 (@aymanbagabas)
Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or on Discord.
v0.1.0
Colorprofile
A simple, powerful—and at times magical—package for detecting terminal color
profiles and performing color (and CSI) degradation.
Detecting the terminal’s color profile
Detecting the terminal’s color profile is easy.
import "github.com/charmbracelet/colorprofile"
// Detect the color profile. If you’re planning on writing to stderr you'd want
// to use os.Stderr instead.
p := colorprofile.Detect(os.Stdout, os.Environ())
// Comment on the profile.
fmt.Printf("You know, your colors are quite %s.", func() string {
switch p {
case colorprofile.TrueColor:
return "fancy"
case colorprofile.ANSI256:
return "1990s fancy"
case colorprofile.ANSI:
return "normcore"
case colorprofile.Ascii:
return "ancient"
case colorprofile.NoTTY:
return "naughty!"
}
return "...IDK" // this should never happen
}())
Downsampling colors
When necessary, colors can be downsampled to a given profile, or manually
downsampled to a specific profile.
p := colorprofile.Detect(os.Stdout, os.Environ())
c := color.RGBA{0x6b, 0x50, 0xff, 0xff} // #6b50ff
// Downsample to the detected profile, when necessary.
convertedColor := p.Convert(c)
// Or manually convert to a given profile.
ansi256Color := colorprofile.ANSI256.Convert(c)
ansiColor := colorprofile.ANSI.Convert(c)
noColor := colorprofile.Ascii.Convert(c)
noANSI := colorprofile.NoTTY.Convert(c)
Automatic downsampling with a Writer
You can also magically downsample colors in ANSI output, when necessary. If
output is not a TTY ANSI will be dropped entirely.
myFancyANSI := "\x1b[38;2;107;80;255mCute \x1b[1;3mpuppy!!\x1b[m"
// Automatically downsample for the terminal at stdout.
w := colorprofile.NewWriter(os.Stdout, os.Environ())
fmt.Fprintf(w, myFancyANSI)
// Downsample to 4-bit ANSI.
w.Profile = colorprofile.ANSI
fmt.Fprintf(w, myFancyANSI)
// Ascii-fy, no colors.
w.Profile = colorprofile.Ascii
fmt.Fprintf(w, myFancyANSI)
// Strip ANSI altogether.
w.Profile = colorprofile.NoTTY
fmt.Fprintf(w, myFancyANSI) // not as fancy
Changelog
New Features
- ef35ba7: feat(ci): use codecove instead of coverall for coverage (@aymanbagabas)
- f35fac6: feat: add examples (@aymanbagabas)
- 674752d: feat: add writer benchmark test (@aymanbagabas)
Bug fixes
- bf81bf3: fix(ci): codecov token (@aymanbagabas)
- 383e9bc: fix(ci): coverage workflow (@aymanbagabas)
- d551e7a: fix: remove helper functions from writer.go (@aymanbagabas)
Documentation updates
- 4a4ff4a: docs(readme): tidy badges (@meowgorithm)
- d96fcae: docs(readme): update footer (@meowgorithm)
- 0bf1814: docs: adjust readme and add example (#2) (@meowgorithm)
- 9298b53: docs: fix and add ascii example (@aymanbagabas)
Other work
- 981b4a8: perf: improve writer performance by using ansi.Style (@aymanbagabas)
- f8f1fbf: refactor: rename exported functions to be more idiomatic (@aymanbagabas)
- ab88f30: refactor: rename profile_writer.go to writer.go (@aymanbagabas)
Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or on Discord.