File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,9 +19,11 @@ export function settings(...sequence: Setting[]): Setting {
1919 } ;
2020}
2121
22- export function alternateBuffer ( ) : Setting {
22+ export function alternateBuffer (
23+ options ?: { clear ?: boolean } ,
24+ ) : Setting {
2325 return {
24- apply : ALTSCREEN ( ) ,
26+ apply : ALTSCREEN ( options ) ,
2527 revert : MAINSCREEN ( ) ,
2628 } ;
2729}
Original file line number Diff line number Diff line change @@ -55,19 +55,27 @@ export function HIDECURSOR(): Uint8Array {
5555}
5656
5757/**
58- * Switch to the alternate screen buffer (xterm private mode 1049) .
58+ * Switch to the alternate screen buffer.
5959 *
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.
6265 *
6366 * @see {@link https://invisible-island.net/xterm/ctlseqs/ctlseqs.html | xterm control sequences }
6467 */
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+ }
6775}
6876
6977/**
70- * Switch back to the main screen buffer (xterm private mode 1049) .
78+ * Switch back to the main screen buffer.
7179 *
7280 * Restores the cursor and returns to the main screen with scrollback intact.
7381 *
Original file line number Diff line number Diff line change @@ -18,6 +18,12 @@ describe("settings", () => {
1818 expect ( str ( s . apply ) ) . toBe ( "\x1b[?1049h" ) ;
1919 expect ( str ( s . revert ) ) . toBe ( "\x1b[?1049l" ) ;
2020 } ) ;
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+ } ) ;
2127 } ) ;
2228
2329 describe ( "cursor" , ( ) => {
You can’t perform that action at this time.
0 commit comments