How to use the enquirer.Select function in enquirer

To help you get started, we’ve selected a few enquirer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github getcampsite / campkit / packages / cli / src / handleCreateCmd.js View on Github external
async function handleCreateCmd(pkg, options) {
  let template;
  const prompt = new Select({
    message: 'Choose a template',
    choices: ['aws node', 'aws node typescript'],
  });

  try {
    // get the project path
    let projectPath = await getProjectPath(
      fs.realpathSync(process.cwd()) + '/' + pkg,
      pkg
    );

    if (options.template) {
      template = options.template.trim();
      if (!prompt.choices.includes(template)) {
        template = await prompt.run();
      }
github enquirer / enquirer / examples / select / option-theme.js View on Github external
off: '  '
    }
  },
  prefix: state => emoji[state.status],
  pointer(state, choice, i) {
    let status = state.index === i ? 'on' : 'off';
    let symbol = this.symbols.radio[status];
    let fallback = '🗡️ ';
    if (typeof symbol === 'function') {
      return symbol(...arguments) || fallback;
    }
    return symbol || fallback;
  }
};

const prompt = new Select({
  name: 'halloween',
  message: 'Trick or treat! Take your pick',
  theme: halloween,
  choices: [
    { name: 'candy', value: 'Sweet!' },
    { name: 'apple', value: 'Hard... core?' },
    { name: 'toothpaste', value: 'Orange juice?' },
    { name: 'insult', value: 'You stink!' },
    { name: 'razor blade', value: 'Ouch!' }
  ]
});

prompt.run()
  .then(key => {
    let choice = prompt.choices.find(ch => ch.name === key);
    console.log('answer:', { [key]: choice.value });
github enquirer / enquirer / examples / select / option-header.js View on Github external
'use strict';

const yosay = require('yosay');
const { Select } = require('enquirer');

const prompt = new Select({
  name: 'color',
  message: 'Pick a color',
  header: yosay('Welcome to my awesome generator!'),
  choices: [
    'aqua',
    'black',
    'blue',
    'fuchsia',
    'gray',
    'green'
  ]
});

prompt.run()
  .then(answer => console.log('Answer:', answer))
  .catch(console.error);
github enquirer / enquirer / examples / select / option-pointer.js View on Github external
'use strict';

const colors = require('ansi-colors');
const { Select } = require('enquirer');

const prompt = new Select({
  name: 'color',
  message: 'Pick a flavor',
  choices: ['apple', 'grape', 'watermelon', 'cherry', 'orange'],
  pointer(choice, i) {
    return this.state.index === i ? colors.green('→') : ' ';
  }
});

prompt.run()
  .then(answer => console.log('Answer:', answer))
  .catch(console.error);
github bunqCommunity / bunq-cli / src / Modes / Interactive / interactive.ts View on Github external
const choices = [];
    if (isReady) {
        choices.push({ message: "View your monetary accounts", value: "view-monetary-account" });
        choices.push({ message: "Call an API endpoint", value: "call-endpoint" });
        choices.push({ message: "Create a new monetary account", value: "create-monetary-account" });
        if (isSandbox) {
            choices.push({ message: "Add funds to sandbox account", value: "request-sandbox-funds" });
        }
    }
    choices.push({ message: isReady ? "Modify API key" : "Setup an API key", value: "setup-api-key" });
    choices.push(separatorChoiceOption());
    choices.push({ message: "Refresh", value: "refresh" });
    choices.push({ message: "Quit", value: "quit" });

    const result = await new Select({
        message: "What would you like to do",
        choices: choices
    }).run();

    clearConsole();
    switch (result) {
        case "call-endpoint":
            return CallEndpoint(bunqCLI);
        case "request-sandbox-funds":
            return RequestSandboxFunds(bunqCLI);
        case "create-monetary-account":
            return CreateMonetaryAccount(bunqCLI);
        case "setup-api-key":
            return SetupApiKey(bunqCLI);
        case "view-monetary-account":
            return ViewMonetaryAccounts(bunqCLI);
github bunqCommunity / bunq-cli / src / Prompts / api_environment.ts View on Github external
export default async ENVIRONMENT => {
    const prompt = new Select({
        message: "Which environment would you like to use?",
        choices: [{ message: "Sandbox", value: "SANDBOX" }, { message: "Production", value: "PRODUCTION" }],
        initial: ENVIRONMENT ? ENVIRONMENT : ""
    });

    return prompt.run();
};
github bunqCommunity / bunq-cli / src / Prompts / select_monetary_account_id.ts View on Github external
export default async accounts => {
    const prompt = new Select({
        message: "Which monetary account would you like to use?",
        choices: accounts.map(accountInfo => {
            return {
                message: `${accountInfo.id}: ${accountInfo.description} - ${accountInfo.balance.value}`,
                value: accountInfo.id
            };
        })
    });

    return prompt.run();
};
github bunqCommunity / bunq-cli / src / Prompts / select_monetary_account_type.ts View on Github external
export default async () => {
    const prompt = new Select({
        message: "Which type of monetary account would you like to use?",
        choices: [{ message: "Regular", value: "regular" }, { message: "Savings", value: "savings" }]
    });

    return prompt.run();
};
github bunqCommunity / bunq-cli / src / Prompts / api_encryption_key.ts View on Github external
export default async ENCRYPTION_KEY => {
    const prompt = new Select({
        message: "No encryption key is set, would you like to enter one or have one generated for you?",
        choices: [{ message: "Generate a new key", value: "generate" }, { message: "Enter a key", value: "custom" }]
    });

    const encryptionKeyType = await prompt.run();
    if (encryptionKeyType === "generate") {
        return randomHex(32);
    } else {
        const inputPrompt = new Password({
            message: "Enter a 16, 24 or 32 bit hex encoded encryption key",
            initial: ENCRYPTION_KEY ? ENCRYPTION_KEY : ""
        });

        return inputPrompt.run();
    }
};
github enquirer / enquirer / examples / select / select-long.js View on Github external
'use strict';

const yosay = require('yosay');
const colors = require('ansi-colors');
const { Select } = require('enquirer');

/**
 * This prompt shows how you can easily customize the footer
 * to render a different value based on conditions.
 */

let keys = Object.keys(colors.styles);
let idx = 0;

const prompt = new Select({
  name: 'color',
  message: 'Pick a color',
  header: yosay('Welcome to my awesome generator!'),
  footer() {
    let fn = colors[keys[++idx % keys.length]];
    return '\n' + fn('(Scroll up and down to reveal more choices)');
  },
  limit: 5,
  choices: [
    'aqua',
    'black',
    'blue',
    'fuchsia',
    'gray',
    'green',
    'lime',