Skip to content

Commit

Permalink
Maximus5gh-1615: Workaroung for Win10 insider cursor position bug aft…
Browse files Browse the repository at this point in the history
…er writing `\b \b` to console.
  • Loading branch information
Maximus5 committed Jun 26, 2018
1 parent c0d4392 commit e971b80
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions src/ConEmuHk/ExtConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ BOOL ExtWriteText(ExtWriteTextParm* Info)
#endif

bool bAutoLfNl = ((Info->Flags & ewtf_NoLfNl) == 0);
bool bNonAutoLfNl = false;
bool bIntCursorOp = false;

const wchar_t *pCur = pFrom;
SHORT x = csbi.dwCursorPosition.X, y = csbi.dwCursorPosition.Y; // 0-based
Expand Down Expand Up @@ -1152,6 +1152,7 @@ BOOL ExtWriteText(ExtWriteTextParm* Info)
bool BSRN = false;
bool bForceDumpScroll = false;
bool bSkipBELL = false;
bool bAdvanceCur = false;

WARNING("Refactoring required: use an object to cache symbols and write them on request");

Expand All @@ -1162,13 +1163,13 @@ BOOL ExtWriteText(ExtWriteTextParm* Info)
if (x2>x)
ForceDumpX = x2;
x2 = ((x2 + 8) >> 3) << 3;
BSRN = true; bNonAutoLfNl = true;
BSRN = true; bIntCursorOp = true;
break;
case L'\r':
if (x2 > 0)
ForceDumpX = x2-1;
x2 = 0;
bNonAutoLfNl = false;
bIntCursorOp = false;
BSRN = true;
// "\r\n"? Do not break in two physical writes
if (((pCur+1) < pEnd) && (*(pCur+1) == L'\n'))
Expand All @@ -1181,7 +1182,7 @@ BOOL ExtWriteText(ExtWriteTextParm* Info)
if (bAutoLfNl)
x2 = 0;
else if (x2)
bNonAutoLfNl = true;
bIntCursorOp = true;
y2++;
if (y2 >= ScrollBottom)
bForceDumpScroll = true;
Expand All @@ -1195,20 +1196,23 @@ BOOL ExtWriteText(ExtWriteTextParm* Info)
{
LogBeepSkip(L"--- Skipped ExtWriteText(7)\n");
bForceDumpScroll = bSkipBELL = true;
pCur--;
bAdvanceCur = true; --pCur;
}
else
{
LogBeepSkip(L"--- ExtWriteText(7)\n");
}
break;
case 8:
case 8: // L'\b'
//BS
if (x2>x)
ForceDumpX = x2;
if (x2>0)
x2--;
BSRN = true;
bIntCursorOp = true;
// Don't pass '\b' to WriteText (problem in Win10 build)
bAdvanceCur = true; --pCur;
break;
default:
// Просто буква.
Expand All @@ -1232,9 +1236,13 @@ BOOL ExtWriteText(ExtWriteTextParm* Info)
(pTrueColorStart && (nLinePosition >= 0)) ? (pTrueColorStart + nLinePosition) : NULL,
(pTrueColorEnd), AIColor, csbi, (WriteConsoleW_t)Info->Private);

if (bAdvanceCur)
{
++pCur;
bAdvanceCur = false;
}
if (bSkipBELL)
{
pCur++;
// User may disable flashing in ConEmu settings
GuiFlashWindow(eFlashBeep, ghConWnd, FALSE, FLASHW_ALL, 1, 0);
}
Expand All @@ -1245,6 +1253,12 @@ BOOL ExtWriteText(ExtWriteTextParm* Info)
else
{
_ASSERTE(!bSkipBELL);

if (bAdvanceCur)
{
++pCur;
bAdvanceCur = false;
}
}

// После BS - сменить "начальную" координату
Expand Down Expand Up @@ -1289,7 +1303,7 @@ BOOL ExtWriteText(ExtWriteTextParm* Info)

SetConsoleCursorPosition(Info->ConsoleOutput, crScrollCursor);

bNonAutoLfNl = false; // already processed
bIntCursorOp = false; // already processed
}
else
{
Expand All @@ -1305,12 +1319,15 @@ BOOL ExtWriteText(ExtWriteTextParm* Info)
y = y2;
}

// xterm-compatible '\n': just move cursor downward, don't do CR
if (bNonAutoLfNl)
// xterm-compatible
// '\n': just move cursor downward, don't do CR
// '\t': move cursor to x8 position, don't erase any cells
// '\b': move cursor backward by one cell, don't erase cell, don't move cursor upward
if (bIntCursorOp)
{
_ASSERTE(x2>0);
_ASSERTE(pCur < pEnd && (*pCur == L'\n' || *pCur == L'\t') && (pFrom == pCur || pFrom == pCur+1));
bNonAutoLfNl = false;
_ASSERTE(pCur < pEnd && (*pCur == L'\n' || *pCur == L'\t' || *pCur == L'\b') && (pFrom == pCur || pFrom == pCur+1));
bIntCursorOp = false;
crScrollCursor.X = x2;
crScrollCursor.Y = y2;
SetConsoleCursorPosition(Info->ConsoleOutput, crScrollCursor);
Expand All @@ -1320,7 +1337,7 @@ BOOL ExtWriteText(ExtWriteTextParm* Info)

if (pCur > pFrom)
{
_ASSERTE(!bNonAutoLfNl && "bNonAutoLfNl must be processed already");
_ASSERTE(bIntCursorOp==false && "must be processed already");

// Printing (NOT including pCur) using extended attributes
SHORT ForceDumpX = (x2 > x) ? (std::min(x2, WrapAtCol)-1) : -1;
Expand Down

0 comments on commit e971b80

Please sign in to comment.