Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace text table #4373

Merged
merged 1 commit into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions lib/plugins/text/textBuilder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import table from 'text-table';
import clic from 'cli-color';

import { plural, short, cap } from '../../support/helpers/index.js';
Expand All @@ -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) {
Expand Down Expand Up @@ -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]);
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Loading