Explorar o código

Fixes #4236. CursesDriver erase the previous text under the cursor when moving if Force16Colors is true (#4237)

* Fixes #4236. CursesDriver erase the previous text under the cursor when moving if Force16Colors is true

* Still trying to fix fluent unit tests

* Fix nullable issue

---------

Co-authored-by: Tig <[email protected]>
BDisp hai 1 día
pai
achega
02d24bba69

+ 11 - 7
Terminal.Gui/Drivers/CursesDriver/CursesDriver.cs

@@ -536,6 +536,8 @@ internal class CursesDriver : ConsoleDriver
         return true;
     }
 
+    private EscSeqUtils.DECSCUSR_Style? _currentDecscusrStyle;
+
     /// <inheritdoc/>
     public override bool SetCursorVisibility (CursorVisibility visibility)
     {
@@ -547,17 +549,19 @@ internal class CursesDriver : ConsoleDriver
         if (!RunningUnitTests)
         {
             Curses.curs_set (((int)visibility >> 16) & 0x000000FF);
+            Curses.leaveok (_window!.Handle, !Force16Colors);
         }
 
         if (visibility != CursorVisibility.Invisible)
         {
-            _mainLoopDriver?.WriteRaw (
-                                       EscSeqUtils.CSI_SetCursorStyle (
-                                                                       (EscSeqUtils.DECSCUSR_Style)
-                                                                       (((int)visibility >> 24)
-                                                                        & 0xFF)
-                                                                      )
-                                      );
+            if (_currentDecscusrStyle is null || _currentDecscusrStyle != (EscSeqUtils.DECSCUSR_Style)(((int)visibility >> 24) & 0xFF))
+            {
+                _currentDecscusrStyle = (EscSeqUtils.DECSCUSR_Style)(((int)visibility >> 24) & 0xFF);
+
+                _mainLoopDriver?.WriteRaw (
+                                           EscSeqUtils.CSI_SetCursorStyle ((EscSeqUtils.DECSCUSR_Style)_currentDecscusrStyle)
+                                          );
+            }
         }
 
         _currentCursorVisibility = visibility;

+ 1 - 2
Terminal.Gui/Drivers/CursesDriver/UnixMainLoop.cs

@@ -249,8 +249,7 @@ internal class UnixMainLoop : IMainLoopDriver
 
     private class Watch
     {
-        // BUGBUG: Fix this nullable issue.
-        public Func<MainLoop, bool> Callback;
+        public Func<MainLoop, bool>? Callback;
         public Condition Condition;
         public int File;
     }

+ 1 - 1
Terminal.Gui/ViewBase/ViewCollectionHelpers.cs

@@ -10,7 +10,7 @@ internal static class ViewCollectionHelpers
             // The list parameter might be the live `_subviews`, so freeze it under a lock
             lock (list)
             {
-                return [.. list]; // C# 12 slice copy (= new List<View>(list).ToArray())
+                return list.ToArray (); // It’s slightly less “fancy C# 12”, but much safer in multithreaded code
             }
         }