@oclif/table 0.4.10 → 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 +24 -5
  2. package/package.json +1 -1
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,10 +326,28 @@ 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
352
  // Process all columns and get their formatted text
334
353
  const columnTexts = columns.map((column) => {
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.10",
4
+ "version": "0.4.11",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/table/issues",
7
7
  "dependencies": {