Exemplo n.º 1
0
    def ask_and_confirm(self, additional_readonly_items: List = None,
                        prepend_listpacking_items: bool = True) -> Union[Dict, None]:
        confirm_question = Question('Are these answers correct? ' +
                                    '[yes/abort/retry]', value='confirm',
                                    validator=CompactListValidator(
                                        choices=['yes', 'abort', 'retry']))

        while True:
            answers = self.ask()
            lp = ListPack(
                [(q.printable_name, answers[q.value]) for q in self.questions])

            # add in items that were not asked as questions but should be
            # displayed alongside that information
            if additional_readonly_items:
                if prepend_listpacking_items:
                    for item in additional_readonly_items:
                        lp.prepend_item(item)
                else:
                    for item in additional_readonly_items:
                        lp.append_item(item)

            print(lp)
            confirm_answer = confirm_question.ask()
            if confirm_answer['confirm'] == 'yes':
                return answers
            if confirm_answer['confirm'] != 'retry':
                return None
Exemplo n.º 2
0
    def ask_and_confirm(self, additional_readonly_items=None,
                        prepend_listpacking_items=True):
        confirm_question = Question('Are these answers correct? ' +
                                    '[yes/abort/retry]', value='confirm',
                                    validator=CompactListValidator(
                                        choices=['yes', 'abort', 'retry']))

        while True:
            answers = self.ask()
            lp = ListPack(map(lambda q: (q.printable_name, answers[q.value]),
                              self.questions))

            # add in items that were not asked as questions but should be
            # displayed alongside that information
            if additional_readonly_items:
                if prepend_listpacking_items:
                    for item in additional_readonly_items:
                        lp.prepend_item(item)
                else:
                    for item in additional_readonly_items:
                        lp.append_item(item)

            print lp
            confirm_answer = confirm_question.ask()
            if confirm_answer['confirm'] == 'yes':
                return answers
            if confirm_answer['confirm'] != 'retry':
                return None
Exemplo n.º 3
0
 def test_append_item(self):
     lp = ListPack([('a', 'b')])
     lp.append_item(('c', 'd'))
     assert str(lp) == '\n\x1b[1ma\x1b[0m: b  \x1b[1mc\x1b[0m: d  '