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

Function handleTextProcess

packages/effect/src/unstable/cli/Prompt.ts:3678–3731  ·  view source on GitHub ↗
(options: TextOptionsReq)

Source from the content-addressed store, hash-verified

3676}
3677
3678const handleTextProcess = (options: TextOptionsReq) => {
3679 return (input: Terminal.UserInput, state: TextState) => {
3680 if (input.key.ctrl) {
3681 switch (input.key.name) {
3682 case "u": {
3683 return processTextClear(state)
3684 }
3685 case "a": {
3686 return processTextCursorStart(state)
3687 }
3688 case "e": {
3689 return processTextCursorEnd(state)
3690 }
3691 default: {
3692 return Effect.succeed(Action.Beep())
3693 }
3694 }
3695 }
3696 switch (input.key.name) {
3697 case "backspace": {
3698 return processTextBackspace(state)
3699 }
3700 case "left": {
3701 return processTextCursorLeft(state)
3702 }
3703 case "right": {
3704 return processTextCursorRight(state)
3705 }
3706 case "home": {
3707 return processTextCursorStart(state)
3708 }
3709 case "end": {
3710 return processTextCursorEnd(state)
3711 }
3712 case "enter":
3713 case "return": {
3714 const value = state.value
3715 return Effect.match(options.validate(value), {
3716 onFailure: (error) =>
3717 Action.NextFrame({
3718 state: { ...state, value, error: Option.some(error) }
3719 }),
3720 onSuccess: (value) => Action.Submit({ value })
3721 })
3722 }
3723 case "tab": {
3724 return processTab(state, options)
3725 }
3726 default: {
3727 return defaultTextProcessor(Option.getOrElse(input.input, () => ""), state)
3728 }
3729 }
3730 }
3731}
3732
3733const handleTextClear = (options: TextOptionsReq) => {
3734 return (state: TextState, _: Action<TextState, string>) => {

Callers 1

basePromptFunction · 0.85

Calls 10

processTextClearFunction · 0.85
processTextCursorStartFunction · 0.85
processTextCursorEndFunction · 0.85
processTextBackspaceFunction · 0.85
processTextCursorLeftFunction · 0.85
processTextCursorRightFunction · 0.85
processTabFunction · 0.85
defaultTextProcessorFunction · 0.85
someMethod · 0.80
succeedMethod · 0.45

Tested by

no test coverage detected