Skip to content

Commit

Permalink
feat: support inferring the color profile from terminfo dbs
Browse files Browse the repository at this point in the history
This will try to load the terminal terminfo database and infer the color
profile supported by the terminal.
  • Loading branch information
aymanbagabas committed Mar 17, 2024
1 parent 715eb23 commit d4d4a46
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions env.go
Expand Up @@ -2,6 +2,8 @@ package lipgloss

import (
"strings"

"github.com/xo/terminfo"
)

// envNoColor returns true if the environment variables explicitly disable color output
Expand Down Expand Up @@ -92,5 +94,28 @@ func (o *Renderer) detectColorProfile() (p Profile) {
setProfile(ANSI)
}

ti, _ := terminfo.Load(term)

Check failure on line 97 in env.go

View workflow job for this annotation

GitHub Actions / lint-soft

variable 'ti' is only used in the if-statement (env.go:98:2); consider using short syntax (ifshort)
if ti != nil {

Check failure on line 98 in env.go

View workflow job for this annotation

GitHub Actions / lint-soft

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

Check failure on line 98 in env.go

View workflow job for this annotation

GitHub Actions / lint-soft

`if ti != 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 110 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 112 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 114 in env.go

View workflow job for this annotation

GitHub Actions / lint-soft

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

return
}

0 comments on commit d4d4a46

Please sign in to comment.