From 053f2bd77a0897b3b2107dc9c327d3769089d850 Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Sat, 6 Aug 2022 10:59:23 -0400 Subject: [PATCH] save/restore fixes --- terminal.d | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/terminal.d b/terminal.d index b43a554..bc7a1b8 100644 --- a/terminal.d +++ b/terminal.d @@ -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)