patch 8.2.2754: :sleep! does not always hide the cursor

Problem:    :sleep! does not always hide the cursor.
Solution:   Add the cursor_is_asleep flag. (Jeremy Lerner, closes #8097,
            closes #7998)
diff --git a/src/drawscreen.c b/src/drawscreen.c
index 0e36e79..7df4a96 100644
--- a/src/drawscreen.c
+++ b/src/drawscreen.c
@@ -297,7 +297,9 @@
 		// Remove the cursor before starting to do anything, because
 		// scrolling may make it difficult to redraw the text under
 		// it.
-		if (gui.in_use && wp == curwin)
+		// Also remove the cursor if it needs to be hidden due to an
+		// ongoing cursor-less sleep.
+		if (gui.in_use && (wp == curwin || cursor_is_sleeping()))
 		{
 		    gui_cursor_col = gui.cursor_col;
 		    gui_cursor_row = gui.cursor_row;
@@ -306,7 +308,6 @@
 		}
 	    }
 #endif
-
 	    win_update(wp);
 	}
 
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index c8cb11b..7c1c448 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -7370,7 +7370,7 @@
 # endif
 
     if (hide_cursor)
-        cursor_off();
+        cursor_sleep();
     else
         cursor_on();
 
@@ -7422,6 +7422,9 @@
     // input buffer, otherwise a following call to input() fails.
     if (got_int)
 	(void)vpeekc();
+
+    if (hide_cursor)
+        cursor_unsleep();
 }
 
 /*
diff --git a/src/gui.c b/src/gui.c
index 0265f7c..c0374c5 100644
--- a/src/gui.c
+++ b/src/gui.c
@@ -1120,6 +1120,11 @@
 		    || gui.row != gui.cursor_row || gui.col != gui.cursor_col)
     {
 	gui_undraw_cursor();
+
+	// If a cursor-less sleep is ongoing, leave the cursor invisible
+	if (cursor_is_sleeping())
+	    return;
+
 	if (gui.row < 0)
 	    return;
 #ifdef HAVE_INPUT_METHOD
diff --git a/src/proto/term.pro b/src/proto/term.pro
index 1b37802..efb2555 100644
--- a/src/proto/term.pro
+++ b/src/proto/term.pro
@@ -56,6 +56,9 @@
 void cursor_on_force(void);
 void cursor_on(void);
 void cursor_off(void);
+int cursor_is_sleeping(void);
+void cursor_sleep(void);
+void cursor_unsleep(void);
 void term_cursor_mode(int forced);
 void term_cursor_color(char_u *color);
 int blink_state_is_inverted(void);
diff --git a/src/term.c b/src/term.c
index ad52d1b..0a4e5b7 100644
--- a/src/term.c
+++ b/src/term.c
@@ -3932,8 +3932,12 @@
     }
 }
 
+// True if cursor is not visible
 static int cursor_is_off = FALSE;
 
+// True if cursor is not visible due to an ongoing cursor-less sleep
+static int cursor_is_asleep = FALSE;
+
 /*
  * Enable the cursor without checking if it's already enabled.
  */
@@ -3942,6 +3946,7 @@
 {
     out_str(T_VE);
     cursor_is_off = FALSE;
+    cursor_is_asleep = FALSE;
 }
 
 /*
@@ -3950,7 +3955,7 @@
     void
 cursor_on(void)
 {
-    if (cursor_is_off)
+    if (cursor_is_off && !cursor_is_asleep)
 	cursor_on_force();
 }
 
@@ -3967,6 +3972,35 @@
     }
 }
 
+/*
+ * Check whether the cursor is invisible due to an ongoing cursor-less sleep
+ */
+    int
+cursor_is_sleeping(void)
+{
+    return cursor_is_asleep;
+}
+
+/*
+ * Disable the cursor and mark it disabled by cursor-less sleep
+ */
+    void
+cursor_sleep(void)
+{
+    cursor_is_asleep = TRUE;
+    cursor_off();
+}
+
+/*
+ * Enable the cursor and mark it not disabled by cursor-less sleep
+ */
+    void
+cursor_unsleep(void)
+{
+    cursor_is_asleep = FALSE;
+    cursor_on();
+}
+
 #if defined(CURSOR_SHAPE) || defined(PROTO)
 /*
  * Set cursor shape to match Insert or Replace mode.
diff --git a/src/version.c b/src/version.c
index c760738..d18c0f8 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2754,
+/**/
     2753,
 /**/
     2752,