package style
import (
"github.com/carapace-sh/carapace/third_party/github.com/elves/elvish/pkg/cli/lscolors"
"github.com/carapace-sh/carapace/third_party/github.com/elves/elvish/pkg/ui"
)
type Context interface {
Abs (s string ) (string , error )
Getenv (key string ) string
LookupEnv (key string ) (string , bool )
}
func ForPath (path string , sc Context ) string {
if abs , err := sc .Abs (path ); err == nil {
path = abs
}
return fromSGR (lscolors .GetColorist (sc .Getenv ("LS_COLORS" )).GetStyle (path ))
}
func ForPathExt (path string , sc Context ) string {
return fromSGR (lscolors .GetColorist (sc .Getenv ("LS_COLORS" )).GetStyleExt (path ))
}
func ForExtension (path string , sc Context ) string {
return ForPathExt ("." +path , sc )
}
func fromSGR(sgr string ) string {
s := ui .StyleFromSGR (sgr )
result := []string {}
if s .Foreground != nil {
result = append (result , s .Foreground .String ())
}
if s .Background != nil {
result = append (result , "bg-" +s .Background .String ())
}
if s .Bold {
result = append (result , Bold )
}
if s .Dim {
result = append (result , Dim )
}
if s .Italic {
result = append (result , Italic )
}
if s .Underlined {
result = append (result , Underlined )
}
if s .Blink {
result = append (result , Blink )
}
if s .Inverse {
result = append (result , Inverse )
}
return Of (result ...)
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .