Maximus5 / ConEmu

Customizable Windows terminal with tabs, splits, quake-style, hotkeys and more
https://conemu.github.io/
BSD 3-Clause "New" or "Revised" License
8.57k stars 573 forks source link

Writing into the rightmost column does not work as expected #2506

Open alabuzhev opened 1 year ago

alabuzhev commented 1 year ago

Versions

ConEmu build: master x64 OS version: Windows 10 x64 Used shell version (Far Manager, git-bash, cmd, powershell, cygwin, whatever): Far

Problem description

It looks like Conemu's VT engine manually reimplements DISABLE_NEWLINE_AUTO_RETURN to support older OSes:

The written character will be printed in the final position on the line and the cursor will remain above this character as if ENABLE_WRAP_AT_EOL_OUTPUT was off, but the next printable character will be printed as if ENABLE_WRAP_AT_EOL_OUTPUT is on. No overwrite will occur.

Conemu implements this as described. The problem is, the description does not mention one important exception: any cursor movements, even into the same coordinates, shoud discard this state and the next write should still not move the cursor to the next line, as if the first one never happened. Windows (conhost, WT) does this, but Conemu does not, which leads to the issue in Far described here.

Steps to reproduce

  1. Get the latest Far
  2. Run it from Conemu with hooks enabled, but without extendedconsole.dll (important, see also #2507)
  3. Enable VT rendering and disable cleartype-friendly redraw in interface settings
  4. Wait until the clock updates

Alternatively, the issue can be reproduced with the following simple code:

#include <windows.h>

int main()
{
    const auto h = GetStdHandle(STD_OUTPUT_HANDLE);

    DWORD Mode;
    GetConsoleMode(h, &Mode);
    SetConsoleMode(h, Mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);

    CONSOLE_SCREEN_BUFFER_INFO bi;
    GetConsoleScreenBufferInfo(h, &bi);

    for (size_t i = 0; ; ++i)
    {
        SetConsoleCursorPosition(h, { static_cast<short>(bi.dwSize.X - 1), 0 });

        wchar_t text = '0' + i % 10;
        DWORD n;
        WriteConsoleW(h, &text, 1, &n, {});

        Sleep(500);
    }
}

Expected results

Cursor movements should discard the special state. All writes should stay in the top right corner.

Actual results

The special state is not discarded. Conemu inserts extra \r\n when it should not, breaking the output (by the way, \r\n is probably excessive, \n should do). The character is written on the next line instead.