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

Function processSpace

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

Source from the content-addressed store, hash-verified

2874}
2875
2876const processSpace = <A>(
2877 state: MultiSelectState,
2878 options: SelectOptionsReq<A>
2879) => {
2880 const selectedIndices = new Set(state.selectedIndices)
2881 if (state.index === 0) {
2882 const selectableCount = options.choices.filter((choice) => !choice.disabled).length
2883 const selectedCount = Array.from(state.selectedIndices).filter((index) => !options.choices[index].disabled).length
2884 if (selectedCount === selectableCount) {
2885 selectedIndices.clear()
2886 } else {
2887 for (let i = 0; i < options.choices.length; i++) {
2888 if (!options.choices[i].disabled) {
2889 selectedIndices.add(i)
2890 }
2891 }
2892 }
2893 } else if (state.index === 1) {
2894 for (let i = 0; i < options.choices.length; i++) {
2895 if (options.choices[i].disabled || state.selectedIndices.has(i)) {
2896 selectedIndices.delete(i)
2897 } else {
2898 selectedIndices.add(i)
2899 }
2900 }
2901 } else {
2902 const choiceIndex = state.index - metaOptionsCount
2903 if (options.choices[choiceIndex].disabled) {
2904 return Effect.succeed(Action.Beep())
2905 } else if (selectedIndices.has(choiceIndex)) {
2906 selectedIndices.delete(choiceIndex)
2907 } else {
2908 selectedIndices.add(choiceIndex)
2909 }
2910 }
2911 return Effect.succeed(Action.NextFrame({ state: { ...state, selectedIndices } }))
2912}
2913
2914const handleMultiSelectClear = <A>(options: SelectOptionsReq<A>) =>
2915 Effect.fnUntraced(function*(state: MultiSelectState, _: Action<MultiSelectState, Array<A>>) {

Callers 1

handleMultiSelectProcessFunction · 0.85

Calls 7

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

Tested by

no test coverage detected