diff --git a/env.go b/env.go index aad1ae12..bfa6e9af 100644 --- a/env.go +++ b/env.go @@ -2,6 +2,8 @@ package lipgloss import ( "strings" + + "github.com/xo/terminfo" ) // envNoColor returns true if the environment variables explicitly disable color output @@ -92,5 +94,28 @@ func (o *Renderer) detectColorProfile() (p Profile) { setProfile(ANSI) } + ti, _ := terminfo.Load(term) + if ti != nil { + 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 { + setProfile(TrueColor) + } else if colors >= 0x100 { + setProfile(ANSI256) + } else if colors >= 0x10 { + setProfile(ANSI) + } + } + } + return }