From 49ec4242489334258696abfea97ffdbb6017c117 Mon Sep 17 00:00:00 2001 From: Rex Zeng Date: Sun, 4 Feb 2024 00:34:15 +0800 Subject: [PATCH] feat(cli): swap screen buffer --- src/cli/show-in-terminal.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cli/show-in-terminal.ts b/src/cli/show-in-terminal.ts index af65c50..892343c 100644 --- a/src/cli/show-in-terminal.ts +++ b/src/cli/show-in-terminal.ts @@ -56,6 +56,15 @@ let columns = terminal.width; let rows = terminal.height; const showInTerminal = ([leftResult, rightResult]: readonly [DiffResult[], DiffResult[]]) => { + // Swap to an alternate screen buffer + // https://github.com/vadimdemedes/ink/issues/263#issuecomment-600927688 + const enterAltScreenCommand = '\x1b[?1049h'; + const leaveAltScreenCommand = '\x1b[?1049l'; + process.stdout.write(enterAltScreenCommand); + process.on('exit', () => { + process.stdout.write(leaveAltScreenCommand); + }); + showContent(leftResult, rightResult, columns, rows); terminal.on('resize', (newColumns: number, newRows: number) => {