(options: FileOptions = {})
| 1031 | * @since 4.0.0 |
| 1032 | */ |
| 1033 | export const File = (options: FileOptions = {}): Prompt<string> => { |
| 1034 | const opts: FileOptionsReq = { |
| 1035 | ...options, |
| 1036 | type: options.type ?? "file", |
| 1037 | message: options.message ?? `Choose a file`, |
| 1038 | startingPath: Option.fromUndefinedOr(options.startingPath), |
| 1039 | default: Option.fromUndefinedOr(options.default), |
| 1040 | maxPerPage: options.maxPerPage ?? 10, |
| 1041 | filter: options.filter ?? (() => Effect.succeed(true)) |
| 1042 | } |
| 1043 | const initialState: Effect.Effect< |
| 1044 | FileState, |
| 1045 | never, |
| 1046 | Environment |
| 1047 | > = Effect.gen(function*() { |
| 1048 | const currentPath = yield* resolveCurrentPath(Option.none(), opts) |
| 1049 | const path = yield* Path.Path |
| 1050 | const defaultPath = Option.map(opts.default, (defaultValue) => path.resolve(currentPath, defaultValue)) |
| 1051 | const initialPath = Option.match(defaultPath, { |
| 1052 | onNone: () => currentPath, |
| 1053 | onSome: (defaultPath) => path.dirname(defaultPath) |
| 1054 | }) |
| 1055 | const files = yield* getFileList(initialPath, opts) |
| 1056 | const cursor = Option.match(defaultPath, { |
| 1057 | onNone: () => 0, |
| 1058 | onSome: (defaultPath) => { |
| 1059 | const index = files.indexOf(path.basename(defaultPath)) |
| 1060 | return index === -1 ? 0 : index |
| 1061 | } |
| 1062 | }) |
| 1063 | const confirm = FileConfirm.Hide() |
| 1064 | return { cursor, files, allFiles: files, query: "", path: Option.map(defaultPath, path.dirname), confirm } |
| 1065 | }) |
| 1066 | return Custom(initialState, { |
| 1067 | render: handleFileRender(opts), |
| 1068 | process: handleFileProcess(opts), |
| 1069 | clear: handleFileClear(opts) |
| 1070 | }) |
| 1071 | } |
| 1072 | |
| 1073 | /** |
| 1074 | * Composes prompts by using the output of this prompt to create the next prompt. |
nothing calls this directly
no test coverage detected