| 805 | |
| 806 | @restore_multiline |
| 807 | def confirm_ask( |
| 808 | self, |
| 809 | question, |
| 810 | default="y", |
| 811 | subject=None, |
| 812 | explicit_yes_required=False, |
| 813 | group=None, |
| 814 | allow_never=False, |
| 815 | ): |
| 816 | self.num_user_asks += 1 |
| 817 | |
| 818 | # Ring the bell if needed |
| 819 | self.ring_bell() |
| 820 | |
| 821 | question_id = (question, subject) |
| 822 | |
| 823 | if question_id in self.never_prompts: |
| 824 | return False |
| 825 | |
| 826 | if group and not group.show_group: |
| 827 | group = None |
| 828 | if group: |
| 829 | allow_never = True |
| 830 | |
| 831 | valid_responses = ["yes", "no", "skip", "all"] |
| 832 | options = " (Y)es/(N)o" |
| 833 | if group: |
| 834 | if not explicit_yes_required: |
| 835 | options += "/(A)ll" |
| 836 | options += "/(S)kip all" |
| 837 | if allow_never: |
| 838 | options += "/(D)on't ask again" |
| 839 | valid_responses.append("don't") |
| 840 | |
| 841 | if default.lower().startswith("y"): |
| 842 | question += options + " [Yes]: " |
| 843 | elif default.lower().startswith("n"): |
| 844 | question += options + " [No]: " |
| 845 | else: |
| 846 | question += options + f" [{default}]: " |
| 847 | |
| 848 | if subject: |
| 849 | self.tool_output() |
| 850 | if "\n" in subject: |
| 851 | lines = subject.splitlines() |
| 852 | max_length = max(len(line) for line in lines) |
| 853 | padded_lines = [line.ljust(max_length) for line in lines] |
| 854 | padded_subject = "\n".join(padded_lines) |
| 855 | self.tool_output(padded_subject, bold=True) |
| 856 | else: |
| 857 | self.tool_output(subject, bold=True) |
| 858 | |
| 859 | style = self._get_style() |
| 860 | |
| 861 | def is_valid_response(text): |
| 862 | if not text: |
| 863 | return True |
| 864 | return text.lower() in valid_responses |