watch in procps-ng 4.0.6 does not handle terminal resize correctly

Starting with procps-ng 4.0.6, watch does not let the inner command occupy the entire terminal after it has been resized upwards. Conversely, if the terminal is resized downwards, the output becomes garbled as if due to partial redraw over old contents.

Bisected to:

d9c96ec0454206ebaf892184516b08de4004844c is the first bad commit
commit d9c96ec0454206ebaf892184516b08de4004844c
Author: Craig Small <csmall@dropbear.xyz>
Date:   Tue Apr 15 19:04:31 2025 +1000

    watch: Add --follow option

    Sometimes you want to keep the output from watch on the screen instead
    of clearing each command run. The --follow option will scroll the
    output window continuosly.  Any option that needs to know what
    is printed doesn't work with it so watch prints an error if
    you try.
    watch now is two windows in a screen; a 2 row header and a
    remainder for the output.

    Signed-off-by: Craig Small <csmall@dropbear.xyz>

 NEWS        |   1 +
 man/watch.1 |  10 ++++++--
 src/watch.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------
 3 files changed, 109 insertions(+), 56 deletions(-)

Demo (4.0.6)

  • observe how first watch chronyc ... does not let chronyc (nor its own header!) occupy available space when watch was started in a narrow terminal and subsequently resized to extend width
  • observe how the second watch sensors ... becomes entirely garbled when watch is started in a tall terminal and subsequently resized to reduce height

Demo (4.0.5)

  • both cases working correctly

Edited by Ivan Shapovalov