@oclif/table 0.4.9 → 0.4.11

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 +46 -10
  2. package/package.json +7 -7
package/lib/table.js CHANGED
@@ -316,7 +316,8 @@ function renderPlainTable(props) {
316
316
  const { columns, headings, processedData, title } = setupTable(props);
317
317
  if (title)
318
318
  console.log(title);
319
- const headerString = columns.reduce((acc, column) => {
319
+ // Process header columns the same way as data rows to handle multi-line headers
320
+ const headerColumnTexts = columns.map((column) => {
320
321
  const { horizontalAlignment, overflow, padding, width } = column;
321
322
  const { marginLeft, marginRight, text } = formatTextWithMargins({
322
323
  horizontalAlignment,
@@ -325,16 +326,35 @@ function renderPlainTable(props) {
325
326
  value: headings[column.column] ?? column.column,
326
327
  width,
327
328
  });
328
- return `${acc}${' '.repeat(marginLeft)}${text}${' '.repeat(marginRight)}`;
329
- }, '');
330
- console.log(headerString);
331
- console.log('-'.repeat(headerString.length));
329
+ // Split the formatted text into lines
330
+ const lines = text.split('\n');
331
+ return lines.map((line) => `${' '.repeat(marginLeft)}${line.trimStart()}${' '.repeat(marginRight)}`);
332
+ });
333
+ // Find the maximum number of lines in any header column
334
+ const maxHeaderLines = Math.max(...headerColumnTexts.map((col) => col.length));
335
+ // Pad all header columns to have the same number of lines
336
+ const paddedHeaderColumns = headerColumnTexts.map((col, colIndex) => {
337
+ const column = columns[colIndex];
338
+ while (col.length < maxHeaderLines) {
339
+ col.push(' '.repeat(column.width)); // Add empty lines
340
+ }
341
+ return col;
342
+ });
343
+ // Print each line of the header
344
+ for (let lineIndex = 0; lineIndex < maxHeaderLines; lineIndex++) {
345
+ const lineToPrint = paddedHeaderColumns.map((col) => col[lineIndex]).join('');
346
+ console.log(lineToPrint);
347
+ }
348
+ // Calculate total width for the separator line
349
+ const totalWidth = columns.reduce((acc, column) => acc + column.width, 0);
350
+ console.log('-'.repeat(totalWidth));
332
351
  for (const row of processedData) {
333
- const stringToPrint = columns.reduce((acc, column) => {
352
+ // Process all columns and get their formatted text
353
+ const columnTexts = columns.map((column) => {
334
354
  const { horizontalAlignment, overflow, padding, width } = column;
335
355
  const value = row[column.column];
336
356
  if (value === undefined || value === null) {
337
- return `${acc}${' '.repeat(width)}`;
357
+ return [' '.repeat(width)]; // Single line of spaces
338
358
  }
339
359
  const { marginLeft, marginRight, text } = formatTextWithMargins({
340
360
  horizontalAlignment,
@@ -343,9 +363,25 @@ function renderPlainTable(props) {
343
363
  value,
344
364
  width,
345
365
  });
346
- return `${acc}${' '.repeat(marginLeft)}${text}${' '.repeat(marginRight)}`;
347
- }, '');
348
- console.log(stringToPrint);
366
+ // Split the formatted text into lines
367
+ const lines = text.split('\n');
368
+ return lines.map((line) => `${' '.repeat(marginLeft)}${line.trimStart()}${' '.repeat(marginRight)}`);
369
+ });
370
+ // Find the maximum number of lines in any column
371
+ const maxLines = Math.max(...columnTexts.map((col) => col.length));
372
+ // Pad all columns to have the same number of lines
373
+ const paddedColumns = columnTexts.map((col, colIndex) => {
374
+ const column = columns[colIndex];
375
+ while (col.length < maxLines) {
376
+ col.push(' '.repeat(column.width)); // Add empty lines
377
+ }
378
+ return col;
379
+ });
380
+ // Print each line of the row
381
+ for (let lineIndex = 0; lineIndex < maxLines; lineIndex++) {
382
+ const lineToPrint = paddedColumns.map((col) => col[lineIndex]).join('');
383
+ console.log(lineToPrint);
384
+ }
349
385
  }
350
386
  console.log();
351
387
  }
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.9",
4
+ "version": "0.4.11",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/table/issues",
7
7
  "dependencies": {
@@ -17,7 +17,7 @@
17
17
  },
18
18
  "devDependencies": {
19
19
  "@commitlint/config-conventional": "^19",
20
- "@eslint/compat": "^1.3.0",
20
+ "@eslint/compat": "^1.3.1",
21
21
  "@oclif/core": "^4",
22
22
  "@oclif/prettier-config": "^0.2.1",
23
23
  "@oclif/test": "^4.1.13",
@@ -29,10 +29,10 @@
29
29
  "ansis": "^3.17.0",
30
30
  "chai": "^4.5.0",
31
31
  "commitlint": "^19",
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",
32
+ "eslint": "^9.32.0",
33
+ "eslint-config-oclif": "^6.0.87",
34
+ "eslint-config-prettier": "^10.1.8",
35
+ "eslint-config-xo": "^0.48.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",
@@ -40,7 +40,7 @@
40
40
  "ink-testing-library": "^4.0.0",
41
41
  "lint-staged": "^15",
42
42
  "mocha": "^10.8.2",
43
- "prettier": "^3.5.3",
43
+ "prettier": "^3.6.2",
44
44
  "shx": "^0.4.0",
45
45
  "sinon": "^18",
46
46
  "terminal-link": "^3.0.0",