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

Function handleProcessInteger

packages/effect/src/cli/Prompt.ts:3142–3203  ·  view source on GitHub ↗
(options: IntOptionsReq)

Source from the content-addressed store, hash-verified

3140}
3141
3142const handleProcessInteger = (options: IntOptionsReq) => {
3143 return (input: Terminal.UserInput, state: NumberState) => {
3144 if (input.key.ctrl && input.key.name === "u") {
3145 return processNumberClear(state)
3146 }
3147 switch (input.key.name) {
3148 case "backspace": {
3149 return processNumberBackspace(state)
3150 }
3151 case "k":
3152 case "up": {
3153 return Effect.succeed(Action.NextFrame({
3154 state: {
3155 ...state,
3156 value: state.value === "" || state.value === "-"
3157 ? `${options.incrementBy}`
3158 : `${globalThis.Number.parseInt(state.value) + options.incrementBy}`,
3159 error: Option.none()
3160 }
3161 }))
3162 }
3163 case "j":
3164 case "down": {
3165 return Effect.succeed(Action.NextFrame({
3166 state: {
3167 ...state,
3168 value: state.value === "" || state.value === "-"
3169 ? `-${options.decrementBy}`
3170 : `${globalThis.Number.parseInt(state.value) - options.decrementBy}`,
3171 error: Option.none()
3172 }
3173 }))
3174 }
3175 case "enter":
3176 case "return": {
3177 const parsed = globalThis.Number.parseInt(state.value)
3178 if (globalThis.Number.isNaN(parsed)) {
3179 return Effect.succeed(Action.NextFrame({
3180 state: {
3181 ...state,
3182 error: Option.some("Must provide an integer value")
3183 }
3184 }))
3185 } else {
3186 return Effect.match(options.validate(parsed), {
3187 onFailure: (error) =>
3188 Action.NextFrame({
3189 state: {
3190 ...state,
3191 error: Option.some(error)
3192 }
3193 }),
3194 onSuccess: (value) => Action.Submit({ value })
3195 })
3196 }
3197 }
3198 default: {
3199 return defaultIntProcessor(Option.getOrElse(input.input, () => ""), state)

Callers 1

IntFunction · 0.85

Calls 6

processNumberClearFunction · 0.85
processNumberBackspaceFunction · 0.85
defaultIntProcessorFunction · 0.85
someMethod · 0.80
validateMethod · 0.80
succeedMethod · 0.45

Tested by

no test coverage detected