Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

const (
CARAPACE_COLOR = "CARAPACE_COLOR" // enable color
CARAPACE_COMPLINE = "CARAPACE_COMPLINE" // TODO
CARAPACE_COVERDIR = "CARAPACE_COVERDIR" // coverage directory for sandbox tests
CARAPACE_EXPERIMENTAL = "CARAPACE_EXPERIMENTAL" // enable experimental features
Expand All @@ -29,6 +30,9 @@ const (
)

func ColorDisabled() bool {
if v, ok := os.LookupEnv(CARAPACE_COLOR); ok { // TODO multiple modes
return v == "0"
}
return getBool(NO_COLOR) || os.Getenv(CLICOLOR) == "0"
}

Expand Down
73 changes: 49 additions & 24 deletions internal/shell/powershell/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,44 +42,69 @@ func ActionRawValues(currentWord string, meta common.Meta, values common.RawValu
descriptionStyle = s
}

nocolor := env.ColorDisabled()
tooltipEnabled := env.Tooltip()

vals := make([]completionResult, 0, len(values))
for _, val := range values {
if val.Value != "" { // must not be empty - any empty `''` parameter in CompletionResult causes an error
val.Value = sanitizer.Replace(val.Value)
nospace := meta.Nospace.Matches(val.Value)
if val.Value == "" {
continue // must not be empty - any empty `''` parameter in CompletionResult causes an error
}

if strings.ContainsAny(val.Value, ` {}()[]*$?\"|<>&(),;#`+"`") {
val.Value = fmt.Sprintf("'%v'", val.Value)
}
val.Value = sanitizer.Replace(val.Value)
nospace := meta.Nospace.Matches(val.Value)

if !nospace {
val.Value = val.Value + " "
}
if strings.ContainsAny(val.Value, ` {}()[]*$?\"|<>&(),;#`+"`") {
val.Value = fmt.Sprintf("'%v'", val.Value)
}

if val.Style == "" || ui.ParseStyling(val.Style) == nil {
val.Style = valueStyle
}
if !nospace {
val.Value = val.Value + " "
}

tooltip := " "
if tooltipEnabled && val.Description != "" {
tooltip = fmt.Sprintf("`e[%vm`e[%vm%v`e[21;22;23;24;25;29;39;49m", sgr(descriptionStyle+" bg-default"), sgr(descriptionStyle), sanitizer.Replace(val.TrimmedDescription()))
val.Description = ""
if val.Style == "" || ui.ParseStyling(val.Style) == nil {
val.Style = valueStyle
}

tooltip := " "
if tooltipEnabled && val.Description != "" {
switch nocolor {
case true:
tooltip = sanitizer.Replace(val.TrimmedDescription())
default:
tooltip = fmt.Sprintf("`e[%vm`e[%vm%v`e[21;22;23;24;25;29;39;49m",
sgr(descriptionStyle+" bg-default"),
sgr(descriptionStyle),
sanitizer.Replace(val.TrimmedDescription()))
}
val.Description = ""
}

listItemText := fmt.Sprintf("`e[21;22;23;24;25;29m`e[%vm%v`e[21;22;23;24;25;29;39;49m", sgr(val.Style), sanitizer.Replace(val.Display))
var listItemText string
switch nocolor {
case true:
listItemText = sanitizer.Replace(val.Display)
if val.Description != "" {
listItemText = fmt.Sprintf("%v (%v)", listItemText, sanitizer.Replace(val.TrimmedDescription()))
}
default:
listItemText = fmt.Sprintf("`e[21;22;23;24;25;29m`e[%vm%v`e[21;22;23;24;25;29;39;49m",
sgr(val.Style),
sanitizer.Replace(val.Display))
if val.Description != "" {
listItemText = listItemText + fmt.Sprintf("`e[%vm `e[%vm(%v)`e[21;22;23;24;25;29;39;49m", sgr(descriptionStyle+" bg-default"), sgr(descriptionStyle), sanitizer.Replace(val.TrimmedDescription()))
listItemText = listItemText + fmt.Sprintf("`e[%vm `e[%vm(%v)`e[21;22;23;24;25;29;39;49m",
sgr(descriptionStyle+" bg-default"),
sgr(descriptionStyle),
sanitizer.Replace(val.TrimmedDescription()))
}
listItemText = listItemText + "`e[0m"

vals = append(vals, completionResult{
CompletionText: val.Value,
ListItemText: ensureNotEmpty(listItemText),
ToolTip: ensureNotEmpty(tooltip),
})
}

vals = append(vals, completionResult{
CompletionText: val.Value,
ListItemText: ensureNotEmpty(listItemText),
ToolTip: ensureNotEmpty(tooltip),
})
}
m, _ := json.Marshal(vals)
return string(m)
Expand Down