CompleteEventTypes returns the known event types that complete the last comma-separated item of toComplete, each prefixed with the preceding items and followed by its description. Types already listed are left out.
(toComplete string)
| 18 | // CompleteEventTypes returns the known event types that complete the last comma-separated item of toComplete, each |
| 19 | // prefixed with the preceding items and followed by its description. Types already listed are left out. |
| 20 | func CompleteEventTypes(toComplete string) []string { |
| 21 | var prefix string |
| 22 | var chosen []string |
| 23 | if idx := strings.LastIndexByte(toComplete, ','); idx >= 0 { |
| 24 | prefix = toComplete[:idx+1] |
| 25 | chosen = strings.Split(toComplete[:idx], ",") |
| 26 | toComplete = toComplete[idx+1:] |
| 27 | } |
| 28 | var results []string |
| 29 | for _, t := range EventTypes { |
| 30 | if strings.HasPrefix(t.Name, toComplete) && !slices.Contains(chosen, t.Name) { |
| 31 | results = append(results, prefix+t.Name+"\t"+t.Description) |
| 32 | } |
| 33 | } |
| 34 | return results |
| 35 | } |