Return whether prompt-toolkit should continue prompting the user for a multiline command.
(self)
| 684 | self.current_command: Statement | None = None |
| 685 | |
| 686 | def _should_continue_multiline(self) -> bool: |
| 687 | """Return whether prompt-toolkit should continue prompting the user for a multiline command.""" |
| 688 | buffer: Buffer = get_app().current_buffer |
| 689 | line: str = buffer.text |
| 690 | |
| 691 | used_macros = [] |
| 692 | |
| 693 | # Continue until all macros are resolved |
| 694 | while True: |
| 695 | try: |
| 696 | statement = self._check_statement_complete(line) |
| 697 | except IncompleteStatement: |
| 698 | # The statement (or the resolved macro) is incomplete. |
| 699 | # Keep prompting the user. |
| 700 | return True |
| 701 | |
| 702 | except (Cmd2ShlexError, EmptyStatement): |
| 703 | # These are "finished" states (even if they are errors). |
| 704 | # Submit so the main loop can handle the exception. |
| 705 | return False |
| 706 | |
| 707 | # Check if this command matches a macro and wasn't already processed to avoid an infinite loop |
| 708 | if statement.command in self.macros and statement.command not in used_macros: |
| 709 | used_macros.append(statement.command) |
| 710 | try: |
| 711 | line = self._resolve_macro(statement) |
| 712 | except MacroError: |
| 713 | # Resolve failed. Submit to let the main loop handle the error. |
| 714 | return False |
| 715 | else: |
| 716 | # No macro found or already processed. The statement is complete. |
| 717 | return False |
| 718 | |
| 719 | def _create_main_session(self, auto_suggest: bool, completekey: str) -> PromptSession[str]: |
| 720 | """Create and return the main PromptSession for the application. |