MCPcopy Create free account
hub / github.com/Effect-TS/effect / renderMultiSelectChoices

Function renderMultiSelectChoices

packages/effect/src/unstable/cli/Prompt.ts:2563–2615  ·  view source on GitHub ↗
(
  state: MultiSelectState,
  options: SelectOptionsReq<A> & MultiSelectOptionsReq,
  figures: Effect.Success<typeof platformFigures>,
  renderOptions?: RenderOptions | undefined
)

Source from the content-addressed store, hash-verified

2561}
2562
2563const renderMultiSelectChoices = <A>(
2564 state: MultiSelectState,
2565 options: SelectOptionsReq<A> & MultiSelectOptionsReq,
2566 figures: Effect.Success<typeof platformFigures>,
2567 renderOptions?: RenderOptions | undefined
2568) => {
2569 const choices = options.choices
2570 const selectableCount = choices.filter((choice) => !choice.disabled).length
2571 const selectedCount = Array.from(state.selectedIndices).filter((index) => !choices[index].disabled).length
2572 const allSelected = selectedCount === selectableCount
2573
2574 const selectAllText = allSelected
2575 ? options?.selectNone ?? "Select None"
2576 : options?.selectAll ?? "Select All"
2577
2578 const inverseSelectionText = options?.inverseSelection ?? "Inverse Selection"
2579
2580 const metaOptions = [
2581 { title: selectAllText },
2582 { title: inverseSelectionText }
2583 ]
2584 const allChoices = [...metaOptions, ...choices]
2585 const toDisplay = entriesToDisplay(state.index, allChoices.length, options.maxPerPage)
2586 const documents: Array<string> = []
2587 for (let index = toDisplay.startIndex; index < toDisplay.endIndex; index++) {
2588 const choice = allChoices[index]
2589 const isHighlighted = state.index === index
2590 let prefix = " "
2591 if (index === toDisplay.startIndex && toDisplay.startIndex > 0) {
2592 prefix = figures.arrowUp
2593 } else if (index === toDisplay.endIndex - 1 && toDisplay.endIndex < allChoices.length) {
2594 prefix = figures.arrowDown
2595 }
2596 if (index < metaOptions.length) {
2597 // Meta options
2598 const title = renderMultiSelectTitle(choice.title, isHighlighted, renderOptions)
2599 documents.push(prefix + " " + title)
2600 } else {
2601 // Regular choices
2602 const choiceIndex = index - metaOptions.length
2603 const isSelected = state.selectedIndices.has(choiceIndex)
2604 const checkbox = isSelected ? figures.checkboxOn : figures.checkboxOff
2605 const annotatedCheckbox = isHighlighted && renderOptions?.plain !== true
2606 ? Ansi.annotate(checkbox, Ansi.cyanBright)
2607 : checkbox
2608 const selectChoice = choice as SelectChoice<A>
2609 const title = renderChoiceTitle(selectChoice, isHighlighted, renderOptions)
2610 const description = renderChoiceDescription(selectChoice, isHighlighted, renderOptions)
2611 documents.push(prefix + " " + annotatedCheckbox + " " + title + " " + description)
2612 }
2613 }
2614 return documents.join("\n")
2615}
2616
2617const renderMultiSelectNextFrame = Effect.fnUntraced(
2618 function*<A>(state: MultiSelectState, options: SelectOptionsReq<A>) {

Callers 2

Prompt.tsFile · 0.85
handleMultiSelectClearFunction · 0.85

Calls 9

entriesToDisplayFunction · 0.85
renderMultiSelectTitleFunction · 0.85
renderChoiceTitleFunction · 0.85
renderChoiceDescriptionFunction · 0.85
filterMethod · 0.80
pushMethod · 0.80
joinMethod · 0.80
annotateMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected