@oclif/table 0.1.15 → 0.1.16

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.
Files changed (2) hide show
  1. package/lib/table.js +21 -7
  2. package/package.json +2 -1
package/lib/table.js CHANGED
@@ -261,7 +261,7 @@ export function Skeleton(props) {
261
261
  * because it uses ansiEscapes.clearTerminal, which doesn't seem to have
262
262
  * the desired effect in powershell.
263
263
  */
264
- class Stdout extends WriteStream {
264
+ class Stream extends WriteStream {
265
265
  frames = [];
266
266
  lastFrame() {
267
267
  return this.frames.filter((f) => stripAnsi(f) !== '').at(-1);
@@ -271,21 +271,35 @@ class Stdout extends WriteStream {
271
271
  return true;
272
272
  }
273
273
  }
274
+ class Output {
275
+ stream;
276
+ constructor(fd = 1) {
277
+ this.stream = process.env.NODE_ENV === 'test' ? process.stdout : new WriteStream(fd);
278
+ }
279
+ maybePrintLastFrame() {
280
+ if (this.stream instanceof Stream) {
281
+ process.stdout.write(`${this.stream.lastFrame()}\n`);
282
+ }
283
+ else {
284
+ process.stdout.write('\n');
285
+ }
286
+ }
287
+ }
274
288
  /**
275
289
  * Renders a table with the given data.
276
290
  * @param options see {@link TableOptions}
277
291
  */
278
292
  export function printTable(options) {
279
- const stdout = new Stdout(1);
280
- const instance = render(React.createElement(Table, { ...options }), { stdout });
293
+ const output = new Output();
294
+ const instance = render(React.createElement(Table, { ...options }), { stdout: output.stream });
281
295
  instance.unmount();
282
- process.stdout.write(`${stdout.lastFrame()}\n`);
296
+ output.maybePrintLastFrame();
283
297
  }
284
298
  function Container(props) {
285
299
  return (React.createElement(Box, { flexWrap: "wrap", flexDirection: props.direction ?? 'row', ...props }, props.children));
286
300
  }
287
301
  export function printTables(tables, options) {
288
- const stdout = new Stdout(1);
302
+ const output = new Output();
289
303
  const leftMargin = options?.marginLeft ?? options?.margin ?? 0;
290
304
  const rightMargin = options?.marginRight ?? options?.margin ?? 0;
291
305
  const columns = process.stdout.columns - (leftMargin + rightMargin);
@@ -294,7 +308,7 @@ export function printTables(tables, options) {
294
308
  // adjust maxWidth to account for margin and columnGap
295
309
  maxWidth: determineConfiguredWidth(table.maxWidth, columns) - (options?.columnGap ?? 0) * tables.length,
296
310
  }));
297
- const instance = render(React.createElement(Container, { ...options }, processed.map((table) => (React.createElement(Table, { key: sha1(table), ...table })))), { stdout });
311
+ const instance = render(React.createElement(Container, { ...options }, processed.map((table) => (React.createElement(Table, { key: sha1(table), ...table })))), { stdout: output.stream });
298
312
  instance.unmount();
299
- process.stdout.write(`${stdout.lastFrame()}\n`);
313
+ output.maybePrintLastFrame();
300
314
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oclif/table",
3
3
  "description": "Display table in terminal",
4
- "version": "0.1.15",
4
+ "version": "0.1.16",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/table/issues",
7
7
  "dependencies": {
@@ -19,6 +19,7 @@
19
19
  "devDependencies": {
20
20
  "@commitlint/config-conventional": "^19",
21
21
  "@oclif/prettier-config": "^0.2.1",
22
+ "@oclif/test": "^4.0.9",
22
23
  "@types/chai": "^4.3.16",
23
24
  "@types/mocha": "^10.0.8",
24
25
  "@types/node": "^18",