@oclif/table 0.4.5 → 0.4.7

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 CHANGED
@@ -8,7 +8,7 @@ import React from 'react';
8
8
  import stripAnsi from 'strip-ansi';
9
9
  import wrapAnsi from 'wrap-ansi';
10
10
  import { BORDER_SKELETONS } from './skeletons.js';
11
- import { allKeysInCollection, determineConfiguredWidth, determineWidthOfWrappedText, getColumns, getHeadings, intersperse, maybeStripAnsi, shouldUsePlainTable, sortData, } from './utils.js';
11
+ import { allKeysInCollection, determineConfiguredWidth, determineWidthOfWrappedText, getColumns, getColumnWidth, getHeadings, intersperse, maybeStripAnsi, shouldUsePlainTable, sortData, } from './utils.js';
12
12
  /**
13
13
  * Determine the width to use for the table.
14
14
  *
@@ -16,7 +16,7 @@ import { allKeysInCollection, determineConfiguredWidth, determineWidthOfWrappedT
16
16
  */
17
17
  function determineWidthToUse(columns, maxWidth, width) {
18
18
  const tableWidth = columns.map((c) => c.width).reduce((a, b) => a + b, 0) + columns.length + 1;
19
- return width ?? Math.max(tableWidth, maxWidth);
19
+ return width ?? (tableWidth < maxWidth ? maxWidth : tableWidth);
20
20
  }
21
21
  function determineTruncatePosition(overflow) {
22
22
  switch (overflow) {
@@ -286,7 +286,7 @@ const createStdout = () => {
286
286
  // https://github.com/vadimdemedes/ink/blob/v5.0.1/src/ink.tsx#L174
287
287
  // This might be a bad idea but it works.
288
288
  stdout.rows = 10_000;
289
- stdout.columns = process.stdout.columns ?? 80;
289
+ stdout.columns = getColumnWidth();
290
290
  const frames = [];
291
291
  stdout.write = (data) => {
292
292
  frames.push(data);
@@ -396,7 +396,7 @@ export function printTables(tables, options) {
396
396
  const output = new Output();
397
397
  const leftMargin = options?.marginLeft ?? options?.margin ?? 0;
398
398
  const rightMargin = options?.marginRight ?? options?.margin ?? 0;
399
- const columns = process.stdout.columns - (leftMargin + rightMargin);
399
+ const columns = getColumnWidth() - (leftMargin + rightMargin);
400
400
  const processed = tables.map((table) => ({
401
401
  ...table,
402
402
  // adjust maxWidth to account for margin and columnGap
package/lib/utils.d.ts CHANGED
@@ -11,6 +11,7 @@ export declare function intersperse<T, I>(intersperser: (index: number) => I, el
11
11
  export declare function sortData<T extends Record<string, unknown>>(data: T[], sort?: Sort<T> | undefined): T[];
12
12
  export declare function allKeysInCollection<T extends Record<string, unknown>>(data: T[]): (keyof T)[];
13
13
  export declare function determineWidthOfWrappedText(text: string): number;
14
+ export declare function getColumnWidth(): number;
14
15
  /**
15
16
  * Determines the configured width based on the provided width value.
16
17
  * If no width is provided, it returns the width of the current terminal.
package/lib/utils.js CHANGED
@@ -42,6 +42,14 @@ export function determineWidthOfWrappedText(text) {
42
42
  const lines = text.split('\n');
43
43
  return lines.reduce((max, line) => Math.max(max, line.length), 0);
44
44
  }
45
+ // In certain systems, `process.stdout.columns` can be 0
46
+ // The column width is calculated by:
47
+ // 1. The value of `OCLIF_TABLE_COLUMN_OVERRIDE` (if set)
48
+ // 2. The value of `process.stdout.columns`
49
+ // 3. If `process.stdout.columns` is 0, use 80
50
+ export function getColumnWidth() {
51
+ return Number.parseInt(process.env.OCLIF_TABLE_COLUMN_OVERRIDE || '0', 10) || process.stdout.columns || 80;
52
+ }
45
53
  /**
46
54
  * Determines the configured width based on the provided width value.
47
55
  * If no width is provided, it returns the width of the current terminal.
@@ -52,7 +60,7 @@ export function determineWidthOfWrappedText(text) {
52
60
  * @param providedWidth - The width value provided.
53
61
  * @returns The determined configured width.
54
62
  */
55
- export function determineConfiguredWidth(providedWidth, columns = process.stdout.columns) {
63
+ export function determineConfiguredWidth(providedWidth, columns = getColumnWidth()) {
56
64
  if (!providedWidth)
57
65
  return columns;
58
66
  const num = typeof providedWidth === 'string' && providedWidth.endsWith('%')
@@ -111,7 +119,7 @@ export function getColumns(config, headings) {
111
119
  break;
112
120
  const minWidth = calcMinWidth(largestColumn);
113
121
  const difference = tableWidth - maxWidth;
114
- const newWidth = Math.max(largestColumn.width - difference, minWidth);
122
+ const newWidth = largestColumn.width - difference < minWidth ? minWidth : largestColumn.width - difference;
115
123
  largestColumn.width = newWidth;
116
124
  tableWidth = calculateTableWidth(widths);
117
125
  seen.add(largestColumn.key);
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@oclif/table",
3
3
  "description": "Display table in terminal",
4
- "version": "0.4.5",
4
+ "version": "0.4.7",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/table/issues",
7
7
  "dependencies": {
8
- "@oclif/core": "^4",
9
8
  "@types/react": "^18.3.12",
10
9
  "change-case": "^5.4.4",
11
10
  "cli-truncate": "^4.0.0",
@@ -18,30 +17,31 @@
18
17
  },
19
18
  "devDependencies": {
20
19
  "@commitlint/config-conventional": "^19",
21
- "@eslint/compat": "^1.2.6",
20
+ "@eslint/compat": "^1.2.8",
21
+ "@oclif/core": "^4",
22
22
  "@oclif/prettier-config": "^0.2.1",
23
- "@oclif/test": "^4.1.8",
23
+ "@oclif/test": "^4.1.12",
24
24
  "@types/chai": "^4.3.16",
25
25
  "@types/mocha": "^10.0.10",
26
26
  "@types/node": "^18",
27
27
  "@types/object-hash": "^3.0.6",
28
28
  "@types/sinon": "^17.0.3",
29
- "ansis": "^3.5.2",
29
+ "ansis": "^3.17.0",
30
30
  "chai": "^4.5.0",
31
31
  "commitlint": "^19",
32
- "eslint": "^9.19.0",
33
- "eslint-config-oclif": "^6.0.0",
34
- "eslint-config-prettier": "^10.0.1",
32
+ "eslint": "^9.24.0",
33
+ "eslint-config-oclif": "^6.0.39",
34
+ "eslint-config-prettier": "^10.1.1",
35
35
  "eslint-config-xo": "^0.46.0",
36
36
  "eslint-config-xo-react": "^0.28.0",
37
- "eslint-plugin-react": "^7.37.4",
37
+ "eslint-plugin-react": "^7.37.5",
38
38
  "eslint-plugin-react-hooks": "^4.6.2",
39
39
  "husky": "^9.1.7",
40
40
  "ink-testing-library": "^4.0.0",
41
41
  "lint-staged": "^15",
42
42
  "mocha": "^10.8.2",
43
- "prettier": "^3.4.2",
44
- "shx": "^0.3.4",
43
+ "prettier": "^3.5.3",
44
+ "shx": "^0.4.0",
45
45
  "sinon": "^18",
46
46
  "terminal-link": "^3.0.0",
47
47
  "ts-node": "^10.9.2",