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

Function handleAutoCompleteProcess

packages/effect/src/cli/Prompt.ts:3668–3718  ·  view source on GitHub ↗
(options: AutoCompleteOptionsReq<A>)

Source from the content-addressed store, hash-verified

3666}
3667
3668const handleAutoCompleteProcess = <A>(options: AutoCompleteOptionsReq<A>) => {
3669 return (input: Terminal.UserInput, state: AutoCompleteState) => {
3670 // Navigation is bound to ctrl chords rather than bare `j`/`k`, so that every
3671 // printable character reaches the filter input.
3672 if (input.key.ctrl) {
3673 switch (input.key.name) {
3674 case "u": {
3675 return processAutoCompleteClear(state, options)
3676 }
3677 case "p":
3678 case "k": {
3679 return processAutoCompleteCursorUp(state)
3680 }
3681 case "n": {
3682 return processAutoCompleteCursorDown(state)
3683 }
3684 default: {
3685 return Effect.succeed(Action.Beep())
3686 }
3687 }
3688 }
3689 switch (input.key.name) {
3690 case "up": {
3691 return processAutoCompleteCursorUp(state)
3692 }
3693 case "down": {
3694 return processAutoCompleteCursorDown(state)
3695 }
3696 case "tab": {
3697 return processAutoCompleteNext(state)
3698 }
3699 case "backspace": {
3700 return processAutoCompleteBackspace(state, options)
3701 }
3702 case "enter":
3703 case "return": {
3704 if (state.filtered.length === 0) {
3705 return Effect.succeed(Action.Beep())
3706 }
3707 const selected = options.choices[state.index]
3708 if (selected.disabled) {
3709 return Effect.succeed(Action.Beep())
3710 }
3711 return Effect.succeed(Action.Submit({ value: selected.value }))
3712 }
3713 default: {
3714 return processAutoCompleteInput(Option.getOrElse(input.input, () => ""), state, options)
3715 }
3716 }
3717 }
3718}
3719
3720interface TextOptionsReq extends OptionsReq<TextOptions> {
3721 /**

Callers 1

AutoCompleteFunction · 0.85

Calls 7

processAutoCompleteClearFunction · 0.85
processAutoCompleteNextFunction · 0.85
processAutoCompleteInputFunction · 0.85
succeedMethod · 0.45

Tested by

no test coverage detected