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 28, 2024
1 parent 9c98fb7 commit 27921d7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions env.go
Expand Up @@ -3,6 +3,8 @@ package lipgloss
import (
"strconv"
"strings"

"github.com/xo/terminfo"
)

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

ti, _ := terminfo.Load(term)
if ti != nil {

Check failure on line 99 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 99 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 111 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 113 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 115 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

0 comments on commit 27921d7

Please sign in to comment.