effect icon indicating copy to clipboard operation
effect copied to clipboard

Prompt.file filter does not provide enough context to filter files

Open danielo515 opened this issue 1 year ago • 0 comments

What is the problem this feature would solve?

Hello. I'm facing some problems using the Prompt.file utility. The first surprising thing is that using a filter to check the file extension can also remove the ability to travel to upper directories, so instead of just checking for the extension I also have to account for .., not very annoying, but worth mentioning IMO.

Second is that the provided path is not absolute, neither relative to the starting directory where the execution started, so if you want to check if the file is a directory (for example) and the user has navigated to a subfolder or to a parent folder, you have no way to know where is the actual file your filer has to check.

Here is an example of what I'm trying:

  const xmlPath = yield* Prompt.file({
    filter: (p) =>
      Effect.gen(function* (_) {
        console.log(p);
        const stat = yield* fs.stat(path.resolve(p)).pipe(Effect.orDie);
        return stat.type === "Directory" || p.endsWith(".xml");
      }),
    message: "Please select one XML file",
  });

What is the feature you are proposing to solve the problem?

The filter should receive a full path, or a relative path, or a file handle

What alternatives have you considered?

The only one I can think about is to implement my own custom input

danielo515 avatar Jul 31 '24 17:07 danielo515