JSPM

inquirer-select-with-state

0.1.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q46245F
  • License MIT

Inquirer select prompt with a stateful banner

Package Exports

  • inquirer-select-with-state
  • inquirer-select-with-state/dist/select.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (inquirer-select-with-state) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

inquirer-select-with-state

Inquirer select prompt with a stateful banner

A fork of inquirer's built-in select command line prompt, but with the ability to add a stateful banner above the list of choices.

You provide a statefulBanner function. This function receives a setState function which can be called at will. The string sent to setState is shown above the select prompt. statefulBanner can also return a cleanup function.

Install

pnpm add inquirer-select-with-state
yarn add inquirer-select-with-state
npm add inquirer-select-with-state

Usage

import select from 'inquirer-select-with-state'

const answer = await select({
    message: 'Choose an option',
    choices: [
        { name: '1', value: '1' },
        { name: '2', value: '2' },
        { name: '3', value: '3' },
    ],
    statefulBanner: (setState: (s: string) => void) => {
        setState('Directory size: loading...')
        exec('du -sh', (err, stdout) => {
            if (!err) {
                setState(`Directory size: ${stdout}`)
            }
        })
    },
})

The prompt will initially look like this:

Directory size: loading...
? Choose an option
❯ 1
  2
  3

A moment later, it will automatically update:

Directory size: 123M
? Choose an option
❯ 1
  2
  3

Return value

If your banner has any side effects (e.g. timeouts), you can return a cleanup function which will be called when the prompt quits.

Example

See src/example.ts for a full example using async/await.