Introduction to alternate screen

When implementing terminal search highlighting using xterm.js, it’s necessary to recognize whether the terminal is currently in vi editor mode. Upon investigation, it was found that xterm.buffer.active.type can be used for this purpose.

Upon examining the corresponding type definitions, it was found that the values are only “normal” and “alternate.” It wasn’t clear why it’s called “alternate,” so further investigation revealed that this concept originates from the terminal’s alternate screen. Here’s an overall introduction.

https://static.1991421.cn/2022/2022-07-28-224538.jpeg

Alternate Screen

  1. The alternate screen is a temporary screen for interactive input, which eventually returns to the main screen. For example, in VI mode, the screen display area is the same as in normal mode. When the alternate screen is activated, the original screen content is saved, and the original content is restored upon exiting the alternate screen.
  2. Therefore, the normal/alternate concepts in xterm are not original but are inherent to the terminal’s design, with these two modes being standard and alternate.

At the end

xterm.js is just one implementation of xterm. To better understand xterm.js, learning more about the design of xterm—the terminal emulator is necessary.