diff options
Diffstat (limited to 'predict/predict.go')
| -rw-r--r-- | predict/predict.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/predict/predict.go b/predict/predict.go new file mode 100644 index 0000000..f4d5bb7 --- /dev/null +++ b/predict/predict.go @@ -0,0 +1,34 @@ +// Package predict provides helper functions for completion predictors. +package predict + +import "github.com/posener/complete" + +// Set predicts a set of predefined values. +type Set []string + +func (p Set) Predict(_ string) (options []string) { + return p +} + +var ( + // Something is used to indicate that does not completes somthing. Such that other prediction + // wont be applied. + Something = Set{""} + + // Nothing is used to indicate that does not completes anything. + Nothing = Set{} +) + +// Or unions prediction functions, so that the result predication is the union of their +// predications. +func Or(ps ...complete.Predictor) complete.Predictor { + return complete.PredictFunc(func(prefix string) (options []string) { + for _, p := range ps { + if p == nil { + continue + } + options = append(options, p.Predict(prefix)...) + } + return + }) +} |
