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

Function handleTextProcess

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

Source from the content-addressed store, hash-verified

3940}
3941
3942const handleTextProcess = (options: TextOptionsReq) => {
3943 return (input: Terminal.UserInput, state: TextState) => {
3944 if (input.key.ctrl) {
3945 switch (input.key.name) {
3946 case "u": {
3947 return processTextClear(state)
3948 }
3949 case "a": {
3950 return processTextCursorStart(state)
3951 }
3952 case "e": {
3953 return processTextCursorEnd(state)
3954 }
3955 default: {
3956 return Effect.succeed(Action.Beep())
3957 }
3958 }
3959 }
3960 switch (input.key.name) {
3961 case "backspace": {
3962 return processTextBackspace(state)
3963 }
3964 case "left": {
3965 return processTextCursorLeft(state)
3966 }
3967 case "right": {
3968 return processTextCursorRight(state)
3969 }
3970 case "home": {
3971 return processTextCursorStart(state)
3972 }
3973 case "end": {
3974 return processTextCursorEnd(state)
3975 }
3976 case "enter":
3977 case "return": {
3978 const value = state.value
3979 return Effect.match(options.validate(value), {
3980 onFailure: (error) =>
3981 Action.NextFrame({
3982 state: { ...state, value, error: Option.some(error) }
3983 }),
3984 onSuccess: (value) => Action.Submit({ value })
3985 })
3986 }
3987 case "tab": {
3988 return processTab(state, options)
3989 }
3990 default: {
3991 return defaultTextProcessor(Option.getOrElse(input.input, () => ""), state)
3992 }
3993 }
3994 }
3995}
3996
3997const handleTextClear = (options: TextOptionsReq) => {
3998 return (state: TextState, _: Action<TextState, string>) => {

Callers 1

basePromptFunction · 0.85

Calls 11

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

Tested by

no test coverage detected