@oclif/table 0.1.13 → 0.1.15
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 -4
- package/package.json +4 -4
package/lib/table.js
CHANGED
|
@@ -1,6 +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 { WriteStream } from 'node:tty';
|
|
4
5
|
import { sha1 } from 'object-hash';
|
|
5
6
|
import React from 'react';
|
|
6
7
|
import stripAnsi from 'strip-ansi';
|
|
@@ -254,19 +255,37 @@ export function Skeleton(props) {
|
|
|
254
255
|
const texts = Array.from({ length: props.height ?? 1 }, (_, i) => (React.createElement(Text, { key: i, ...rest }, children)));
|
|
255
256
|
return React.createElement(Box, { flexDirection: "column" }, texts);
|
|
256
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* A custom WriteStream that captures the frames written to stdout.
|
|
260
|
+
* This allows us to avoid an issue where Ink rerenders the component twice
|
|
261
|
+
* because it uses ansiEscapes.clearTerminal, which doesn't seem to have
|
|
262
|
+
* the desired effect in powershell.
|
|
263
|
+
*/
|
|
264
|
+
class Stdout extends WriteStream {
|
|
265
|
+
frames = [];
|
|
266
|
+
lastFrame() {
|
|
267
|
+
return this.frames.filter((f) => stripAnsi(f) !== '').at(-1);
|
|
268
|
+
}
|
|
269
|
+
write(data) {
|
|
270
|
+
this.frames.push(data);
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
257
274
|
/**
|
|
258
275
|
* Renders a table with the given data.
|
|
259
276
|
* @param options see {@link TableOptions}
|
|
260
277
|
*/
|
|
261
278
|
export function printTable(options) {
|
|
262
|
-
const
|
|
279
|
+
const stdout = new Stdout(1);
|
|
280
|
+
const instance = render(React.createElement(Table, { ...options }), { stdout });
|
|
263
281
|
instance.unmount();
|
|
264
|
-
process.stdout.write(
|
|
282
|
+
process.stdout.write(`${stdout.lastFrame()}\n`);
|
|
265
283
|
}
|
|
266
284
|
function Container(props) {
|
|
267
285
|
return (React.createElement(Box, { flexWrap: "wrap", flexDirection: props.direction ?? 'row', ...props }, props.children));
|
|
268
286
|
}
|
|
269
287
|
export function printTables(tables, options) {
|
|
288
|
+
const stdout = new Stdout(1);
|
|
270
289
|
const leftMargin = options?.marginLeft ?? options?.margin ?? 0;
|
|
271
290
|
const rightMargin = options?.marginRight ?? options?.margin ?? 0;
|
|
272
291
|
const columns = process.stdout.columns - (leftMargin + rightMargin);
|
|
@@ -275,7 +294,7 @@ export function printTables(tables, options) {
|
|
|
275
294
|
// adjust maxWidth to account for margin and columnGap
|
|
276
295
|
maxWidth: determineConfiguredWidth(table.maxWidth, columns) - (options?.columnGap ?? 0) * tables.length,
|
|
277
296
|
}));
|
|
278
|
-
const instance = render(React.createElement(Container, { ...options }, processed.map((table) => (React.createElement(Table, { key: sha1(table), ...table })))));
|
|
297
|
+
const instance = render(React.createElement(Container, { ...options }, processed.map((table) => (React.createElement(Table, { key: sha1(table), ...table })))), { stdout });
|
|
279
298
|
instance.unmount();
|
|
280
|
-
process.stdout.write(
|
|
299
|
+
process.stdout.write(`${stdout.lastFrame()}\n`);
|
|
281
300
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oclif/table",
|
|
3
3
|
"description": "Display table in terminal",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.15",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/oclif/table/issues",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@oclif/core": "^4",
|
|
9
|
-
"@types/react": "^18.3.
|
|
9
|
+
"@types/react": "^18.3.11",
|
|
10
10
|
"change-case": "^5.4.4",
|
|
11
11
|
"cli-truncate": "^4.0.0",
|
|
12
12
|
"ink": "^5.0.1",
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"commitlint": "^19",
|
|
30
30
|
"eslint": "^8.57.0",
|
|
31
31
|
"eslint-config-oclif": "^5.2.0",
|
|
32
|
-
"eslint-config-oclif-typescript": "^3.1.
|
|
32
|
+
"eslint-config-oclif-typescript": "^3.1.11",
|
|
33
33
|
"eslint-config-prettier": "^9.1.0",
|
|
34
34
|
"eslint-config-xo": "^0.45.0",
|
|
35
35
|
"eslint-config-xo-react": "^0.27.0",
|
|
36
|
-
"eslint-plugin-react": "^7.37.
|
|
36
|
+
"eslint-plugin-react": "^7.37.1",
|
|
37
37
|
"eslint-plugin-react-hooks": "^4.6.2",
|
|
38
38
|
"husky": "^9.1.6",
|
|
39
39
|
"ink-testing-library": "^4.0.0",
|