package zsh
import (
"fmt"
"strings"
"github.com/carapace-sh/carapace/internal/common"
"github.com/carapace-sh/carapace/pkg/style"
"github.com/carapace-sh/carapace/third_party/github.com/elves/elvish/pkg/ui"
)
type zstyles struct {
rawValues common .RawValues
}
func (z zstyles ) descriptionSGR () string {
if s := style .Carapace .Description ; s != "" && ui .ParseStyling (s ) != nil {
return style .SGR (s )
}
return style .SGR (style .Default )
}
func (z zstyles ) valueSGR (val common .RawValue ) string {
if val .Style != "" && ui .ParseStyling (val .Style ) != nil {
return style .SGR (val .Style )
}
if ui .ParseStyling (style .Carapace .Value ) != nil {
return style .SGR (style .Carapace .Value )
}
return style .SGR (style .Default )
}
func (z zstyles ) Format () string {
replacer := strings .NewReplacer (
"#" , `\#` ,
"*" , `\*` ,
"(" , `\(` ,
")" , `\)` ,
"[" , `\[` ,
"]" , `\]` ,
"|" , `\|` ,
"~" , `\~` ,
)
formatted := make ([]string , 0 )
if len (z .rawValues ) < 500 {
for _ , val := range z .rawValues {
formatted = append (formatted , fmt .Sprintf ("=(#b)(%v)([ ]## -- *)=0=%v=%v" , replacer .Replace (val .Display ), z .valueSGR (val ), z .descriptionSGR ()))
formatted = append (formatted , fmt .Sprintf ("=(#b)(%v)=0=%v" , replacer .Replace (val .Display ), z .valueSGR (val )))
}
}
formatted = append (formatted , fmt .Sprintf ("=(#b)(%v)=0=%v" , "-- *" , z .descriptionSGR ()))
return strings .Join (formatted , ":" )
}
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 .