sunkan/console-select

A fancy selection interface for symfony's console component.

4.0.0 2025-05-26 10:26 UTC

This package is auto-updated.

Last update: 2025-05-26 10:27:47 UTC


README

A fancy selection interface for symfony's console component.

Sample

Requirements

This project is intended to be run with one of these frameworks:

  • symfony/console 5.0+

Install

composer require sunkan/console-select

On Symfony

Add the EddIriarte\Console\Traits\SelectableInputs trait to your command class

# importing : \EddIriarte\Console\Helpers\SelectionHelper
# passing the input and output interfaces
$this->getHelperSet()->set(
  new SelectionHelper($this->input, $this->output)
);

Checkboxes

Useful when you need several answers from the user.

$selected = $this->select(
  'Select characters that appeared in "Star Wars,  Episode I - The phantom menace"',
  [
    'Ahsoka Tano',
    'Anakin Skywalker',
    'Boba Fett',
    'Chewbacca',
    'Count Dooku',
    'Darth Maul',
    'Darth Vader',
    'Finn',
    'Han Solo',
    'Jabba the Hutt',
    'Jar Jar Binks',
    'Kylo Ren',
    'Lando Calrissian',
    'Luke Skywalker',
    'Mace Windu',
    'Obi-Wan Kenobi',
    'Padmé Amidala',
    'Sheev Palpatine',
    'Poe Dameron',
    'Princess Leia Organa',
    'Qui-Gon Jinn',
    'Rey',
    'Watto',
    'Yoda',
  ]
);

Radio

Useful when you need the user to pick only one anwer from the list.

$selected = $this->select(
  'What is the name of the ancient Jedi master that lives at the swamps of Dagobah',
  [
    'Ahsoka Tano',
    'Anakin Skywalker',
    'Boba Fett',
    'Chewbacca',
    'Count Dooku',
    'Darth Maul',
    'Darth Vader',
    'Finn',
    'Han Solo',
    'Jabba the Hutt',
    'Jar Jar Binks',
    'Kylo Ren',
    'Lando Calrissian',
    'Luke Skywalker',
    'Mace Windu',
    'Obi-Wan Kenobi',
    'Padmé Amidala',
    'Sheev Palpatine',
    'Poe Dameron',
    'Princess Leia Organa',
    'Qui-Gon Jinn',
    'Rey',
    'Watto',
    'Yoda',
  ],
  false // third argument(bool) that allows multiple selections (default: true)
);

Still to do

  • Handle user-interruptions, such as Ctrl+C

License

The MIT License (MIT). Please see License File for more information.