diff --git a/lib/plugins/text/textBuilder.js b/lib/plugins/text/textBuilder.js index 591a02883e..75872184e0 100644 --- a/lib/plugins/text/textBuilder.js +++ b/lib/plugins/text/textBuilder.js @@ -1,4 +1,3 @@ -import table from 'text-table'; import clic from 'cli-color'; import { plural, short, cap } from '../../support/helpers/index.js'; @@ -10,6 +9,30 @@ const tableOptions = { }; const drab = blackBright; +function table(rows, options = {}) { + const { stringLength = str => str.length } = options; + + const colWidths = []; + for (const row of rows) { + for (const [i, cell] of row.entries()) { + const len = stringLength(String(cell)); + colWidths[i] = Math.max(colWidths[i] || 0, len); + } + } + + return rows + .map(row => + row + .map((cell, i) => { + const cellStr = String(cell); + const padding = colWidths[i] - stringLength(cellStr); + return cellStr + ' '.repeat(padding); + }) + .join(' ') + ) + .join('\n'); +} + function chunk(array, size) { const out = []; for (let i = 0; i < array.length; i += size) { @@ -46,7 +69,6 @@ function getBoxes(metrics, html) { return chunk(summaryBoxesSetup(metrics, html).filter(Boolean), 3).flat(); } -// foo bar -> fb function abbr(string_) { if (/total|overall/i.test(string_)) return string_.trim(); return string_.replaceAll(/\w+\s?/g, a => a[0]); @@ -61,7 +83,7 @@ export function renderSummary(metrics, context, options) { let rows = getBoxes(metrics, options.html).map(b => { const marker = getMarker(b.label), c = getColor(b.label); - // color.xterm(ansi)(label), + return [clic[c](marker), clic[c](b.name), bold(b.median)]; }); rows.unshift( diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index a3b5fc0552..34fbdde690 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -50,7 +50,6 @@ "recursive-readdir": "2.2.3", "simplecrawler": "1.1.9", "tape": "5.8.1", - "text-table": "0.2.0", "yargs": "17.7.2" }, "bin": { @@ -10858,7 +10857,8 @@ "node_modules/text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", - "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=" + "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", + "dev": true }, "node_modules/third-party-web": { "version": "0.26.2", diff --git a/package.json b/package.json index 8066f2af99..22a56192c7 100644 --- a/package.json +++ b/package.json @@ -121,7 +121,6 @@ "simplecrawler": "1.1.9", "@sitespeed.io/plugin": "0.0.6", "tape": "5.8.1", - "text-table": "0.2.0", "yargs": "17.7.2" }, "overrides": {