Skip to content

Commit

Permalink
Add escapes for entering/exiting the alternative screen (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
vadimdemedes authored Apr 24, 2023
1 parent 9ebbcf0 commit 2f25a50
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ declare const ansiEscapes: {
*/
clearTerminal: string;

/**
Enter the [alternative screen](https://terminalguide.namepad.de/mode/p47/).
*/
enterAlternativeScreen: string;

/**
Exit the [alternative screen](https://terminalguide.namepad.de/mode/p47/), assuming `enterAlternativeScreen` was called before.
*/
exitAlternativeScreen: string;

/**
Output a beeping sound.
*/
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ ansiEscapes.clearTerminal = isWindows
// More info: https://www.real-world-systems.com/docs/ANSIcode.html
: `${ansiEscapes.eraseScreen}${ESC}3J${ESC}H`;

ansiEscapes.enterAlternativeScreen = ESC + '?1049h';
ansiEscapes.exitAlternativeScreen = ESC + '?1049l';

ansiEscapes.beep = BEL;

ansiEscapes.link = (text, url) => [
Expand Down
2 changes: 2 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ expectType<string>(ansiEscapes.scrollUp);
expectType<string>(ansiEscapes.scrollDown);
expectType<string>(ansiEscapes.clearScreen);
expectType<string>(ansiEscapes.clearTerminal);
expectType<string>(ansiEscapes.enterAlternativeScreen);
expectType<string>(ansiEscapes.exitAlternativeScreen);
expectType<string>(ansiEscapes.beep);
expectType<string>(ansiEscapes.link('foo', 'https://foo.bar'));
expectType<string>(ansiEscapes.image(Buffer.from('1')));
Expand Down
8 changes: 8 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ Clear the terminal screen. (Viewport)

Clear the whole terminal, including scrollback buffer. (Not just the visible part of it)

### enterAlternativeScreen

Enter the [alternative screen](https://terminalguide.namepad.de/mode/p47/).

### exitAlternativeScreen

Exit the [alternative screen](https://terminalguide.namepad.de/mode/p47/), assuming `enterAlternativeScreen` was called before.

### beep

Output a beeping sound.
Expand Down

0 comments on commit 2f25a50

Please sign in to comment.