MCPcopy Index your code
hub / github.com/Effect-TS/effect / handleProcessInteger

Function handleProcessInteger

packages/cli/src/internal/prompt/number.ts:213–272  ·  view source on GitHub ↗
(options: IntegerOptions)

Source from the content-addressed store, hash-verified

211}
212
213function handleProcessInteger(options: IntegerOptions) {
214 return (input: Terminal.UserInput, state: State) => {
215 switch (input.key.name) {
216 case "backspace": {
217 return processBackspace(state)
218 }
219 case "k":
220 case "up": {
221 return Effect.succeed(Action.NextFrame({
222 state: {
223 ...state,
224 value: state.value === "" || state.value === "-"
225 ? `${options.incrementBy}`
226 : `${Number.parseInt(state.value) + options.incrementBy}`,
227 error: Option.none()
228 }
229 }))
230 }
231 case "j":
232 case "down": {
233 return Effect.succeed(Action.NextFrame({
234 state: {
235 ...state,
236 value: state.value === "" || state.value === "-"
237 ? `-${options.decrementBy}`
238 : `${Number.parseInt(state.value) - options.decrementBy}`,
239 error: Option.none()
240 }
241 }))
242 }
243 case "enter":
244 case "return": {
245 return Effect.matchEffect(parseInt(state.value), {
246 onFailure: () =>
247 Effect.succeed(Action.NextFrame({
248 state: {
249 ...state,
250 error: Option.some("Must provide an integer value")
251 }
252 })),
253 onSuccess: (n) =>
254 Effect.match(options.validate(n), {
255 onFailure: (error) =>
256 Action.NextFrame({
257 state: {
258 ...state,
259 error: Option.some(error)
260 }
261 }),
262 onSuccess: (value) => Action.Submit({ value })
263 })
264 })
265 }
266 default: {
267 const value = Option.getOrElse(input.input, () => "")
268 return defaultIntProcessor(state, value)
269 }
270 }

Callers 1

integerFunction · 0.85

Calls 4

parseIntFunction · 0.85
defaultIntProcessorFunction · 0.85
validateMethod · 0.80
processBackspaceFunction · 0.70

Tested by

no test coverage detected