gh-140131: Fix REPL cursor position on Windows when module completion suggestion line hits console width #140333
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When pressing TAB, the cursor moves to the end of the last printed autocomplete suggestion line, then should reposition back to where TAB was pressed. This repositioning fails when the last suggestion line's length equals the console width.
For example: The cursor starts at
(column 12, row 0)
when TAB is pressed. There are 3 suggestion lines, and the last one reaches the console width. The cursor moves to(column 80, row 3)
. When _move_relative(0, y+1) is called, the cursor should go to(column 0, row 4)
but doesn’t—yet Python thinks it succeeded. When repositioning back, the cursor is supposed to move right from column 0 to 12, but it actually moves right from column 80, ending up far right._move_relative(0, y+1)
doesn't trigger wrapping. Adding aself.__write('\r\n')
ensures the cursor wraps to the new line correctly.Here is the demo (modified from https://github.com/microsoft/terminal/issues/349#issue-399157942) showing the failed wrapping with the same constrol sequence used by `_move_relative()` for cursor movement:
```cpp #include #include #includeusing std::string;
using std::cout;
using std::endl;
int main()
{
HANDLE stdOut = GetStdHandle(STD_OUTPUT_HANDLE);
}
..............................................................................x
console width: 79
cursor row before moving down: 25
cursor row after moving down: 25