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

Function handleProcessFloat

packages/effect/src/cli/Prompt.ts:3215–3280  ·  view source on GitHub ↗
(options: NumberOptionsReq)

Source from the content-addressed store, hash-verified

3213}
3214
3215const handleProcessFloat = (options: NumberOptionsReq) => {
3216 return (input: Terminal.UserInput, state: NumberState) => {
3217 if (input.key.ctrl && input.key.name === "u") {
3218 return processNumberClear(state)
3219 }
3220 switch (input.key.name) {
3221 case "backspace": {
3222 return processNumberBackspace(state)
3223 }
3224 case "k":
3225 case "up": {
3226 return Effect.succeed(Action.NextFrame({
3227 state: {
3228 ...state,
3229 value: state.value === "" || state.value === "-"
3230 ? `${options.incrementBy}`
3231 : `${globalThis.Number.parseFloat(state.value) + options.incrementBy}`,
3232 error: Option.none()
3233 }
3234 }))
3235 }
3236 case "j":
3237 case "down": {
3238 return Effect.succeed(Action.NextFrame({
3239 state: {
3240 ...state,
3241 value: state.value === "" || state.value === "-"
3242 ? `-${options.decrementBy}`
3243 : `${globalThis.Number.parseFloat(state.value) - options.decrementBy}`,
3244 error: Option.none()
3245 }
3246 }))
3247 }
3248 case "enter":
3249 case "return": {
3250 const parsed = globalThis.Number.parseFloat(state.value)
3251 if (globalThis.Number.isNaN(parsed)) {
3252 return Effect.succeed(Action.NextFrame({
3253 state: {
3254 ...state,
3255 error: Option.some("Must provide a floating point value")
3256 }
3257 }))
3258 } else {
3259 return Effect.flatMap(
3260 Effect.sync(() => EffectNumber.round(parsed, options.precision)),
3261 (rounded) =>
3262 Effect.match(options.validate(rounded), {
3263 onFailure: (error) =>
3264 Action.NextFrame({
3265 state: {
3266 ...state,
3267 error: Option.some(error)
3268 }
3269 }),
3270 onSuccess: (value) => Action.Submit({ value })
3271 })
3272 )

Callers 1

NumberFunction · 0.85

Calls 7

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

Tested by

no test coverage detected