@oclif/table 0.1.23 → 0.1.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/table.js +23 -29
- package/package.json +1 -1
package/lib/table.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable react/prop-types */
|
|
2
2
|
import cliTruncate from 'cli-truncate';
|
|
3
3
|
import { Box, Text, render } from 'ink';
|
|
4
|
-
import {
|
|
4
|
+
import { EventEmitter } from 'node:events';
|
|
5
5
|
import { sha1 } from 'object-hash';
|
|
6
6
|
import React from 'react';
|
|
7
7
|
import stripAnsi from 'strip-ansi';
|
|
@@ -279,49 +279,43 @@ export function Skeleton(props) {
|
|
|
279
279
|
return React.createElement(Box, { flexDirection: "column" }, texts);
|
|
280
280
|
}
|
|
281
281
|
/**
|
|
282
|
-
*
|
|
282
|
+
* Return a custom WriteStream that captures the frames written to stdout.
|
|
283
283
|
* This allows us to avoid an issue where Ink rerenders the component twice
|
|
284
284
|
* because it uses ansiEscapes.clearTerminal, which doesn't seem to have
|
|
285
285
|
* the desired effect in powershell.
|
|
286
|
+
*
|
|
287
|
+
* Implementation inspired by https://github.com/vadimdemedes/ink/blob/master/test/helpers/create-stdout.ts
|
|
286
288
|
*/
|
|
287
|
-
|
|
289
|
+
const createStdout = () => {
|
|
290
|
+
// eslint-disable-next-line unicorn/prefer-event-target
|
|
291
|
+
const stdout = new EventEmitter();
|
|
288
292
|
// Override the rows so that ink doesn't clear the entire terminal when
|
|
289
293
|
// unmounting the component and the height of the output is greater than
|
|
290
294
|
// the height of the terminal
|
|
291
295
|
// https://github.com/vadimdemedes/ink/blob/v5.0.1/src/ink.tsx#L174
|
|
292
296
|
// This might be a bad idea but it works.
|
|
293
|
-
rows = 10_000;
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
const stripped = stripAnsi(f);
|
|
299
|
-
return stripped !== '' && stripped !== '\n';
|
|
300
|
-
})
|
|
301
|
-
.at(-1);
|
|
302
|
-
}
|
|
303
|
-
write(data) {
|
|
304
|
-
this.frames.push(data);
|
|
297
|
+
stdout.rows = 10_000;
|
|
298
|
+
stdout.columns = process.stdout.columns ?? 80;
|
|
299
|
+
const frames = [];
|
|
300
|
+
stdout.write = (data) => {
|
|
301
|
+
frames.push(data);
|
|
305
302
|
return true;
|
|
306
|
-
}
|
|
307
|
-
|
|
303
|
+
};
|
|
304
|
+
stdout.lastFrame = () => frames
|
|
305
|
+
.filter((f) => {
|
|
306
|
+
const stripped = stripAnsi(f);
|
|
307
|
+
return stripped !== '' && stripped !== '\n';
|
|
308
|
+
})
|
|
309
|
+
.at(-1);
|
|
310
|
+
return stdout;
|
|
311
|
+
};
|
|
308
312
|
class Output {
|
|
309
313
|
stream;
|
|
310
314
|
constructor() {
|
|
311
|
-
|
|
312
|
-
// are problematic for an unknown reason)
|
|
313
|
-
this.stream =
|
|
314
|
-
(process.platform === 'win32' && process.env.npm_lifecycle_script === 'wireit') || process.env.NODE_ENV === 'test'
|
|
315
|
-
? process.stdout
|
|
316
|
-
: new Stream(process.env.OCLIF_TABLE_FD ? Number(process.env.OCLIF_TABLE_FD) : 0);
|
|
315
|
+
this.stream = createStdout();
|
|
317
316
|
}
|
|
318
317
|
maybePrintLastFrame() {
|
|
319
|
-
|
|
320
|
-
process.stdout.write(`${this.stream.lastFrame()}`);
|
|
321
|
-
}
|
|
322
|
-
else {
|
|
323
|
-
process.stdout.write('\n');
|
|
324
|
-
}
|
|
318
|
+
process.stdout.write(`${this.stream.lastFrame()}\n`);
|
|
325
319
|
}
|
|
326
320
|
}
|
|
327
321
|
function chunk(array, size) {
|