[READ-ONLY] Mirror of https://github.com/bombshell-dev/tty. Platform independent 2D layout engine for terminal applications based on Clay
5

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #14 from thefrontside/decouple-altbuffer-clear

Decouple alternate buffer switching from clearing

authored by

Charles Lowell and committed by
GitHub
(Apr 17, 2026, 12:25 PM -0500) a6b1ee1e 5372af80

+24 -8
+4 -2
settings.ts
··· 19 19 }; 20 20 } 21 21 22 - export function alternateBuffer(): Setting { 22 + export function alternateBuffer( 23 + options?: { clear?: boolean }, 24 + ): Setting { 23 25 return { 24 - apply: ALTSCREEN(), 26 + apply: ALTSCREEN(options), 25 27 revert: MAINSCREEN(), 26 28 }; 27 29 }
+14 -6
termcodes.ts
··· 55 55 } 56 56 57 57 /** 58 - * Switch to the alternate screen buffer (xterm private mode 1049). 58 + * Switch to the alternate screen buffer. 59 59 * 60 - * Saves the cursor and switches to a clean alternate screen. Use 61 - * {@link MAINSCREEN} to switch back. 60 + * Saves the cursor and switches to the alternate screen. When `clear` is 61 + * `true` (the default), the alternate buffer is cleared on entry. When 62 + * `false`, the existing contents are preserved. 63 + * 64 + * Use {@link MAINSCREEN} to switch back. 62 65 * 63 66 * @see {@link https://invisible-island.net/xterm/ctlseqs/ctlseqs.html | xterm control sequences} 64 67 */ 65 - export function ALTSCREEN(): Uint8Array { 66 - return CSI("?1049h"); 68 + export function ALTSCREEN(options?: { clear?: boolean }): Uint8Array { 69 + let { clear = true } = options ?? {}; 70 + if (clear) { 71 + return CSI("?1049h"); 72 + } else { 73 + return CSI("?47h"); 74 + } 67 75 } 68 76 69 77 /** 70 - * Switch back to the main screen buffer (xterm private mode 1049). 78 + * Switch back to the main screen buffer. 71 79 * 72 80 * Restores the cursor and returns to the main screen with scrollback intact. 73 81 *
+6
test/settings.test.ts
··· 18 18 expect(str(s.apply)).toBe("\x1b[?1049h"); 19 19 expect(str(s.revert)).toBe("\x1b[?1049l"); 20 20 }); 21 + 22 + it("uses mode 47 when clear is false", () => { 23 + let s = alternateBuffer({ clear: false }); 24 + expect(str(s.apply)).toBe("\x1b[?47h"); 25 + expect(str(s.revert)).toBe("\x1b[?1049l"); 26 + }); 21 27 }); 22 28 23 29 describe("cursor", () => {