Skip to content

Commit

Permalink
Fix line wrapping in patch_stdout on Windows.
Browse files Browse the repository at this point in the history
Enable autowrap before writing data to the output in `patch_stdout`. We
enable/disable VT terminal processing during every `flush()` of the Windows
Output implementation, but it turns out that this causes the autowrap flag to
be reset each time. Because of this, we have to enable autowrap each time
before writing.
  • Loading branch information
jonathanslenders committed Dec 8, 2023
1 parent 857af14 commit 55cde3e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/prompt_toolkit/patch_stdout.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ def _write_and_flush(
"""

def write_and_flush() -> None:
# Ensure that autowrap is enabled before calling `write`.
# XXX: On Windows, the `Windows10_Output` enables/disables VT
# terminal processing for every flush. It turns out that this
# causes autowrap to be reset (disabled) after each flush. So,
# we have to enable it again before writing text.
self._output.enable_autowrap()

if self.raw:
self._output.write_raw(text)
else:
Expand Down

0 comments on commit 55cde3e

Please sign in to comment.