@oclif/table
Advanced tools
Comparing version 0.1.23 to 0.1.24
/* eslint-disable react/prop-types */ | ||
import cliTruncate from 'cli-truncate'; | ||
import { Box, Text, render } from 'ink'; | ||
import { WriteStream } from 'node:tty'; | ||
import { EventEmitter } from 'node:events'; | ||
import { sha1 } from 'object-hash'; | ||
@@ -282,8 +282,12 @@ import React from 'react'; | ||
/** | ||
* A custom WriteStream that captures the frames written to stdout. | ||
* Return a custom WriteStream that captures the frames written to stdout. | ||
* This allows us to avoid an issue where Ink rerenders the component twice | ||
* because it uses ansiEscapes.clearTerminal, which doesn't seem to have | ||
* the desired effect in powershell. | ||
* | ||
* Implementation inspired by https://github.com/vadimdemedes/ink/blob/master/test/helpers/create-stdout.ts | ||
*/ | ||
class Stream extends WriteStream { | ||
const createStdout = () => { | ||
// eslint-disable-next-line unicorn/prefer-event-target | ||
const stdout = new EventEmitter(); | ||
// Override the rows so that ink doesn't clear the entire terminal when | ||
@@ -294,34 +298,24 @@ // unmounting the component and the height of the output is greater than | ||
// This might be a bad idea but it works. | ||
rows = 10_000; | ||
frames = []; | ||
lastFrame() { | ||
return this.frames | ||
.filter((f) => { | ||
const stripped = stripAnsi(f); | ||
return stripped !== '' && stripped !== '\n'; | ||
}) | ||
.at(-1); | ||
} | ||
write(data) { | ||
this.frames.push(data); | ||
stdout.rows = 10_000; | ||
stdout.columns = process.stdout.columns ?? 80; | ||
const frames = []; | ||
stdout.write = (data) => { | ||
frames.push(data); | ||
return true; | ||
} | ||
} | ||
}; | ||
stdout.lastFrame = () => frames | ||
.filter((f) => { | ||
const stripped = stripAnsi(f); | ||
return stripped !== '' && stripped !== '\n'; | ||
}) | ||
.at(-1); | ||
return stdout; | ||
}; | ||
class Output { | ||
stream; | ||
constructor() { | ||
// 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) : 0); | ||
this.stream = createStdout(); | ||
} | ||
maybePrintLastFrame() { | ||
if (this.stream instanceof Stream) { | ||
process.stdout.write(`${this.stream.lastFrame()}`); | ||
} | ||
else { | ||
process.stdout.write('\n'); | ||
} | ||
process.stdout.write(`${this.stream.lastFrame()}\n`); | ||
} | ||
@@ -328,0 +322,0 @@ } |
{ | ||
"name": "@oclif/table", | ||
"description": "Display table in terminal", | ||
"version": "0.1.23", | ||
"version": "0.1.24", | ||
"author": "Salesforce", | ||
@@ -6,0 +6,0 @@ "bugs": "https://github.com/oclif/table/issues", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
1
45035
1221
3