MCPcopy Create free account
hub / github.com/github/gh-aw / showTextList

Function showTextList

pkg/console/list.go:66–91  ·  view source on GitHub ↗

showTextList displays a non-interactive numbered list for non-TTY environments

(title string, items []ListItem)

Source from the content-addressed store, hash-verified

64
65// showTextList displays a non-interactive numbered list for non-TTY environments
66func showTextList(title string, items []ListItem) (string, error) {
67 listLog.Printf("Showing text list: title=%s, items=%d", title, len(items))
68
69 fmt.Fprintf(os.Stderr, "\n%s\n\n", title)
70 for i, item := range items {
71 fmt.Fprintf(os.Stderr, " %d) %s\n", i+1, item.title)
72 if item.description != "" {
73 fmt.Fprintf(os.Stderr, " %s\n", item.description)
74 }
75 }
76 fmt.Fprintf(os.Stderr, "\nSelect (1-%d): ", len(items))
77
78 var choice int
79 _, err := fmt.Scanf("%d", &choice)
80 if err != nil {
81 return "", fmt.Errorf("invalid input: %w", err)
82 }
83
84 if choice < 1 || choice > len(items) {
85 return "", fmt.Errorf("selection out of range (must be 1-%d)", len(items))
86 }
87
88 selectedItem := items[choice-1]
89 listLog.Printf("Selected item from text list: %s", selectedItem.value)
90 return selectedItem.value, nil
91}

Callers 1

ShowInteractiveListFunction · 0.85

Calls 2

PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected