MCPcopy Index your code
hub / github.com/coder/coder / View

Method View

cli/cliui/select.go:638–696  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

636}
637
638func (m multiSelectModel) View() string {
639 var s strings.Builder
640
641 msg := pretty.Sprintf(pretty.Bold(), "? %s", m.message)
642
643 if m.selected {
644 selected := pretty.Sprint(DefaultStyles.Keyword, strings.Join(m.selectedOptions(), ", "))
645 _, _ = s.WriteString(fmt.Sprintf("%s %s\n", msg, selected))
646
647 return s.String()
648 }
649
650 if m.isCustomInputMode {
651 _, _ = s.WriteString(fmt.Sprintf("%s\nEnter custom value: %s\n", msg, m.customInput))
652 return s.String()
653 }
654
655 _, _ = s.WriteString(fmt.Sprintf(
656 "%s %s[Use arrows to move, space to select, <right> to all, <left> to none, type to filter]\n",
657 msg,
658 m.search.View(),
659 ))
660
661 options := m.filteredOptions()
662 for i, option := range options {
663 cursor := " "
664 chosen := "[ ]"
665 o := option.option
666
667 if m.cursor == i {
668 cursor = pretty.Sprint(DefaultStyles.Keyword, "> ")
669 chosen = pretty.Sprint(DefaultStyles.Keyword, "[ ]")
670 o = pretty.Sprint(DefaultStyles.Keyword, o)
671 }
672
673 if option.chosen {
674 chosen = pretty.Sprint(DefaultStyles.Keyword, "[x]")
675 }
676
677 _, _ = s.WriteString(fmt.Sprintf(
678 "%s%s %s\n",
679 cursor,
680 chosen,
681 o,
682 ))
683 }
684
685 if m.enableCustomInput {
686 // Add the "+ Add custom value" option at the bottom
687 cursor := " "
688 text := " + Add custom value"
689 if m.cursor == len(options) {
690 cursor = pretty.Sprint(DefaultStyles.Keyword, "> ")
691 text = pretty.Sprint(DefaultStyles.Keyword, text)
692 }
693 _, _ = s.WriteString(fmt.Sprintf("%s%s\n", cursor, text))
694 }
695 return s.String()

Callers

nothing calls this directly

Calls 5

selectedOptionsMethod · 0.95
filteredOptionsMethod · 0.95
WriteStringMethod · 0.80
StringMethod · 0.45
ViewMethod · 0.45

Tested by

no test coverage detected