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

Function handleMultiSelectProcess

packages/effect/src/cli/Prompt.ts:2927–2965  ·  view source on GitHub ↗
(options: SelectOptionsReq<A> & MultiSelectOptionsReq)

Source from the content-addressed store, hash-verified

2925 })
2926
2927const handleMultiSelectProcess = <A>(options: SelectOptionsReq<A> & MultiSelectOptionsReq) => {
2928 return (input: Terminal.UserInput, state: MultiSelectState) => {
2929 const totalChoices = options.choices.length + metaOptionsCount
2930 switch (input.key.name) {
2931 case "k":
2932 case "up": {
2933 return processMultiSelectCursorUp({ ...state, error: Option.none() }, totalChoices)
2934 }
2935 case "j":
2936 case "down":
2937 case "tab": {
2938 return processMultiSelectCursorDown({ ...state, error: Option.none() }, totalChoices)
2939 }
2940 case "space": {
2941 return processSpace(state, options)
2942 }
2943 case "enter":
2944 case "return": {
2945 const selectedIndices = Array.from(state.selectedIndices).filter((index) => !options.choices[index].disabled)
2946 const selectedCount = selectedIndices.length
2947 if (options.min !== undefined && selectedCount < options.min) {
2948 return Effect.succeed(
2949 Action.NextFrame({ state: { ...state, error: Option.some(`At least ${options.min} are required`) } })
2950 )
2951 }
2952 if (options.max !== undefined && selectedCount > options.max) {
2953 return Effect.succeed(
2954 Action.NextFrame({ state: { ...state, error: Option.some(`At most ${options.max} choices are allowed`) } })
2955 )
2956 }
2957 const selectedValues = selectedIndices.sort(EffectNumber.Order).map((index) => options.choices[index].value)
2958 return Effect.succeed(Action.Submit({ value: selectedValues }))
2959 }
2960 default: {
2961 return Effect.succeed(Action.Beep())
2962 }
2963 }
2964 }
2965}
2966
2967const handleMultiSelectRender = <A>(options: SelectOptionsReq<A>) => {
2968 return (state: MultiSelectState, action: Action<MultiSelectState, Array<A>>) => {

Callers 1

MultiSelectFunction · 0.85

Calls 8

processSpaceFunction · 0.85
fromMethod · 0.80
someMethod · 0.80
filterMethod · 0.45
succeedMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected