aha icon indicating copy to clipboard operation
aha copied to clipboard

Feature request: Ignore xterm alternate screen

Open iskunk opened this issue 2 years ago • 0 comments

When I record terminal sessions using script(1), on occasion a full-screen ncurses-style dialog will pop up. This results in a big mess in the recorded session, with a large number of escapes for colors, cursor positioning, etc. However, none of that needs to be reflected in the final output, if all you want to see is the normal terminal buffer.

This file is a simple example. It is a terminal session recorded with script(1), in which I invoke a command dpkg-reconfigure tzdata that pops up an ncurses dialog. You can see the mess of escapes in the file, after the command is entered. I even navigated around the dialog a bit, just to make the mess even worse.

However, once I exit the dialog, the terminal looks like this:

root@xubuntu:/tmp# script typescript-dialog.txt 
Script started, output log file is 'typescript-dialog.txt'.
root@xubuntu:/tmp# 
root@xubuntu:/tmp# dpkg-reconfigure tzdata

Current default time zone: 'Etc/UTC'
Local time is now:      Mon Mar 21 17:21:29 UTC 2022.
Universal Time is now:  Mon Mar 21 17:21:29 UTC 2022.

root@xubuntu:/tmp# 
root@xubuntu:/tmp# 
exit
Script done.
root@xubuntu:/tmp# 

The dialog screens are no longer present in the terminal buffer, even if I scroll up. That is because the entire dialog interaction took place in the terminal's "alternative screen buffer," which is separate from the normal buffer. The normal buffer is what I would want to see in the final HTML output.

As documented here, the alternative screen buffer is enabled by ESC[?1049h, and disabled by ESC[?1049l. All that would be needed is to ignore everything between these two escapes.

(This could be made optional, but given that the alternative screen buffer is typically used by full-screen text UIs that aha can't meaningfully handle anyway, I don't think that anyone would want to turn it off.)

iskunk avatar Mar 21 '22 17:03 iskunk