xterm js,关于使用的几个问题

xtermjs, few questions regaring the usage

正在努力使用xtermjs,还有一些官方文档没有涉及的问题,至少我没有找到。

  1. 我了解到,当我在终端内使用某些应用程序时,例如,Vim终端需要切换到备用缓冲区,在我退出应用程序后,终端切换回正常缓冲区。这样对吗?

  1. 要在缓冲区之间切换(以及整体控制终端行为),我需要使用控制序列。它不是xterm.js独有的东西,但是终端之间的通用模式和控制序列是统一的吗?

  1. 根据文档,切换到备用缓冲区的控制顺序为 CSI ? Pm h,参数为 47

DECSET DEC Private Set Mode CSI ? Pm h Set various terminal attributes.

在哪里

paramAction 47 - Use Alternate Screen Buffer.


  1. 这个控制序列如何与xterm.js一起使用,比如我想切换到alternate buffer。 terminal.write(...) 中应使用什么字符串?
  1. 是的,请参阅此问题中的说明 Using the “alternate screen” in a bash script

    The alternate screen is used by many "user-interactive" terminal applications like vim, htop, screen, alsamixer, less, ... It is like a different buffer of the terminal content, which disappears when the application exits, so the whole terminal gets restored and it looks like the application hasn't output anything

  2. 是的,ANSI escape code

    ANSI escape sequences are a standard for in-band signaling to control the cursor location, color, and other options on video text terminals and terminal emulators. Certain sequences of bytes, most starting with Esc (ASCII character 27) and '[', are embedded into the text, which the terminal looks for and interprets as commands, not as character codes.

    • 切换到备用缓冲区的控制序列:CSI ? 47 h
    • 切换到常规缓冲区的控制序列:CSI ? 47 l
  3. 应用控制序列切换到备用缓冲区的代码:

terminal.write("\x9B?47h"); //CSI ? 47 h