How to use the cleo.formatters.Formatter.escape function in cleo

To help you get started, we’ve selected a few cleo 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 sdispater / cleo / tests / formatters / test_output_formatter.py View on Github external
def test_lg_char_escaping(self):
        formatter = Formatter(True)

        self.assertEqual('foosome info',
            formatter.format('\\some info\\')
        )
        self.assertEqual(
            '\\some info\\',
            Formatter.escape('some info')
        )
github sdispater / cleo / cleo / helpers / question_helper.py View on Github external
message = '{} '.format(message)
        elif isinstance(question, ConfirmationQuestion):
            message = '{} (yes/no) [{}] '.format(
                message,
                'yes' if default else 'no'
            )
        elif isinstance(question, ChoiceQuestion) and question.multiselect:
            choices = question.choices
            default = default.split(',')

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

            message = '{} [{}]:'.format(
                message,
                Formatter.escape(', '.join(default))
            )
        elif isinstance(question, ChoiceQuestion):
            choices = question.choices
            message = '{} [{}]:'.format(
                message,
                Formatter.escape(choices[int(default)])
            )

        if isinstance(question, ChoiceQuestion):
            if len(question.choices) > 1:
                width = max(*map(self.len, [str(k) for k, _ in enumerate(question.choices)]))
            else:
                width = self.len('0')

            messages = [message]
            for key, value in enumerate(question.choices):
github sdispater / cleo / cleo / styles / cleo_style.py View on Github external
messages = [messages]

        lines = []

        # Add type
        if type is not None:
            messages[0] = '[%s] %s' % (type, messages[0])

            if indent_on_type:
                for key, message in enumerate(messages[1:]):
                    key = key + 1
                    messages[key] = ' ' * (Helper.len(type) + 1 + 2) + message

        # Wrap and add newlines for each element
        for key, message in enumerate(messages):
            message = Formatter.escape(message)
            wrap_limit = self._line_length - Helper.len(prefix)

            lines += os.linesep.join(textwrap.wrap(message, wrap_limit)).split(os.linesep)

            if messages and key < len(messages) - 1:
                lines.append('')

        if padding and self.is_decorated():
            lines.insert(0, '')
            lines.append('')

        new_lines = []
        for line in lines:
            line = '%s%s' % (prefix, line)
            line += ' ' * (self._line_length - Helper.len_without_decoration(self.get_formatter(), line))
github sdispater / cleo / cleo / helpers / question_helper.py View on Github external
elif isinstance(question, ChoiceQuestion) and question.multiselect:
            choices = question.choices
            default = default.split(',')

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

            message = '{} [{}]:'.format(
                message,
                Formatter.escape(', '.join(default))
            )
        elif isinstance(question, ChoiceQuestion):
            choices = question.choices
            message = '{} [{}]:'.format(
                message,
                Formatter.escape(choices[int(default)])
            )

        if isinstance(question, ChoiceQuestion):
            if len(question.choices) > 1:
                width = max(*map(self.len, [str(k) for k, _ in enumerate(question.choices)]))
            else:
                width = self.len('0')

            messages = [message]
            for key, value in enumerate(question.choices):
                messages.append(' [{:{}}] {}'.format(key, width, value))

            output.writeln(messages)

            message = question.prompt
github sdispater / cleo / cleo / helpers / formatter_helper.py View on Github external
def format_block(self, messages, style, large=False):
        messages = [messages] if not isinstance(messages, (list, tuple)) else messages

        l = 0
        lines = []
        for message in messages:
            message = Formatter.escape(message)
            lines.append(('  %s  ' if large else ' %s ') % message)
            l = max(len(message) + (4 if large else 2), l)

        messages = [' ' * l] if large else []
        for line in lines:
            messages.append(line + ' ' * (l - len(line)))

        if large:
            messages.append(' ' * l)

        messages = map(lambda m: '<%s>%s' % (style, m, style), messages)

        return '\n'.join(messages)