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

Function handleMultiSelectProcess

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

Source from the content-addressed store, hash-verified

2702 })
2703
2704const handleMultiSelectProcess = <A>(options: SelectOptionsReq<A> & MultiSelectOptionsReq) => {
2705 return (input: Terminal.UserInput, state: MultiSelectState) => {
2706 const totalChoices = options.choices.length + metaOptionsCount
2707 switch (input.key.name) {
2708 case "k":
2709 case "up": {
2710 return processMultiSelectCursorUp({ ...state, error: Option.none() }, totalChoices)
2711 }
2712 case "j":
2713 case "down":
2714 case "tab": {
2715 return processMultiSelectCursorDown({ ...state, error: Option.none() }, totalChoices)
2716 }
2717 case "space": {
2718 return processSpace(state, options)
2719 }
2720 case "enter":
2721 case "return": {
2722 const selectedIndices = Array.from(state.selectedIndices).filter((index) => !options.choices[index].disabled)
2723 const selectedCount = selectedIndices.length
2724 if (options.min !== undefined && selectedCount < options.min) {
2725 return Effect.succeed(
2726 Action.NextFrame({ state: { ...state, error: Option.some(`At least ${options.min} are required`) } })
2727 )
2728 }
2729 if (options.max !== undefined && selectedCount > options.max) {
2730 return Effect.succeed(
2731 Action.NextFrame({ state: { ...state, error: Option.some(`At most ${options.max} choices are allowed`) } })
2732 )
2733 }
2734 const selectedValues = selectedIndices.sort(EffectNumber.Order).map((index) => options.choices[index].value)
2735 return Effect.succeed(Action.Submit({ value: selectedValues }))
2736 }
2737 default: {
2738 return Effect.succeed(Action.Beep())
2739 }
2740 }
2741 }
2742}
2743
2744const handleMultiSelectRender = <A>(options: SelectOptionsReq<A>) => {
2745 return (state: MultiSelectState, action: Action<MultiSelectState, Array<A>>) => {

Callers 1

multiSelectFunction · 0.85

Calls 7

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

Tested by

no test coverage detected