Format the choices for use on output.

@return ChoiceListInterface
541979
public function format(): ChoiceListInterface
    {
        if (empty($this->choices)) {
            return $this;
        }

        $this->results = $this->parse($this->choices);

        return $this;
    }
761595
def choices(self):
        
        if isinstance(self.validator, list):
            return self.validator[0].print_choices()
        return self.validator.print_choices()
76686
public function choice($question, array $choices, $default = null, $attempts = null, $multiple = null)
    {
        return $this->output->choice($question, $choices, $default, $attempts, $multiple);
    }
1222750
public function prepareOptions()
    {
        foreach ($this->content as $key => $option) {
            if (!($option instanceof Option)) {
                throw new \InvalidArgumentException('List item should be an Windwalker\\Html\\Option object.');
            }

            if ($this->isChecked($option)) {
                $option['checked'] = 'checked';
            }

            $attrs = $option->getAttributes();

            $attrs['type'] = $this->type;
            $attrs['name'] = $this->getAttribute('name');

            $attrs['id'] = $option->getAttribute('id');
            $attrs['id'] = $attrs['id'] ?: strtolower(
                trim(
                    preg_replace(
                        '/[^A-Z0-9_\.-]/i',
                        '-',
                        $attrs['name'] ?: 'empty'
                    ),
                    '-'
                )
            );
            $attrs['id'] .= '-' . strtolower(
                trim(
                    preg_replace(
                        '/[^A-Z0-9_\.-]/i',
                        '-',
                        $option->getValue() ?: 'empty'
                    ),
                    '-'
                )
            );
            $attrs['id'] = 'input-' . $attrs['id'];
            $attrs['disabled'] = $this->disabled;
            $attrs['readonly'] = $this->readonly;

            // Do not affect source options
            $option = clone $option;

            $option->setAttributes($attrs);

            $input = new HtmlElement('input', null, $attrs);

            $option->setAttribute('disabled', null);
            $option->setAttribute('readonly', null);

            $label = $this->createLabel($option);

            $this->content[$key] = new HtmlElements([$input, $label]);
        }
    }
518901
public function formatTableOptions(array $options) {
        $output = [];

        foreach ($this->formatAttributes($options) as $key => $value) {
            if ($this->hasClause($key)) {
                $option = sprintf($this->getClause($key), $value);

            } else {
                $option = $this->getKeyword($key);

                if ($value !== true) {
                    $option .= ' ' . $value;
                }
            }

            $output[] = $option;
        }

        return implode(' ', $output);
    }
1123064
protected function selectChoice()
    {
        $index = array_search(
            $this->choices[$this->cursor->getPosition()],
            $this->answers
        );

        if (false !== $index) {
            unset($this->answers[$index]);
        } else {
            $this->answers[] = $this->choices[$this->cursor->getPosition()];
        }

        $this->answers = array_values($this->answers);

        return $this;
    }
555945
final public function optionHelp()
    {
        // Show Usage
        output()->write(
            (new Format())
                ->setContextualClass(Format::INFO)
                ->setString(language()->getLine('CLI_USAGE') . ':')
                ->setNewLinesBefore(1)
                ->setNewLinesAfter(1)
        );

        // Show Actions
        $this->loadActions();

        if (count($this->actionsPool)) {
            output()->write(
                (new Format())
                    ->setContextualClass(Format::INFO)
                    ->setString($this->commandName . '/action --option=value')
            );

            output()->write(
                (new Format())
                    ->setString(language()->getLine('CLI_ACTIONS') . ':')
                    ->setNewLinesBefore(2)
                    ->setNewLinesAfter(1)
            );

            $table = new Table();
            $table->isShowBorder = false;

            foreach ($this->actionsPool as $action) {

                if ($action instanceof AbstractCommander) {
                    $table
                        ->addRow()
                        ->addColumn($action->getCommandName())
                        ->addColumn(language()->getLine($action->getCommandDescription()));
                }
            }

            output()->write(
                (new Format())
                    ->setString($table->render())
            );
        } else {
            output()->write(
                (new Format())
                    ->setContextualClass(Format::INFO)
                    ->setString($this->commandName . ' --option=value')
            );
        }

        // Show Options
        output()->write(
            (new Format())
                ->setString(language()->getLine('CLI_OPTIONS') . ':')
                ->setNewLinesBefore(2)
                ->setNewLinesAfter(1)
        );

        $table = new Table();
        $table->isShowBorder = false;

        foreach ($this->commandOptions as $optionCaller => $optionProps) {
            $table
                ->addRow()
                ->addColumn('--' . $optionCaller)
                ->addColumn($optionProps[ 'shortcut' ])
                ->addColumn(language()->getLine($optionProps[ 'description' ]));
        }

        output()->write(
            (new Format())
                ->setString($table->render())
                ->setNewLinesAfter(2)
        );

        exit(EXIT_SUCCESS);
    }
832568
protected function renderList()
    {
        $list = '';
        $alignSpaces = 8;

        // Count key length
        $keys = array_keys($this->options);
        $lengths = array_map('strlen', $keys);
        $longest = max($lengths);
        $longest = $longest >= $alignSpaces ? $alignSpaces : $longest;

        // Build select list.
        foreach ($this->options as $key => $description) {
            $tmpl = str_replace('{WIDTH}', $longest, $this->listTemplate);

            $list .= sprintf($tmpl, ' ', $key, $description) . "\n";
        }

        return rtrim($list);
    }
125404
public function getFilterFormats() {
    $options = [];
    $formats = filter_formats($this->currentUser);
    foreach ($formats as $format) {
      $options[$format->id()] = $format->label();
    }
    return $options;
  }
984014
public static function getStringOperandsChoices()
    {
        $choices = array();

        $reflection = new \ReflectionClass(__CLASS__);
        foreach ($reflection->getConstants() as $name => $value) {
            if ('STRING_' === substr($name, 0, 7)) {
                $choices[$value] = strtolower(str_replace('STRING_', 'text.', $name));
            }
        }

        return array_flip($choices);
    }
1340121
public function formatSelectOptions(Field $field, EloquentCollection $results)
    {
        $return = array();

        foreach ($results as $m) {
            $return[] = array(
                'id'   => $m->getKey(),
                'text' => strval($m->{$field->getOption('name_field')}),
            );
        }

        return $return;
    }
1173013
public function format()
    {
        if ($this->format === null) {
            if (null !== ($format = $this->parameters->getParam('format'))) {
                $this->format = $format;
            } else {
                $headers = getallheaders();
                if (isset($headers['Accept'])) {
                    $acceptHeader = $headers['Accept'];
                    
                    $negotiator = new FormatNegotiator();
                    $priorities = ['html', 'json', 'xml', 'js', '*.*'];
                    $this->format = $negotiator->getBestFormat($acceptHeader, $priorities) ?: 'html';
                } else {
                    $this->format = 'html';
                }
            }
        }
        return $this->format;
    }
751403
public function createListFromChoices($choices, $value = null)
    {
        if (\is_string($value)) {
            $value = new PropertyPath($value);
        }

        if ($value instanceof PropertyPath) {
            $accessor = $this->propertyAccessor;
            $value = function ($choice) use ($accessor, $value) {
                // The callable may be invoked with a non-object/array value
                // when such values are passed to
                // ChoiceListInterface::getValuesForChoices(). Handle this case
                // so that the call to getValue() doesn't break.
                if (\is_object($choice) || \is_array($choice)) {
                    return $accessor->getValue($choice, $value);
                }
            };
        }

        return $this->decoratedFactory->createListFromChoices($choices, $value);
    }
868248
protected function getFormatOptionsFromPost()
    {
        $presetMode = post('format_preset');

        $options = [
            'delimiter' => null,
            'enclosure' => null,
            'escape' => null,
            'encoding' => null
        ];

        if ($presetMode == 'custom') {
            $options['delimiter'] = post('format_delimiter');
            $options['enclosure'] = post('format_enclosure');
            $options['escape'] = post('format_escape');
            $options['encoding'] = post('format_encoding');
        }

        return $options;
    }
1151917
private function getSortOrderChoices()
    {
        $choices = [];
        foreach ($this->getSortOrderValues() as $value) {
            $choices[$this->getSortOrderLabel($value)] = $value;
        }

        return $choices;
    }
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;
    }
1259906
public function defaultSelectizeOptions()
    {
        $metadata = $this->metadata();
        $options = [];

        if (isset($metadata['data']['selectize_options'])) {
            $options = $metadata['data']['selectize_options'];
            $options = $this->parseSelectizeOptions($options);
        }

        if ($this->deferred()) {
            $placeholder = $this->translator()->trans('Search...');
        } else {
            $placeholder = $this->translator()->trans('Select...');
        }

        $options['placeholder'] = $placeholder;
        $prop = $this->property();
        if ($prop instanceof SelectablePropertyInterface) {
            $choices = iterator_to_array($this->choices());

            if (isset($options['options'])) {
                $options['options'] = array_merge($options['options'], $choices);
            } else {
                $options['options'] = $choices;
            }

            $items = $this->propertyVal();

            if ($prop instanceof AbstractProperty) {
                $items = $prop->parseVal($items);

                if ($prop->l10n()) {
                    $items = (string)$this->translator()->translation($items);
                }

                if (is_string($items)) {
                    $items = explode($prop->multipleSeparator(), $items);
                }
            }

            if (!$prop->multiple()) {
                $items = (array)$items;
            }

            if (!$items) {
                $items = [];
            }

            // workaround for object setter casting the property as object.
            if ($items instanceof ModelInterface) {
                $items = $this->mapObjToChoice($items)['value'];
            }

            if (is_scalar($items)) {
                $items = [$items];
            }

            if (!isset($options['items'])) {
                $options['items'] = [];
            }
            $options['items'] = array_merge($options['items'], $items);
        }

        return $options;
    }