(options: IntegerOptionsReq)
| 2909 | } |
| 2910 | |
| 2911 | const handleProcessInteger = (options: IntegerOptionsReq) => { |
| 2912 | return (input: Terminal.UserInput, state: NumberState) => { |
| 2913 | if (input.key.ctrl && input.key.name === "u") { |
| 2914 | return processNumberClear(state) |
| 2915 | } |
| 2916 | switch (input.key.name) { |
| 2917 | case "backspace": { |
| 2918 | return processNumberBackspace(state) |
| 2919 | } |
| 2920 | case "k": |
| 2921 | case "up": { |
| 2922 | return Effect.succeed(Action.NextFrame({ |
| 2923 | state: { |
| 2924 | ...state, |
| 2925 | value: state.value === "" || state.value === "-" |
| 2926 | ? `${options.incrementBy}` |
| 2927 | : `${Number.parseInt(state.value) + options.incrementBy}`, |
| 2928 | error: Option.none() |
| 2929 | } |
| 2930 | })) |
| 2931 | } |
| 2932 | case "j": |
| 2933 | case "down": { |
| 2934 | return Effect.succeed(Action.NextFrame({ |
| 2935 | state: { |
| 2936 | ...state, |
| 2937 | value: state.value === "" || state.value === "-" |
| 2938 | ? `-${options.decrementBy}` |
| 2939 | : `${Number.parseInt(state.value) - options.decrementBy}`, |
| 2940 | error: Option.none() |
| 2941 | } |
| 2942 | })) |
| 2943 | } |
| 2944 | case "enter": |
| 2945 | case "return": { |
| 2946 | const parsed = Number.parseInt(state.value) |
| 2947 | if (Number.isNaN(parsed)) { |
| 2948 | return Effect.succeed(Action.NextFrame({ |
| 2949 | state: { |
| 2950 | ...state, |
| 2951 | error: Option.some("Must provide an integer value") |
| 2952 | } |
| 2953 | })) |
| 2954 | } else { |
| 2955 | return Effect.match(options.validate(parsed), { |
| 2956 | onFailure: (error) => |
| 2957 | Action.NextFrame({ |
| 2958 | state: { |
| 2959 | ...state, |
| 2960 | error: Option.some(error) |
| 2961 | } |
| 2962 | }), |
| 2963 | onSuccess: (value) => Action.Submit({ value }) |
| 2964 | }) |
| 2965 | } |
| 2966 | } |
| 2967 | default: { |
| 2968 | return defaultIntProcessor(Option.getOrElse(input.input, () => ""), state) |
no test coverage detected