Fix a bug in alternate screen handling.