(state: State, options: FileOptions)
| 257 | } |
| 258 | |
| 259 | function processSelection(state: State, options: FileOptions) { |
| 260 | return Effect.gen(function*() { |
| 261 | const fs = yield* FileSystem.FileSystem |
| 262 | const path = yield* Path.Path |
| 263 | const currentPath = yield* resolveCurrentPath(state.path, options) |
| 264 | const selectedPath = state.files[state.cursor] |
| 265 | const resolvedPath = path.resolve(currentPath, selectedPath) |
| 266 | const info = yield* Effect.orDie(fs.stat(resolvedPath)) |
| 267 | if (info.type === "Directory") { |
| 268 | const files = yield* getFileList(resolvedPath, options) |
| 269 | const filesWithoutParent = files.filter((file) => file !== "..") |
| 270 | // If the user selected a directory AND the prompt type can result with |
| 271 | // a directory, we must confirm: |
| 272 | // - If the selected directory has any files |
| 273 | // - Confirm whether or not the user wants to traverse those files |
| 274 | if (options.type === "directory" || options.type === "either") { |
| 275 | return filesWithoutParent.length === 0 |
| 276 | // Directory is empty so it's safe to select it |
| 277 | ? Action.Submit({ value: resolvedPath }) |
| 278 | // Directory has contents - show confirmation to user |
| 279 | : Action.NextFrame({ |
| 280 | state: { ...state, confirm: Confirm.Show() } |
| 281 | }) |
| 282 | } |
| 283 | return Action.NextFrame({ |
| 284 | state: { |
| 285 | cursor: 0, |
| 286 | files, |
| 287 | path: Option.some(resolvedPath), |
| 288 | confirm: Confirm.Hide() |
| 289 | } |
| 290 | }) |
| 291 | } |
| 292 | return Action.Submit({ value: resolvedPath }) |
| 293 | }) |
| 294 | } |
| 295 | |
| 296 | function handleProcess(options: FileOptions) { |
| 297 | return (input: Terminal.UserInput, state: State) => |
no test coverage detected