Skip to content

Implementation details of alternate screen buffer using virtual codes #15920

Closed Answered by j4james
2trvl asked this question in Q&A
Discussion options

You must be logged in to vote

I don't think you can detect the alternate buffer status with a Console API call, and if you could, it's probably not something you should rely on. However, you can query that state with a standard DECRQM escape sequence. If you output \x1b[?1049$p, you should get back one of two responses:

  • \x1b[?1049;1$y if you're in the alternate buffer
  • \x1b[?1049;2$y if you're in the main buffer

That said, you should be aware that not all terminals will respond to DECRQM, and it has only been supported in Windows Terminal since version 1.17.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by 2trvl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants