-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Full-screen LayerZero experience
- Loading branch information
1 parent
8061250
commit ed1f5f8
Showing
2 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const ENTER_ALT_SCREEN_ANSI = "\x1b[?1049h" | ||
const EXIT_ALT_SCREEN_ANSI = "\x1b[?1049l" | ||
|
||
/** | ||
* Helper function that wraps socket writes with a promise | ||
* | ||
* @param socket `WriteStream` | ||
* @returns `(content: string) => Promise<void>` | ||
*/ | ||
const createWrite = (socket: NodeJS.WriteStream) => (content: string) => { | ||
return new Promise<void>((resolve, reject) => { | ||
socket.write(content, (error) => { | ||
if (error != null) reject(error) | ||
else resolve() | ||
}) | ||
}) | ||
} | ||
|
||
/** | ||
* Starts an alt screen and returns a callback that exits back to the default screen. | ||
* This makes the app "full screen" | ||
* | ||
* See https://github.com/vadimdemedes/ink/issues/263 for more info | ||
* | ||
* @returns `Promise<() => void>` | ||
*/ | ||
export const altScreen = async () => { | ||
const write = createWrite(process.stdout) | ||
|
||
await write(ENTER_ALT_SCREEN_ANSI) | ||
|
||
return () => write(EXIT_ALT_SCREEN_ANSI) | ||
} |