Skip to content

Inquirer file selector prompt, you can navigate freely between directories, choose what type of files you want to allow and it is fully customizable.

License

Notifications You must be signed in to change notification settings

br14n-sol/inquirer-file-selector

Repository files navigation

inquirer-file-selector

An file selector prompt implementation for Inquirer.js.

license node-current version unpacked-size downloads

preview

Installation

npm install inquirer-file-selector

Usage

import fileSelector from 'inquirer-file-selector'

const filePath = await fileSelector({
  message: 'Select a file:',
  ...
})

Options

Option Type Required Description
message string The message to display in the prompt.
basePath string The path to the directory where it will be started.
Default: process.cwd()
pageSize number The maximum number of items to display in the list.
Default: 10
filter (file: FileStats) => boolean A function to filter files and directories.
If not provided, all files and directories will be included by default.
showExcluded boolean If true, the list will include files and directories that are excluded by the filter function.
Default: false
disabledLabel string The label to display when a file is disabled.
Default: (not allowed)
allowCancel boolean If true, the prompt will allow the user to cancel the selection.
Default: false
cancelText string The message to display when the user cancels the selection.
Default: Canceled.
emptyText string The message that will be displayed when the directory is empty.
Default: Directory is empty.
theme See Theming The theme to use for the file selector.
match (file: FileStats) => boolean Deprecated: Use filter instead.
hideNonMatch boolean Deprecated: Use showExcluded instead.

Theming

You can theme a prompt by passing a theme object option. The theme object only need to includes the keys you wish to modify, we'll fallback on the defaults for the rest.

type FileSelectorTheme = {
  icon: {
    /**
     * The prefix to use for the line.
     * @default isLast => isLast ? └── : ├──
     */
    linePrefix: (isLast: boolean) => string
  }
  style: {
    /**
     * The style to use for the disabled items.
     * @default chalk.dim
     */
    disabled: (text: string) => string
    /**
     * The style to use for the active item.
     * @default chalk.cyan
     */
    active: (text: string) => string
    /**
     * The style to use for the cancel text.
     * @default chalk.red
     */
    cancelText: (text: string) => string
    /**
     * The style to use for the empty text.
     * @default chalk.red
     */
    emptyText: (text: string) => string
    /**
     * The style to use for items of type directory.
     * @default chalk.yellow
     */
    directory: (text: string) => string
    /**
     * The style to use for items of type file.
     * @default chalk.white
     */
    file: (text: string) => string
    /**
     * The style to use for the current directory header.
     * @default chalk.magenta
     */
    currentDir: (text: string) => string
    /**
     * The style to use for the key bindings help.
     * @default chalk.white
     */
    help: (text: string) => string
    /**
     * The style to use for the keys in the key bindings help.
     * @default chalk.cyan
     */
    key: (text: string) => string
  }
}

Examples

For examples look in the examples/ directory. You can execute the examples using node.

cd examples/
node <example-name>.js

Note

Before running the examples, make sure you have installed the dependencies with npm install and compiled the project with npm run build.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am "feat: my new feature"
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Note

The commit message should follow the Conventional Commits specification.

Copyright & License

© 2024 Brian Fernandez

This project is licensed under the MIT license. See the file LICENSE for details.

About

Inquirer file selector prompt, you can navigate freely between directories, choose what type of files you want to allow and it is fully customizable.

Topics

Resources

License

Stars

Watchers

Forks