Skip to content

Commit

Permalink
Merge pull request #27 from oclif/mdonnalley/stream-rows
Browse files Browse the repository at this point in the history
fix: override stdout rows to prevent terminal clearing
  • Loading branch information
WillieRuemmele authored Oct 21, 2024
2 parents 6c55c49 + 8ea1f20 commit b1927b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 0 additions & 1 deletion examples/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const data = [
},
{
age: 22,
bigData: 'c'.repeat(30),
employed: ansis.bold('false'),
id: terminalLink('51786', 'https://example.com/51786'),
name: 'Charlie',
Expand Down
14 changes: 12 additions & 2 deletions src/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,12 @@ export function Skeleton(props: React.PropsWithChildren & {readonly height?: num
* the desired effect in powershell.
*/
class Stream extends WriteStream {
// Override the rows so that ink doesn't clear the entire terminal when
// unmounting the component and the height of the output is greater than
// the height of the terminal
// https://github.com/vadimdemedes/ink/blob/v5.0.1/src/ink.tsx#L174
// This might be a bad idea but it works.
public rows = 10_000
private frames: string[] = []

public lastFrame(): string | undefined {
Expand All @@ -451,8 +457,12 @@ class Output {
public stream: Stream | WriteStream

public constructor() {
const fd = process.env.OCLIF_TABLE_FD ? Number(process.env.OCLIF_TABLE_FD) : 0
this.stream = process.env.NODE_ENV === 'test' ? process.stdout : new Stream(fd)
// Use process.stdout if NODE_ENV is `test` OR if tests are being run by wireit on windows (windows + tests run by wireit
// are problematic for an unknown reason)
this.stream =
(process.platform === 'win32' && process.env.npm_lifecycle_script === 'wireit') || process.env.NODE_ENV === 'test'
? process.stdout
: new Stream(process.env.OCLIF_TABLE_FD ? Number(process.env.OCLIF_TABLE_FD) : process.stdout.fd)
}

public maybePrintLastFrame() {
Expand Down

0 comments on commit b1927b5

Please sign in to comment.