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

Function processSpace

packages/effect/src/unstable/cli/Prompt.ts:2653–2689  ·  view source on GitHub ↗
(
  state: MultiSelectState,
  options: SelectOptionsReq<A>
)

Source from the content-addressed store, hash-verified

2651}
2652
2653const processSpace = <A>(
2654 state: MultiSelectState,
2655 options: SelectOptionsReq<A>
2656) => {
2657 const selectedIndices = new Set(state.selectedIndices)
2658 if (state.index === 0) {
2659 const selectableCount = options.choices.filter((choice) => !choice.disabled).length
2660 const selectedCount = Array.from(state.selectedIndices).filter((index) => !options.choices[index].disabled).length
2661 if (selectedCount === selectableCount) {
2662 selectedIndices.clear()
2663 } else {
2664 for (let i = 0; i < options.choices.length; i++) {
2665 if (!options.choices[i].disabled) {
2666 selectedIndices.add(i)
2667 }
2668 }
2669 }
2670 } else if (state.index === 1) {
2671 for (let i = 0; i < options.choices.length; i++) {
2672 if (options.choices[i].disabled || state.selectedIndices.has(i)) {
2673 selectedIndices.delete(i)
2674 } else {
2675 selectedIndices.add(i)
2676 }
2677 }
2678 } else {
2679 const choiceIndex = state.index - metaOptionsCount
2680 if (options.choices[choiceIndex].disabled) {
2681 return Effect.succeed(Action.Beep())
2682 } else if (selectedIndices.has(choiceIndex)) {
2683 selectedIndices.delete(choiceIndex)
2684 } else {
2685 selectedIndices.add(choiceIndex)
2686 }
2687 }
2688 return Effect.succeed(Action.NextFrame({ state: { ...state, selectedIndices } }))
2689}
2690
2691const handleMultiSelectClear = <A>(options: SelectOptionsReq<A>) =>
2692 Effect.fnUntraced(function*(state: MultiSelectState, _: Action<MultiSelectState, Array<A>>) {

Callers 1

handleMultiSelectProcessFunction · 0.85

Calls 5

filterMethod · 0.80
clearMethod · 0.80
addMethod · 0.65
hasMethod · 0.45
succeedMethod · 0.45

Tested by

no test coverage detected