]> granicus.if.org Git - nethack/commitdiff
revisit display artifact appearing to the right of status line
authornhmall <nhmall@nethack.org>
Sun, 30 Sep 2018 02:28:10 +0000 (22:28 -0400)
committernhmall <nhmall@nethack.org>
Sun, 30 Sep 2018 02:28:10 +0000 (22:28 -0400)
The prior fix for this was a bit flawed. It was only considering
the length of the last field, but what it really needed to do was
consider the placement of the last character of the last field
on the row relative to the placement of the last character of
the last field on the row previously.

If the new placement of that last character of the last field
is left of the previous placement, some clearing must be done.

doc/fixes36.2
include/wintty.h
win/tty/wintty.c

index a56ab4b9f2430634aa64364f7ed46339a65b3234..25fd65dc4b166986811479decc89249614516c14 100644 (file)
@@ -168,8 +168,9 @@ tty: turn off an optimization that is the suspected cause of Windows reported
 tty: ensure that current status fields are always copied to prior status
        values so that comparisons are correct
 tty: fix an out of bounds error in tty_status_update() for BL_HUNGER case
-tty: fix leftover display artifact when last field on the row got smaller
-       and optimize so only the right-most field requires the cleanup code
+tty: fix leftover display artifact when the last field on the row got placed
+       to the left of where it was previously due to it, or one of the fields
+       to its left, getting shorter
 X11: its use of genl_status_update exposed a negative index use that could
        lead to a segfault
 
index 9a375145e834c0d0d19e186d38c09c515b4c5203..009baf69ced486a94a3e11b8075bfa86b3cd77a2 100644 (file)
@@ -75,11 +75,11 @@ struct tty_status_fields {
     int color;
     int attr;
     int x, y;
+    int padright;
     size_t lth;
     boolean valid;
     boolean dirty;
     boolean redraw;
-    boolean padright;
 };
 #endif
 
index 145a535fe4403ad94398467d43468690961acbb7..f235f6c9107d07fc82c9f3e63989b5b6c8903ee5 100644 (file)
@@ -3588,7 +3588,7 @@ tty_status_init()
         tty_status[NOW][i].valid  = FALSE;
         tty_status[NOW][i].dirty  = FALSE;
         tty_status[NOW][i].redraw = FALSE;
-        tty_status[NOW][i].padright = FALSE;
+        tty_status[NOW][i].padright = 0;
         tty_status[BEFORE][i] = tty_status[NOW][i];
     }
     tty_condition_bits = 0L;
@@ -3883,11 +3883,17 @@ int *topsz, *bottomsz;
 
             /* On a change to the field length, everything 
                further to the right must be updated as well */
-            if (tty_status[NOW][idx].lth != tty_status[BEFORE][idx].lth) {
+            if (tty_status[NOW][idx].lth != tty_status[BEFORE][idx].lth)
                 update_right = TRUE;
-                if ((tty_status[NOW][idx].lth < tty_status[BEFORE][idx].lth) &&
-                        idx == last_on_row[row])
-                    tty_status[NOW][idx].padright = TRUE;
+
+            if (idx == last_on_row[row]) {
+                int prevright = tty_status[BEFORE][idx].x
+                                + tty_status[BEFORE][idx].lth,
+                    currright = tty_status[NOW][idx].x
+                                + tty_status[NOW][idx].lth;
+
+                    if (currright < prevright)
+                        tty_status[NOW][idx].padright = prevright - currright;
             }
 
             if (!update_right && !forcefields) {
@@ -4339,10 +4345,11 @@ render_status(VOID_ARGS)
                             term_end_color();
                         End_Attr(attridx);
                     }
-                    if (tty_status[NOW][fldidx].padright) {
-                        int cnt = tty_status[BEFORE][fldidx].lth
-                                     - tty_status[NOW][fldidx].lth;
+                    if (tty_status[NOW][fldidx].padright > 0) {
+                        int cnt = tty_status[NOW][fldidx].padright;
 
+                        /* .lth - 1 below because we already did the leading
+                           blank above */
                         x += (tty_status[NOW][fldidx].lth - 1);
                         while (cnt-- > 0)
                             tty_putstatusfield(nullfield, " ", x++, y);
@@ -4352,7 +4359,7 @@ render_status(VOID_ARGS)
             /* reset .redraw, .dirty, .padright now that they've been rendered */
             tty_status[NOW][fldidx].dirty  = FALSE;
             tty_status[NOW][fldidx].redraw = FALSE;
-            tty_status[NOW][fldidx].padright = FALSE;
+            tty_status[NOW][fldidx].padright = 0;
 
             /*
              * Make a copy of the entire tty_status struct for comparison