···5555}
56565757/**
5858- * Switch to the alternate screen buffer (xterm private mode 1049).
5858+ * Switch to the alternate screen buffer.
5959 *
6060- * Saves the cursor and switches to a clean alternate screen. Use
6161- * {@link MAINSCREEN} to switch back.
6060+ * Saves the cursor and switches to the alternate screen. When `clear` is
6161+ * `true` (the default), the alternate buffer is cleared on entry. When
6262+ * `false`, the existing contents are preserved.
6363+ *
6464+ * Use {@link MAINSCREEN} to switch back.
6265 *
6366 * @see {@link https://invisible-island.net/xterm/ctlseqs/ctlseqs.html | xterm control sequences}
6467 */
6565-export function ALTSCREEN(): Uint8Array {
6666- return CSI("?1049h");
6868+export function ALTSCREEN(options?: { clear?: boolean }): Uint8Array {
6969+ let { clear = true } = options ?? {};
7070+ if (clear) {
7171+ return CSI("?1049h");
7272+ } else {
7373+ return CSI("?47h");
7474+ }
6775}
68766977/**
7070- * Switch back to the main screen buffer (xterm private mode 1049).
7878+ * Switch back to the main screen buffer.
7179 *
7280 * Restores the cursor and returns to the main screen with scrollback intact.
7381 *
+6
test/settings.test.ts
···1818 expect(str(s.apply)).toBe("\x1b[?1049h");
1919 expect(str(s.revert)).toBe("\x1b[?1049l");
2020 });
2121+2222+ it("uses mode 47 when clear is false", () => {
2323+ let s = alternateBuffer({ clear: false });
2424+ expect(str(s.apply)).toBe("\x1b[?47h");
2525+ expect(str(s.revert)).toBe("\x1b[?1049l");
2626+ });
2127 });
22282329 describe("cursor", () => {