package zsh
import (
"fmt"
"strings"
"github.com/rsteube/carapace/internal/common"
)
var sanitizer = strings .NewReplacer (
"\n" , `` ,
"\r" , `` ,
"\t" , `` ,
)
var quoter = strings .NewReplacer (
`\` , `\\` ,
`&` , `\&` ,
`<` , `\<` ,
`>` , `\>` ,
"`" , "\\`" ,
`'` , `\'` ,
`"` , `\"` ,
`{` , `\{` ,
`}` , `\}` ,
`$` , `\$` ,
`#` , `\#` ,
`|` , `\|` ,
`?` , `\?` ,
`(` , `\(` ,
`)` , `\)` ,
`;` , `\;` ,
` ` , `\ ` ,
`[` , `\[` ,
`]` , `\]` ,
`*` , `\*` ,
`~` , `\~` ,
)
func quoteValue(s string ) string {
if strings .HasPrefix (s , "~/" ) || NamedDirectories .Matches (s ) {
return "~" + quoter .Replace (strings .TrimPrefix (s , "~" ))
}
return quoter .Replace (s )
}
func ActionRawValues (currentWord string , meta common .Meta , values common .RawValues ) string {
tagGroup := make ([]string , 0 )
values .EachTag (func (tag string , values common .RawValues ) {
vals := make ([]string , len (values ))
displays := make ([]string , len (values ))
for index , val := range values {
val .Value = sanitizer .Replace (val .Value )
val .Value = quoteValue (val .Value )
val .Value = strings .ReplaceAll (val .Value , `\` , `\\` )
val .Value = strings .ReplaceAll (val .Value , `:` , `\:` )
if !meta .Nospace .Matches (val .Value ) {
val .Value = val .Value + " "
}
val .Display = sanitizer .Replace (val .Display )
val .Display = strings .ReplaceAll (val .Display , `\` , `\\` )
val .Display = strings .ReplaceAll (val .Display , `:` , `\:` )
val .Description = sanitizer .Replace (val .Description )
vals [index ] = val .Value
if strings .TrimSpace (val .Description ) == "" {
displays [index ] = val .Display
} else {
displays [index ] = fmt .Sprintf ("%v:%v" , val .Display , val .Description )
}
}
tagGroup = append (tagGroup , strings .Join ([]string {tag , strings .Join (displays , "\n" ), strings .Join (vals , "\n" )}, "\003" ))
})
return fmt .Sprintf ("%v\001%v\001%v\001" , zstyles {values }.Format (), message {meta }.Format (), strings .Join (tagGroup , "\002" )+"\002" )
}
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 .