[hackers] [st][PATCH] Saner cursor handling on altscreen swapping

From: <szunti_AT_gmail.com>
Date: Mon, 28 Jan 2019 13:31:47 +0100

From: Szunti <szunti_AT_gmail.com>

Normal and alternate screen both have 1-1 slots to save a cursor
position.

Old behaviour was putting the normal position in both save slots
on entering altscreen, which is probably not what was intended.

New behaviour is to only save normal position to normal slot.
Altscreen cursor is not saved on swapping, wouldn't make much
sense because altscreen is cleared before reentering.

Altscreen is changed to be cleared when entering the mode instead of
exiting.

Trying to react reasonably when the enter-exit-enter-exit cycle is
broken:
altscreen -> altscreen: clear the screen
  giving a fresh new screen if the last program forgot to exit
normal -> normal: doesn't do anything
  you can use '\e[1049l' in your shell prompt to not be stuck on
  the altscreen
---
 st.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/st.c b/st.c
index b8e6077..296eeb3 100644
--- a/st.c
+++ b/st.c
_AT_@ -1542,24 +1542,24 @@ tsetmode(int priv, int set, int *args, int narg)
 				xsetmode(set, MODE_8BIT);
 				break;
 			case 1049: /* swap screen & set/restore cursor as xterm */
-				if (!allowaltscreen)
-					break;
-				tcursor((set) ? CURSOR_SAVE : CURSOR_LOAD);
-				/* FALLTHROUGH */
 			case 47: /* swap screen */
 			case 1047:
 				if (!allowaltscreen)
 					break;
 				alt = IS_SET(MODE_ALTSCREEN);
+				if (set ^ alt) { /* set is always 1 or 0 */
+					if (*args == 1049 && set) /* normal -> alternate */
+						tcursor(CURSOR_SAVE);
+					tswapscreen();
+					if (*args == 1049 && !set) /* alternate -> normal */
+						tcursor(CURSOR_LOAD);
+				}
+				alt = IS_SET(MODE_ALTSCREEN);
 				if (alt) {
 					tclearregion(0, 0, term.col-1,
 							term.row-1);
 				}
-				if (set ^ alt) /* set is always 1 or 0 */
-					tswapscreen();
-				if (*args != 1049)
-					break;
-				/* FALLTHROUGH */
+				break;
 			case 1048:
 				tcursor((set) ? CURSOR_SAVE : CURSOR_LOAD);
 				break;
-- 
2.20.1
Received on Mon Jan 28 2019 - 13:31:47 CET

This archive was generated by hypermail 2.3.0 : Mon Jan 28 2019 - 13:36:23 CET