package elvish
import (
"encoding/json"
"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"
)
var sanitizer = strings .NewReplacer (
"\n" , `` ,
"\r" , `` ,
"\t" , `` ,
)
func sanitize(values []common .RawValue ) []common .RawValue {
for index , v := range values {
(&values [index ]).Value = sanitizer .Replace (v .Value )
(&values [index ]).Display = sanitizer .Replace (v .Display )
(&values [index ]).Description = sanitizer .Replace (v .TrimmedDescription ())
}
return values
}
type completion struct {
Usage string
Messages common .Messages
DescriptionStyle string
Candidates []complexCandidate
}
type complexCandidate struct {
Value string
Display string
Description string
CodeSuffix string
Style string
}
func ActionRawValues (currentWord string , meta common .Meta , values common .RawValues ) string {
valueStyle := "default"
if s := style .Carapace .Value ; s != "" && ui .ParseStyling (s ) != nil {
valueStyle = s
}
descriptionStyle := "default"
if s := style .Carapace .Description ; s != "" && ui .ParseStyling (s ) != nil {
descriptionStyle = s
}
vals := make ([]complexCandidate , len (values ))
for index , val := range sanitize (values ) {
suffix := " "
if meta .Nospace .Matches (val .Value ) {
suffix = ""
}
if val .Style == "" || ui .ParseStyling (val .Style ) == nil {
val .Style = valueStyle
}
vals [index ] = complexCandidate {Value : val .Value , Display : val .Display , Description : val .Description , CodeSuffix : suffix , Style : val .Style }
}
if len (values ) > 0 {
meta .Usage = ""
}
m , _ := json .Marshal (completion {
Usage : meta .Usage ,
Messages : meta .Messages ,
DescriptionStyle : descriptionStyle ,
Candidates : vals ,
})
return string (m )
}
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 .