From b4f6f96f0f1e276daba16c79a0e3bb3d00a8fc29 Mon Sep 17 00:00:00 2001 From: rsteube Date: Sun, 30 Jul 2023 12:35:27 +0200 Subject: [PATCH] MultiPartsP: renamed param --- action.go | 13 +++++++------ docs/src/carapace/action/multiPartsP.md | 4 ++-- example/cmd/modifier.go | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/action.go b/action.go index 59f5e3e9..6545d813 100644 --- a/action.go +++ b/action.go @@ -115,13 +115,14 @@ func (a Action) MultiParts(dividers ...string) Action { }) } -// MultiPartsP is like MultiParts but with placeholder completion. -func (a Action) MultiPartsP(delimiter string, placeholderPattern string, f func(segment string, matches map[string]string) Action) Action { +// MultiPartsP is like MultiParts but with placeholders +func (a Action) MultiPartsP(delimiter string, pattern string, f func(placeholder string, matches map[string]string) Action) Action { + // TODO add delimiter as suffix for proper nospace handling (some values/placeholders might appear with and without suffix) return ActionCallback(func(c Context) Action { invoked := a.Invoke(c) return ActionMultiParts(delimiter, func(c Context) Action { - placeholder := regexp.MustCompile(placeholderPattern) + rPlaceholder := regexp.MustCompile(pattern) matchedData := make(map[string]string) matchedSegments := make(map[string]common.RawValue) staticMatches := make(map[int]bool) @@ -135,7 +136,7 @@ func (a Action) MultiPartsP(delimiter string, placeholderPattern string, f func( break segment } else { if segment != c.Parts[index] { - if !placeholder.MatchString(segment) { + if !rPlaceholder.MatchString(segment) { continue path // skip this path as it doesn't match and is not a placeholder } else { matchedData[segment] = c.Parts[index] // store entered data for placeholder (overwrite if duplicate) @@ -160,7 +161,7 @@ func (a Action) MultiPartsP(delimiter string, placeholderPattern string, f func( if len(segments) == (len(c.Parts) + 1) { matchedSegments[segments[len(c.Parts)]] = invoked.rawValues[index] } else { - if segment := segments[len(c.Parts)]; placeholder.MatchString(segment) { + if segment := segments[len(c.Parts)]; rPlaceholder.MatchString(segment) { matchedSegments[segment] = common.RawValue{} } else { matchedSegments[segment+delimiter] = common.RawValue{} @@ -170,7 +171,7 @@ func (a Action) MultiPartsP(delimiter string, placeholderPattern string, f func( actions := make([]Action, 0, len(matchedSegments)) for key, value := range matchedSegments { - if placeholder.MatchString(key) { + if rPlaceholder.MatchString(key) { actions = append(actions, f(key, matchedData)) } else { actions = append(actions, ActionStyledValuesDescribed(key, value.Description, value.Style)) // TODO tag,.. diff --git a/docs/src/carapace/action/multiPartsP.md b/docs/src/carapace/action/multiPartsP.md index 43ca4e21..916eedef 100644 --- a/docs/src/carapace/action/multiPartsP.md +++ b/docs/src/carapace/action/multiPartsP.md @@ -1,6 +1,6 @@ # MultiPartsP -[`MultiPartsP`] is like [MultiParts] but with placeholder completion. +[`MultiPartsP`] is like [MultiParts] but with placeholders. ```go carapace.ActionStyledValuesDescribed( @@ -8,7 +8,7 @@ carapace.ActionStyledValuesDescribed( "styles/custom", "custom style", style.Of(style.Blue, style.Blink), "styles", "list", style.Yellow, "styles/