Skip to content

Conversation

tanloong
Copy link
Contributor

@tanloong tanloong commented Oct 19, 2025

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 a self.__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 #include

using std::string;
using std::cout;
using std::endl;

int main()
{
HANDLE stdOut = GetStdHandle(STD_OUTPUT_HANDLE);

DWORD consoleMode =
    ENABLE_PROCESSED_OUTPUT |
    ENABLE_WRAP_AT_EOL_OUTPUT |
    ENABLE_VIRTUAL_TERMINAL_PROCESSING;

SetConsoleMode(stdOut, consoleMode);

CONSOLE_SCREEN_BUFFER_INFO screenBufferInfo;
GetConsoleScreenBufferInfo(stdOut, &screenBufferInfo);

SHORT length = screenBufferInfo.dwSize.X;
string str(length - 1, '.');
cout << str;
cout << "x";

GetConsoleScreenBufferInfo(stdOut, &screenBufferInfo);
SHORT row1 = screenBufferInfo.dwCursorPosition.Y;

cout << "\x1b[B"; // MOVE_DOWN to the next line

GetConsoleScreenBufferInfo(stdOut, &screenBufferInfo);
SHORT row2 = screenBufferInfo.dwCursorPosition.Y;

cout << endl
  << "console width: " << length << endl
  << "cursor row before moving down: " <<  row1 << endl
  << "cursor row after moving down: " << row2  << endl;

}


..............................................................................x
console width: 79
cursor row before moving down: 25
cursor row after moving down: 25

</details>

@tanloong tanloong marked this pull request as ready for review October 20, 2025 14:32
@tanloong tanloong marked this pull request as draft October 20, 2025 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant