From 4e2f72ea7d644a6460f26a14bdd201296ab40789 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Fri, 13 May 2022 15:21:18 -0700 Subject: [PATCH] On Windows, reset cursor visibility back to previous state when rendering progress (#16782) * On Windows, reset cursor visibility back to previous state when rendering progress * Update src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressPane.cs Co-authored-by: Ilya Co-authored-by: Ilya --- .../host/msh/ProgressPane.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressPane.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressPane.cs index a3be724b7c..404477fa6a 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressPane.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressPane.cs @@ -301,7 +301,17 @@ namespace Microsoft.PowerShell { if (_content is not null) { + // On Windows, we can check if the cursor is currently visible and not change it to visible + // if it is intentionally hidden. On Unix, it is not currently supported to read the cursor visibility. +#if UNIX Console.CursorVisible = false; +#else + bool currentCursorVisible = Console.CursorVisible; + if (currentCursorVisible) + { + Console.CursorVisible = false; + } +#endif var currentPosition = _rawui.CursorPosition; _rawui.CursorPosition = _location; @@ -319,7 +329,11 @@ namespace Microsoft.PowerShell } _rawui.CursorPosition = currentPosition; +#if UNIX Console.CursorVisible = true; +#else + Console.CursorVisible = currentCursorVisible; +#endif } }