The problem is more complicated than suggested. Start with the script:
tput smcup
clear
dialog --yesno "Do you want to continue?" 0 0
rc=$?
clear
tput rmcup
if [ "${rc}" == "0" ]; then
echo Yes
else
echo No
fi
There is only one alternate screen (and you cannot treat it like a stack). The tput smcup
(technically "start cursor-addressing mode") is often used with xterm and look-alikes to switch to the alternate screen. There is actually more than one control sequence implemented in xterm for this purpose (see Why doesn't the screen clear when running vi?), and some are not recognized by the look-alikes. In one of the comments, MobaXterm is said to be the actual terminal in this case. That is based on (uses code from) PuTTY, which happens to handle the 1049 code in MobaXterm's terminfo.
So...
- the script switches to the alternate screen
- it clears that (again: xterm clears the alternate screen on the previous step)
- it runs dialog, still using the alternate screen.
- when dialog exits, it sends the
rmcup
sequence, switching back into the normal screen, whose content will be the same as before the script began
- then the screen is cleared. Normally that causes the cursor to be moved to the upper left of the screen and then cleared, but (see below)
- finally,
tput rmcup
is used. That asks the terminal emulator to switch back from the alternate screen.
Since the terminal is already in normal mode, that last line could be interpreted in one of (at least) two ways:
- it could be ignored
- some part of the operations performed in the switch from alternate to normal mode might be executed.
In this case, it seems that the latter: part is performed. PuTTY (and in a quick check, xterm) restore the cursor position from the first use of tput smcup
, because the prompt is in the middle of the screen (rather than at the top, where clear
would leave it). OP noticed a gap because there were several commands already done in that window before running the script—the cursor returns to the original position, but the commands are gone because of the clear
before the tput rmcup
.
dialog
, terminal, what command you run with --keep-tite and what happens then... so people don't have to look through all the comments to get the full picture. – Stéphane Chazelas Mar 14 '13 at 20:31