save/restore fixes

This commit is contained in:
Adam D. Ruppe 2022-08-06 10:59:23 -04:00
parent 5896009a7a
commit 053f2bd77a
1 changed files with 19 additions and 7 deletions

View File

@ -1013,10 +1013,17 @@ struct Terminal {
// Mimic sc & rc termcaps on Windows
COORD[] cursorPositionStack;
/++
Saves/restores cursor position to a stack.
History:
Added August 6, 2022 (dub v10.9)
+/
bool saveCursorPosition()
{
version (Win32Console)
{
flush();
CONSOLE_SCREEN_BUFFER_INFO info;
if (GetConsoleScreenBufferInfo(hConsole, &info))
{
@ -1024,29 +1031,34 @@ struct Terminal {
return true;
}
else
{
return false;
}
}
else
return doTermcap("sc");
}
/// ditto
bool restoreCursorPosition()
{
version (Win32Console)
{
if (cursorPositionStack.length > 0)
{
if (SetConsoleCursorPosition(hConsole, cursorPositionStack[$ - 1]))
{
cursorPositionStack = cursorPositionStack[0 .. $ - 1]; // pop
return true;
}
else
return false;
auto p = cursorPositionStack[$ - 1];
moveTo(p.X, p.Y);
cursorPositionStack = cursorPositionStack[0 .. $ - 1]; // pop
return true;
}
else
return false;
}
else
{
// FIXME: needs to update cursorX and cursorY
return doTermcap("rc");
}
}
// only supported on my custom terminal emulator. guarded behind if(inlineImagesSupported)