Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support inferring the color profile from terminfo dbs #285

Open
wants to merge 1 commit into
base: use-ansi-style
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions env.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"strings"

"github.com/charmbracelet/x/exp/term"
"github.com/xo/terminfo"
)

// DetectColorProfile returns the color profile based on the terminal output,
Expand Down Expand Up @@ -133,6 +134,28 @@
setProfile(ANSI)
}

if ti, err := terminfo.Load(term); err == nil {

Check failure on line 137 in env.go

View workflow job for this annotation

GitHub Actions / lint-soft

`if err == nil` has complex nested blocks (complexity: 7) (nestif)

Check failure on line 137 in env.go

View workflow job for this annotation

GitHub Actions / lint-soft

`if err == nil` has complex nested blocks (complexity: 7) (nestif)
extbools := ti.ExtBoolCapsShort()
if _, ok := extbools["RGB"]; ok {
setProfile(TrueColor)
}

if _, ok := extbools["Tc"]; ok {
setProfile(TrueColor)
}

nums := ti.NumCapsShort()
if colors, ok := nums["colors"]; ok {
if colors >= 0x1000000 {

Check failure on line 149 in env.go

View workflow job for this annotation

GitHub Actions / lint-soft

mnd: Magic number: 0x1000000, in <condition> detected (gomnd)

Check failure on line 149 in env.go

View workflow job for this annotation

GitHub Actions / lint-soft

mnd: Magic number: 0x1000000, in <condition> detected (gomnd)
setProfile(TrueColor)
} else if colors >= 0x100 {

Check failure on line 151 in env.go

View workflow job for this annotation

GitHub Actions / lint-soft

mnd: Magic number: 0x100, in <condition> detected (gomnd)

Check failure on line 151 in env.go

View workflow job for this annotation

GitHub Actions / lint-soft

mnd: Magic number: 0x100, in <condition> detected (gomnd)
setProfile(ANSI256)
} else if colors >= 0x10 {

Check failure on line 153 in env.go

View workflow job for this annotation

GitHub Actions / lint-soft

mnd: Magic number: 0x10, in <condition> detected (gomnd)

Check failure on line 153 in env.go

View workflow job for this annotation

GitHub Actions / lint-soft

mnd: Magic number: 0x10, in <condition> detected (gomnd)
setProfile(ANSI)
}
}
}

return
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ require (
github.com/charmbracelet/x/exp/term v0.0.0-20240425164147-ba2a9512b05f
github.com/lucasb-eyer/go-colorful v1.2.0
github.com/rivo/uniseg v0.4.7
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e
golang.org/x/sys v0.19.0
)

require (
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
)
Loading