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

Function handleProcessFloat

packages/effect/src/unstable/cli/Prompt.ts:2984–3049  ·  view source on GitHub ↗
(options: FloatOptionsReq)

Source from the content-addressed store, hash-verified

2982}
2983
2984const handleProcessFloat = (options: FloatOptionsReq) => {
2985 return (input: Terminal.UserInput, state: NumberState) => {
2986 if (input.key.ctrl && input.key.name === "u") {
2987 return processNumberClear(state)
2988 }
2989 switch (input.key.name) {
2990 case "backspace": {
2991 return processNumberBackspace(state)
2992 }
2993 case "k":
2994 case "up": {
2995 return Effect.succeed(Action.NextFrame({
2996 state: {
2997 ...state,
2998 value: state.value === "" || state.value === "-"
2999 ? `${options.incrementBy}`
3000 : `${Number.parseFloat(state.value) + options.incrementBy}`,
3001 error: Option.none()
3002 }
3003 }))
3004 }
3005 case "j":
3006 case "down": {
3007 return Effect.succeed(Action.NextFrame({
3008 state: {
3009 ...state,
3010 value: state.value === "" || state.value === "-"
3011 ? `-${options.decrementBy}`
3012 : `${Number.parseFloat(state.value) - options.decrementBy}`,
3013 error: Option.none()
3014 }
3015 }))
3016 }
3017 case "enter":
3018 case "return": {
3019 const parsed = Number.parseFloat(state.value)
3020 if (Number.isNaN(parsed)) {
3021 return Effect.succeed(Action.NextFrame({
3022 state: {
3023 ...state,
3024 error: Option.some("Must provide a floating point value")
3025 }
3026 }))
3027 } else {
3028 return Effect.flatMap(
3029 Effect.sync(() => EffectNumber.round(parsed, options.precision)),
3030 (rounded) =>
3031 Effect.match(options.validate(rounded), {
3032 onFailure: (error) =>
3033 Action.NextFrame({
3034 state: {
3035 ...state,
3036 error: Option.some(error)
3037 }
3038 }),
3039 onSuccess: (value) => Action.Submit({ value })
3040 })
3041 )

Callers 1

floatFunction · 0.85

Calls 6

processNumberClearFunction · 0.85
processNumberBackspaceFunction · 0.85
defaultFloatProcessorFunction · 0.85
someMethod · 0.80
succeedMethod · 0.45
syncMethod · 0.45

Tested by

no test coverage detected