From 160a68a54e6a31bccf4f33b6e5068d131329c4b6 Mon Sep 17 00:00:00 2001 From: Ahmet Sait Date: Sat, 6 Aug 2022 17:38:13 +0300 Subject: [PATCH] Terminal save & restore cursor --- terminal.d | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/terminal.d b/terminal.d index ac0f56d..b43a554 100644 --- a/terminal.d +++ b/terminal.d @@ -1009,6 +1009,46 @@ struct Terminal { else return (tcaps & TerminalCapabilities.arsdClipboard) ? true : false; } + version (Win32Console) + // Mimic sc & rc termcaps on Windows + COORD[] cursorPositionStack; + + bool saveCursorPosition() + { + version (Win32Console) + { + CONSOLE_SCREEN_BUFFER_INFO info; + if (GetConsoleScreenBufferInfo(hConsole, &info)) + { + cursorPositionStack ~= info.dwCursorPosition; // push + return true; + } + else + return false; + } + else + return doTermcap("sc"); + } + + bool restoreCursorPosition() + { + version (Win32Console) + { + if (cursorPositionStack.length > 0) + { + if (SetConsoleCursorPosition(hConsole, cursorPositionStack[$ - 1])) + { + cursorPositionStack = cursorPositionStack[0 .. $ - 1]; // pop + return true; + } + else + return false; + } + } + else + return doTermcap("rc"); + } + // only supported on my custom terminal emulator. guarded behind if(inlineImagesSupported) // though that isn't even 100% accurate but meh void changeWindowIcon()(string filename) {