Repository navigation
feat!: rewrite color engine with terminal detection and downsampling - #3
Draft
MarvinJWendt wants to merge 2 commits into
Draft
MarvinJWendt wants to merge 2 commits into
MarvinJWendt wants to merge 2 commits into
Conversation
Replaces the Mode/Style API with a single Color value type, a Style value with attributes, per-writer level detection (TTY, FORCE_COLOR, NO_COLOR, COLORTERM, TERM, Windows VT), automatic downsampling to 256 and 16 colors, background color detection (COLORFGBG and OSC 11), Strip and Hyperlink. Drops the predefined styles. Requires Go 1.27. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Dno7CsMx2fSzNx5ZTm7RL
Welcome to Codecov 馃帀Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered 鈽傦笍 |
The v2.11.4 release binary is built with Go 1.26 and refuses to lint a module that targets Go 1.27. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Dno7CsMx2fSzNx5ZTm7RL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Marvin 路 project thread
Before: color printed escape codes whatever the terminal could show. A pipe or a file got raw codes, an RGB color on a 16-color terminal came out wrong, and the package shipped its own Success/Error styles.
After: every print checks the writer it goes to. Piped output is plain, RGB colors are converted to the closest color a 256 or 16 color terminal can show, and the package only does color and text attributes. PTerm v0.13 builds on it.
How: the engine is PTerm's internal color code moved here.
Detect(w)reads FORCE_COLOR, CLICOLOR_FORCE, NO_COLOR, CLICOLOR, checks whetherwis a terminal, then reads COLORTERM, TERM and TERM_PROGRAM, and on Windows turns on ANSI processing in the console.Background(timeout)reads COLORFGBG or sends an OSC 11 query followed by DA1, so terminals that do not answer OSC 11 return at once instead of waiting for the timeout.API
Color: one comparable value type.Red...BrightWhite,Index(n),RGB(r, g, b),Hex(s),MustHex(s),Parse(s)(hex, names, 0-255, "none"). MethodsRGB,Hex,String,Mix,Luminance,IsDark,Fg,Bg,Sprint.Style{Foreground, Background, Attrs}withNew(attrs...),Fg,Bg,Add,Boldand friends,Sequence(level),Render(level, text),Sprint/Fprint/Printvariants.Renderhandles nesting and styles each line separately.Level:LevelNone,LevelBasic,Level256,LevelTrueColor.Detect(w),DetectEnv(),IsTerminal(w),SetLevel(l),ResetLevel().Strip,Hyperlink,SGR,Background.Breaking changes
Mode,ANSIColor,ANSI256Color,RGBColor, theColorinterface,NoColor,NewColorFromRGB,NewColorFromHex,NewStyle,Modifierandcolor.Writerare gone. UseColor,Index,RGB,Hex,None,StyleandAttr.Success,Error,Green(...)and so on) are gone.golang.org/x/term.Tests:
go test -race ./...passes, golangci-lint reports 0 issues for linux and windows.馃 Generated with Claude Code
https://claude.ai/code/session_011Dno7CsMx2fSzNx5ZTm7RL
Generated by Claude Code