Call a prompt function, passing the full prompt on non-Windows so readline can handle line editing and cursor positioning correctly. On Windows the prompt is written separately via :func:`echo` for colorama support, with only the last character passed to *func*.
(func: t.Callable[[str], str], text: str, err: bool)
| 82 | |
| 83 | |
| 84 | def _readline_prompt(func: t.Callable[[str], str], text: str, err: bool) -> str: |
| 85 | """Call a prompt function, passing the full prompt on non-Windows so |
| 86 | readline can handle line editing and cursor positioning correctly. |
| 87 | |
| 88 | On Windows the prompt is written separately via :func:`echo` for |
| 89 | colorama support, with only the last character passed to *func*. |
| 90 | """ |
| 91 | if WIN: |
| 92 | # Write the prompt separately so that we get nice coloring |
| 93 | # through colorama on Windows. |
| 94 | echo(text[:-1], nl=False, err=err) |
| 95 | # Echo the last character to stdout to work around an issue |
| 96 | # where readline causes backspace to clear the whole line. |
| 97 | return func(text[-1:]) |
| 98 | if err: |
| 99 | with redirect_stdout(sys.stderr): |
| 100 | return func(text) |
| 101 | return func(text) |
| 102 | |
| 103 | |
| 104 | def _build_prompt( |
no test coverage detected
searching dependent graphs…