@oclif/table 0.4.7 → 0.4.9
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 +4 -1
- package/lib/utils.d.ts +12 -0
- package/lib/utils.js +17 -6
- package/package.json +7 -7
package/lib/table.js
CHANGED
|
@@ -64,13 +64,15 @@ export function formatTextWithMargins({ horizontalAlignment, overflow, padding,
|
|
|
64
64
|
// https://github.com/Shopify/cli/pull/995
|
|
65
65
|
const valueWithNoZeroWidthChars = String(value).replaceAll('', ' ');
|
|
66
66
|
const spaceForText = width - padding * 2;
|
|
67
|
-
|
|
67
|
+
// Handle the simple case where text fits within the available space and doesn't contain any newlines.
|
|
68
|
+
if (stripAnsi(valueWithNoZeroWidthChars).length <= spaceForText && !valueWithNoZeroWidthChars.includes('\n')) {
|
|
68
69
|
const spaces = width - stripAnsi(valueWithNoZeroWidthChars).length;
|
|
69
70
|
return {
|
|
70
71
|
text: valueWithNoZeroWidthChars,
|
|
71
72
|
...calculateMargins(spaces),
|
|
72
73
|
};
|
|
73
74
|
}
|
|
75
|
+
// Handle the case where the text needs to be wrapped.
|
|
74
76
|
if (overflow === 'wrap') {
|
|
75
77
|
const wrappedText = wrapAnsi(valueWithNoZeroWidthChars, spaceForText, {
|
|
76
78
|
hard: true,
|
|
@@ -101,6 +103,7 @@ export function formatTextWithMargins({ horizontalAlignment, overflow, padding,
|
|
|
101
103
|
text: lines.join('\n'),
|
|
102
104
|
};
|
|
103
105
|
}
|
|
106
|
+
// Handle the case where the text needs to be truncated.
|
|
104
107
|
const text = cliTruncate(valueWithNoZeroWidthChars.replaceAll('\n', ' '), spaceForText, {
|
|
105
108
|
position: determineTruncatePosition(overflow),
|
|
106
109
|
});
|
package/lib/utils.d.ts
CHANGED
|
@@ -11,10 +11,22 @@ 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
|
+
/**
|
|
15
|
+
* Gets the width of the terminal column.
|
|
16
|
+
* First checks for an override in the OCLIF_TABLE_COLUMN_OVERRIDE environment variable.
|
|
17
|
+
* If no override is set or the override is 0, returns the actual terminal width from process.stdout.columns.
|
|
18
|
+
*
|
|
19
|
+
* It's possible that `process.stdout.columns` is undefined or 0, which is okay. We'll end up using the table's natural width
|
|
20
|
+
* in that case. If that renders poorly for the user, they can set the OCLIF_TABLE_COLUMN_OVERRIDE environment variable to a
|
|
21
|
+
* non-zero value.
|
|
22
|
+
*
|
|
23
|
+
* @returns {number} The width of the terminal column
|
|
24
|
+
*/
|
|
14
25
|
export declare function getColumnWidth(): number;
|
|
15
26
|
/**
|
|
16
27
|
* Determines the configured width based on the provided width value.
|
|
17
28
|
* If no width is provided, it returns the width of the current terminal.
|
|
29
|
+
* - It's possible that `process.stdout.columns` is undefined, which is okay. We'll end up using the table's natural width.
|
|
18
30
|
* If the provided width is a percentage, it calculates the width based on the percentage of the terminal width.
|
|
19
31
|
* If the provided width is a number, it returns the provided width.
|
|
20
32
|
* If the calculated width is greater than the terminal width, it returns the terminal width.
|
package/lib/utils.js
CHANGED
|
@@ -42,17 +42,24 @@ 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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Gets the width of the terminal column.
|
|
47
|
+
* First checks for an override in the OCLIF_TABLE_COLUMN_OVERRIDE environment variable.
|
|
48
|
+
* If no override is set or the override is 0, returns the actual terminal width from process.stdout.columns.
|
|
49
|
+
*
|
|
50
|
+
* It's possible that `process.stdout.columns` is undefined or 0, which is okay. We'll end up using the table's natural width
|
|
51
|
+
* in that case. If that renders poorly for the user, they can set the OCLIF_TABLE_COLUMN_OVERRIDE environment variable to a
|
|
52
|
+
* non-zero value.
|
|
53
|
+
*
|
|
54
|
+
* @returns {number} The width of the terminal column
|
|
55
|
+
*/
|
|
50
56
|
export function getColumnWidth() {
|
|
51
|
-
return Number.parseInt(process.env.OCLIF_TABLE_COLUMN_OVERRIDE || '0', 10) || process.stdout.columns
|
|
57
|
+
return Number.parseInt(process.env.OCLIF_TABLE_COLUMN_OVERRIDE || '0', 10) || process.stdout.columns;
|
|
52
58
|
}
|
|
53
59
|
/**
|
|
54
60
|
* Determines the configured width based on the provided width value.
|
|
55
61
|
* If no width is provided, it returns the width of the current terminal.
|
|
62
|
+
* - It's possible that `process.stdout.columns` is undefined, which is okay. We'll end up using the table's natural width.
|
|
56
63
|
* If the provided width is a percentage, it calculates the width based on the percentage of the terminal width.
|
|
57
64
|
* If the provided width is a number, it returns the provided width.
|
|
58
65
|
* If the calculated width is greater than the terminal width, it returns the terminal width.
|
|
@@ -109,6 +116,10 @@ export function getColumns(config, headings) {
|
|
|
109
116
|
let tableWidth = calculateTableWidth(widths);
|
|
110
117
|
const seen = new Set();
|
|
111
118
|
const reduceColumnWidths = (calcMinWidth) => {
|
|
119
|
+
// maxWidth === 0 is likely from a test environment where process.stdout.columns is undefined or 0
|
|
120
|
+
// In that case, we don't want to reduce the column widths and just use the table's natural width.
|
|
121
|
+
if (maxWidth === 0)
|
|
122
|
+
return;
|
|
112
123
|
// If the table is too wide, reduce the width of the largest column as little as possible to fit the table.
|
|
113
124
|
// If the table is still too wide, it will reduce the width of the next largest column and so on
|
|
114
125
|
while (tableWidth > maxWidth) {
|
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.4.
|
|
4
|
+
"version": "0.4.9",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/oclif/table/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@commitlint/config-conventional": "^19",
|
|
20
|
-
"@eslint/compat": "^1.
|
|
20
|
+
"@eslint/compat": "^1.3.0",
|
|
21
21
|
"@oclif/core": "^4",
|
|
22
22
|
"@oclif/prettier-config": "^0.2.1",
|
|
23
|
-
"@oclif/test": "^4.1.
|
|
23
|
+
"@oclif/test": "^4.1.13",
|
|
24
24
|
"@types/chai": "^4.3.16",
|
|
25
25
|
"@types/mocha": "^10.0.10",
|
|
26
26
|
"@types/node": "^18",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"ansis": "^3.17.0",
|
|
30
30
|
"chai": "^4.5.0",
|
|
31
31
|
"commitlint": "^19",
|
|
32
|
-
"eslint": "^9.
|
|
33
|
-
"eslint-config-oclif": "^6.0.
|
|
34
|
-
"eslint-config-prettier": "^10.1.
|
|
35
|
-
"eslint-config-xo": "^0.
|
|
32
|
+
"eslint": "^9.29.0",
|
|
33
|
+
"eslint-config-oclif": "^6.0.68",
|
|
34
|
+
"eslint-config-prettier": "^10.1.5",
|
|
35
|
+
"eslint-config-xo": "^0.47.0",
|
|
36
36
|
"eslint-config-xo-react": "^0.28.0",
|
|
37
37
|
"eslint-plugin-react": "^7.37.5",
|
|
38
38
|
"eslint-plugin-react-hooks": "^4.6.2",
|