Read command with support for line continuation using backslash.
(prompt_session, params)
| 833 | |
| 834 | |
| 835 | def read_command_with_continuation(prompt_session, params): |
| 836 | """Read command with support for line continuation using backslash.""" |
| 837 | command_lines = [] |
| 838 | continuation_prompt = "... " |
| 839 | current_prompt = get_prompt(params) |
| 840 | |
| 841 | while True: |
| 842 | if prompt_session is not None: |
| 843 | line = prompt_session.prompt(current_prompt) |
| 844 | else: |
| 845 | line = input(current_prompt) |
| 846 | |
| 847 | # Check if line ends with backslash (line continuation) |
| 848 | # First strip all trailing whitespace, then check for backslash |
| 849 | stripped_line = line.rstrip() |
| 850 | if stripped_line.endswith('\\'): |
| 851 | # Remove the backslash and any remaining whitespace |
| 852 | line_content = stripped_line[:-1].strip() |
| 853 | if line_content: # Only add non-empty lines |
| 854 | command_lines.append(line_content) |
| 855 | current_prompt = continuation_prompt |
| 856 | else: |
| 857 | # No continuation, add the final line if it has content |
| 858 | line_content = stripped_line |
| 859 | if line_content: |
| 860 | command_lines.append(line_content) |
| 861 | break |
| 862 | |
| 863 | # Join all lines with spaces, ensuring no extra spaces |
| 864 | # Also clean up any multiple spaces that might have been introduced |
| 865 | result = ' '.join(command_lines) |
| 866 | # Replace multiple spaces with single spaces to handle any remaining formatting issues |
| 867 | import re |
| 868 | result = re.sub(r'\s+', ' ', result).strip() |
| 869 | return result |
| 870 | |
| 871 | |
| 872 | def loop(params, skip_init=False, suppress_goodbye=False, new_login=False): # type: (KeeperParams, bool, bool, bool) -> int # suppress_goodbye kept for API compat |