MCPcopy Index your code
hub / github.com/pterm/pterm / renderSelectMenu

Method renderSelectMenu

interactive_select_printer.go:272–315  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

270}
271
272func (p *InteractiveSelectPrinter) renderSelectMenu() string {
273 var content strings.Builder
274 if p.Filter {
275 content.WriteString(Sprintf("%s %s: %s\n", p.text, p.SelectorStyle.Sprint(p.FilterInputPlaceholder), p.fuzzySearchString))
276 } else {
277 content.WriteString(Sprintf("%s:\n", p.text))
278 }
279
280 // find options that match fuzzy search string
281 rankedResults := fuzzy.RankFindFold(p.fuzzySearchString, p.Options)
282 // map rankedResults to fuzzySearchMatches
283 p.fuzzySearchMatches = []string{}
284 if len(rankedResults) != len(p.Options) {
285 sort.Sort(rankedResults)
286 }
287 for _, result := range rankedResults {
288 p.fuzzySearchMatches = append(p.fuzzySearchMatches, result.Target)
289 }
290
291 if len(p.fuzzySearchMatches) != 0 {
292 p.result = p.fuzzySearchMatches[p.selectedOption]
293 }
294
295 indexMapper := make([]string, len(p.fuzzySearchMatches))
296 for i := 0; i < len(p.fuzzySearchMatches); i++ {
297 // if in displayed options range
298 if i >= p.displayedOptionsStart && i < p.displayedOptionsEnd {
299 indexMapper[i] = p.fuzzySearchMatches[i]
300 }
301 }
302
303 for i, option := range indexMapper {
304 if option == "" {
305 continue
306 }
307 if i == p.selectedOption {
308 content.WriteString(Sprintf("%s %s\n", p.renderSelector(), p.OptionStyle.Sprint(option)))
309 } else {
310 content.WriteString(Sprintf(" %s\n", p.OptionStyle.Sprint(option)))
311 }
312 }
313
314 return content.String()
315}
316
317func (p InteractiveSelectPrinter) renderFinishedMenu() string {
318 var content string

Callers 1

ShowMethod · 0.95

Calls 4

renderSelectorMethod · 0.95
SprintfFunction · 0.85
SprintMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected