JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Save cursor position in terminal reset
[st.git] / st.c
diff --git a/st.c b/st.c
index 2ad13ef..4a77d71 100644 (file)
--- a/st.c
+++ b/st.c
@@ -96,8 +96,7 @@ enum cursor_movement {
 
 enum cursor_state {
        CURSOR_DEFAULT  = 0,
-       CURSOR_HIDE     = 1,
-       CURSOR_WRAPNEXT = 2
+       CURSOR_WRAPNEXT = 1,
 };
 
 enum glyph_state {
@@ -115,7 +114,8 @@ enum term_mode {
        MODE_MOUSEMOTION = 64,
        MODE_MOUSE       = 32|64,
        MODE_REVERSE     = 128,
-       MODE_KBDLOCK     = 256
+       MODE_KBDLOCK     = 256,
+       MODE_HIDE      = 512
 };
 
 enum escape_state {
@@ -1076,6 +1076,8 @@ treset(void) {
        term.mode = MODE_WRAP;
 
        tclearregion(0, 0, term.col-1, term.row-1);
+       tmoveto(0, 0);
+       tcursor(CURSOR_SAVE);
 }
 
 void
@@ -1464,8 +1466,8 @@ tsetmode(bool priv, bool set, int *args, int narg) {
                        case 0:  /* Error (IGNORED) */
                        case 12: /* att610 -- Start blinking cursor (IGNORED) */
                                break;
-                       case 25:
-                               MODBIT(term.c.state, !set, CURSOR_HIDE);
+                       case 25: /* DECTCEM -- Text Cursor Enable Mode */
+                               MODBIT(term.mode, !set, MODE_HIDE);
                                break;
                        case 1000: /* 1000,1002: enable xterm mouse report */
                                MODBIT(term.mode, set, MODE_MOUSEBTN);
@@ -1475,15 +1477,15 @@ tsetmode(bool priv, bool set, int *args, int narg) {
                                break;
                        case 1049: /* = 1047 and 1048 */
                        case 47:
-                       case 1047:
-                               if(IS_SET(MODE_ALTSCREEN))
+                       case 1047: {
+                               bool alt = IS_SET(MODE_ALTSCREEN) != 0;
+                               if(alt)
                                        tclearregion(0, 0, term.col-1, term.row-1);
-                               if((set && !IS_SET(MODE_ALTSCREEN)) ||
-                                               (!set && IS_SET(MODE_ALTSCREEN))) {
+                               if(set ^ alt)           /* set is always 1 or 0 */
                                        tswapscreen();
-                               }
                                if(*args != 1049)
                                        break;
+                       }
                                /* pass through */
                        case 1048:
                                tcursor((set) ? CURSOR_SAVE : CURSOR_LOAD);
@@ -2505,7 +2507,7 @@ xdrawcursor(void) {
        }
 
        /* draw the new one */
-       if(!(term.c.state & CURSOR_HIDE)) {
+       if(!(IS_SET(MODE_HIDE))) {
                if(!(xw.state & WIN_FOCUSED))
                        g.bg = defaultucs;
 
@@ -2546,9 +2548,9 @@ drawregion(int x1, int y1, int x2, int y2) {
        int ic, ib, x, y, ox, sl;
        Glyph base, new;
        char buf[DRAW_BUF_SIZ];
-       bool ena_sel = sel.bx != -1, alt = IS_SET(MODE_ALTSCREEN);
+       bool ena_sel = sel.bx != -1, alt = IS_SET(MODE_ALTSCREEN) != 0;
 
-       if((sel.alt && !alt) || (!sel.alt && alt))
+       if((sel.alt != 0) ^ alt)
                ena_sel = 0;
        if(!(xw.state & WIN_VISIBLE))
                return;