JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
People, learn to keep to styles. Thanks.
[st.git] / st.c
diff --git a/st.c b/st.c
index 05e285c..84f9abb 100644 (file)
--- a/st.c
+++ b/st.c
@@ -1342,13 +1342,14 @@ tfulldirt(void) {
 
 void
 tcursor(int mode) {
-       static TCursor c;
+       static TCursor c[2];
+       bool alt = IS_SET(MODE_ALTSCREEN);
 
        if(mode == CURSOR_SAVE) {
-               c = term.c;
+               c[alt] = term.c;
        } else if(mode == CURSOR_LOAD) {
-               term.c = c;
-               tmoveto(c.x, c.y);
+               term.c = c[alt];
+               tmoveto(c[alt].x, c[alt].y);
        }
 }
 
@@ -1854,12 +1855,12 @@ tsetmode(bool priv, bool set, int *args, int narg) {
                        case 1034:
                                MODBIT(term.mode, set, MODE_8BIT);
                                break;
-                       case 1049: /* = 1047 and 1048 */
-                       case 47:
+                       case 1049: /* swap screen & set/restore cursor as xterm */
+                               tcursor((set) ? CURSOR_SAVE : CURSOR_LOAD);
+                       case 47: /* swap screen */
                        case 1047:
                                if (!allowaltscreen)
                                        break;
-
                                alt = IS_SET(MODE_ALTSCREEN);
                                if(alt) {
                                        tclearregion(0, 0, term.col-1,
@@ -1919,6 +1920,9 @@ tsetmode(bool priv, bool set, int *args, int narg) {
 
 void
 csihandle(void) {
+       char buf[40];
+       int len;
+
        switch(csiescseq.mode) {
        default:
        unknown:
@@ -2069,8 +2073,8 @@ csihandle(void) {
                break;
        case 'n': /* DSR – Device Status Report (cursor position) */
                if (csiescseq.arg[0] == 6) {
-                       char buf[40];
-                       int len = snprintf(buf, sizeof(buf),"\033[%i;%iR", term.c.y+1, term.c.x+1);
+                       len = snprintf(buf, sizeof(buf),"\033[%i;%iR",
+                                       term.c.y+1, term.c.x+1);
                        ttywrite(buf, len);
                        break;
                }