Show choices list.

@param array $choices Available choices.
@param mixed $default
@param bool  $multi   Indicates multiple choices.

@return self
550117
protected function listOptions(array $choices, $default = null, bool $multi = false): self
    {
        if (!$this->isAssocChoice($choices)) {
            return $this->promptOptions($choices, $default);
        }

        $maxLen = \max(\array_map('strlen', \array_keys($choices)));

        foreach ($choices as $choice => $desc) {
            $this->writer->eol()->cyan(\str_pad("  [$choice]", $maxLen + 6))->comment($desc);
        }

        $label = $multi ? 'Choices (comma separated)' : 'Choice';

        $this->writer->eol()->yellow($label);

        return $this->promptOptions(\array_keys($choices), $default);
    }
235513
public function choice( array $keys, $default = false )
	{
		foreach( $keys as $key )
		{
			if( $this->offsetExists($key) )
			{
				return $this->items[$key];
			}
		}

		return $default;
	}
1219473
protected function askOptions(string $description, array $options, int $default, $multiSelect = false)
    {
        $helper   = $this->getHelper('question');
        $question = new ChoiceQuestion(
            $description,
            $options,
            $default
        );
        if ($multiSelect) {
            $question->setMultiselect(true);
        }
        $question->setErrorMessage('Answer is invalid');
        $answer = $helper->ask($this->input, $this->output, $question);

        return $answer;
    }
836948
public function confirmation($message, $choices = ['y' => true, 'n' => false], $default = false)
    {
        return $this->response->confirmation($message, $choices, $default);
    }
475475
public function load_choices() {
        if (is_array($this->choices)) {
            return true;
        }
        $this->choices = array();
        $days = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday');
        foreach ($days as $day) {
            $this->choices[$day] = get_string($day, 'calendar');
        }
        return true;
    }
11277
public function getListOptions(array $list = [], $default = [])
    {
        $options = [];
        foreach ($list as $key => $value) {
            $options[] = [
                'value'        => $key,
                'display-name' => $value,
            ];
            if (is_array($default) && in_array($key,$default)) {
                $indice = count($options) - 1;
                $options[$indice]['selected'] = '';
            }
        };
        return $options;
    }
1280203
public function choice($question, array $choices, $default = null, $attempts = null, $multiple = null)
    {
        $helper = $this->getHelperSet()->get('question');

        $question = new ChoiceQuestion("<question>$question</question> ", $choices, $default);

        $question->setMaxAttempts($attempts)->setMultiselect($multiple);

        return $helper->ask($this->input, $this->output, $question);
    }
1325238
private function deserializeChoices(ChoiceQuestion $choiceQuestion, array $choices, array $solutions, array $options = [])
    {
        $choiceEntities = $choiceQuestion->getChoices()->toArray();

        foreach ($choices as $index => $choiceData) {
            $choice = null;

            // Searches for an existing choice entity.
            foreach ($choiceEntities as $entityIndex => $entityChoice) {
                /** @var Choice $entityChoice */
                if ($entityChoice->getUuid() === $choiceData['id']) {
                    $choice = $entityChoice;
                    unset($choiceEntities[$entityIndex]);
                    break;
                }
            }

            $choice = $choice ?: new Choice();
            $choice->setUuid($choiceData['id']);
            $choice->setOrder($index);

            // Deserialize choice content
            $choice = $this->contentSerializer->deserialize($choiceData, $choice, $options);

            // Set choice score and feedback
            $choice->setScore(0);

            foreach ($solutions as $solution) {
                if ($solution['id'] === $choiceData['id']) {
                    $choice->setScore($solution['score']);

                    if (isset($solution['feedback'])) {
                        $choice->setFeedback($solution['feedback']);
                    }
                    break;
                }
            }

            if (0 < $choice->getScore()) {
                $choice->setExpected(true);
            }

            $choiceQuestion->addChoice($choice);
        }

        // Remaining choices are no longer in the Question
        foreach ($choiceEntities as $choiceToRemove) {
            $choiceQuestion->removeChoice($choiceToRemove);
        }
    }
21860
public function setLazy(string $id, Definition $definition, bool $multi = false): self
    {
        return $this->set($id, new Definition\Lazy($definition), $multi);
    }
28582
public function addChoices($choices)
    {
        if (func_num_args() > 1) {
            $choices = func_get_args();
        }

        foreach ($choices as $key => $value) {
            $label = $choice = $value;

            if (is_array($choice)) {
                $label = array_values($choice)[0];
                $choice = array_keys($choice)[0];
            } else if (is_string($key)) {
                $choice = $key;
                $label = $value;
            }

            $this->addChoice($choice, $label);
        }

        return $this;
    }
992354
public function load_choices() {
        global $CFG;

        if (is_array($this->choices)) {
            return true;
        }

        require_once($CFG->dirroot . '/question/type/multichoice/questiontype.php');
        $this->choices = qtype_multichoice::get_numbering_styles();

        return true;
    }
846633
public function confirmation($message, $choices = ['y' => true, 'n' => false], $default = false)
    {
        $message = is_array($message) ? call_user_func_array('sprintf', $message) : $message;

        $answers = [];
        foreach ($choices as $answer => $value) {
            $answers[$answer] = $answer;
            if ($value === $default) $answers[$answer] = ucfirst($answer);
        }
        
        $this->send(sprintf('%s [%s]: ', $message, join('/', $answers)), '');
        $answer = $this->readline();
        if ($answer === '') return $default;

        if (array_key_exists($answer, $choices)) {
            return $choices[$answer];
        } else {
            foreach ($choices as $key => $value) {
                if ($answer === substr($key, 0, strlen($answer))) return $value;
            }
            return $default;
        }
    }
1236325
def multchoicebox(message='Pick as many items as you like.', title='', choices=['program logic error - no choices specified']):
    
    return psidialogs.multi_choice(message=message, title=title, choices=choices)
1031749
public function addChoices(array $choices)
    {
        foreach ($choices as $choiceIdent => $choice) {
            $this->addChoice($choiceIdent, $choice);
        }

        return $this;
    }
1332716
public function findDefaults(array &$settings)
    {
        if (!isset($settings['allow_multiple_selection'])) {
            $settings['allow_multiple_selection'] = 'no';
        }

        if (!isset($settings['show_association'])) {
            $settings['show_association'] = 'no';
        }

        if (!isset($settings['sort_options'])) {
            $settings['sort_options'] = 'no';
        }
    }
997503
public function setMultiselect($multiselect)
    {
        $this->multiselect = $multiselect;
        $this->setValidator($this->getDefaultValidator());

        return $this;
    }
1256210
protected function promptOptions(array $choices, $default): self
    {
        $options = '';

        foreach ($choices as $choice) {
            $style    = \in_array($choice, (array) $default) ? 'boldCyan' : 'cyan';
            $options .= "/<$style>$choice</end>";
        }

        $options = \ltrim($options, '/');

        $this->writer->colors(" ($options): ");

        return $this;
    }