(options: FileOptions = {})
| 876 | * @since 4.0.0 |
| 877 | */ |
| 878 | export const file = (options: FileOptions = {}): Prompt<string> => { |
| 879 | const opts: FileOptionsReq = { |
| 880 | type: options.type ?? "file", |
| 881 | message: options.message ?? `Choose a file`, |
| 882 | startingPath: Option.fromUndefinedOr(options.startingPath), |
| 883 | default: Option.fromUndefinedOr(options.default), |
| 884 | maxPerPage: options.maxPerPage ?? 10, |
| 885 | filter: options.filter ?? (() => Effect.succeed(true)) |
| 886 | } |
| 887 | const initialState: Effect.Effect< |
| 888 | FileState, |
| 889 | never, |
| 890 | Environment |
| 891 | > = Effect.gen(function*() { |
| 892 | const currentPath = yield* resolveCurrentPath(Option.none(), opts) |
| 893 | const path = yield* Path.Path |
| 894 | const defaultPath = Option.map(opts.default, (defaultValue) => path.resolve(currentPath, defaultValue)) |
| 895 | const initialPath = Option.match(defaultPath, { |
| 896 | onNone: () => currentPath, |
| 897 | onSome: (defaultPath) => path.dirname(defaultPath) |
| 898 | }) |
| 899 | const files = yield* getFileList(initialPath, opts) |
| 900 | const cursor = Option.match(defaultPath, { |
| 901 | onNone: () => 0, |
| 902 | onSome: (defaultPath) => { |
| 903 | const index = files.indexOf(path.basename(defaultPath)) |
| 904 | return index === -1 ? 0 : index |
| 905 | } |
| 906 | }) |
| 907 | const confirm = Confirm.Hide() |
| 908 | return { cursor, files, allFiles: files, query: "", path: Option.map(defaultPath, path.dirname), confirm } |
| 909 | }) |
| 910 | return custom(initialState, { |
| 911 | render: handleFileRender(opts), |
| 912 | process: handleFileProcess(opts), |
| 913 | clear: handleFileClear(opts) |
| 914 | }) |
| 915 | } |
| 916 | |
| 917 | /** |
| 918 | * Composes prompts by using the output of this prompt to create the next prompt. |
nothing calls this directly
no test coverage detected