Exemplo n.º 1
0
    def _write_error(self, io: IO, error: Exception) -> None:
        """
        Outputs an error message.
        """
        message = "<error>{}</error>".format(str(error))

        io.write_error_line(message)
Exemplo n.º 2
0
    def _write_prompt(self, io: IO) -> None:
        """
        Outputs the question prompt.
        """
        message = self._question
        default = self._default

        if default is None:
            message = "<question>{}</question>: ".format(message)
        elif self._multi_select:
            choices = self._choices
            default = default.split(",")

            for i, value in enumerate(default):
                default[i] = choices[int(value.strip())]

            message = "<question>{}</question> [<comment>{}</comment>]:".format(
                message, ", ".join(default))
        else:
            choices = self._choices
            message = "<question>{}</question> [<comment>{}</comment>]:".format(
                message, choices[int(default)])

        if len(self._choices) > 1:
            width = max(
                *map(len, [str(k) for k, _ in enumerate(self._choices)]))
        else:
            width = 1

        messages = [message]
        for key, value in enumerate(self._choices):
            messages.append(" [<comment>{:{}}</>] {}".format(
                key, width, value))

        io.write_error_line("\n".join(messages))

        message = self._prompt

        io.write_error(message)