mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-06 20:11:38 +08:00
This reverts commit 4df552c652.
Reason for revert: Breaks esprima.
Original change's description:
> Updates node_modules and update script
>
> Change-Id: I3fcf49bc416301a030d298cfc48c448bfeba4335
> Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/1878808
> Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
> Reviewed-by: Yang Guo <yangguo@chromium.org>
> Commit-Queue: Paul Lewis <aerotwist@chromium.org>
TBR=yangguo@chromium.org,aerotwist@chromium.org,tvanderlippe@chromium.org
Change-Id: Iad2bcdf98a486476715d1e829cdce450c5f218af
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/1880098
Reviewed-by: Lorne Mitchell <lomitch@microsoft.com>
Commit-Queue: Lorne Mitchell <lomitch@microsoft.com>
125 lines
2.9 KiB
Plaintext
125 lines
2.9 KiB
Plaintext
import _ from 'lodash';
|
|
import makeStreamConfig from './makeStreamConfig';
|
|
import drawRow from './drawRow';
|
|
import {
|
|
drawBorderBottom,
|
|
drawBorderJoin,
|
|
drawBorderTop
|
|
} from './drawBorder';
|
|
import stringifyTableData from './stringifyTableData';
|
|
import truncateTableData from './truncateTableData';
|
|
import mapDataUsingRowHeightIndex from './mapDataUsingRowHeightIndex';
|
|
import alignTableData from './alignTableData';
|
|
import padTableData from './padTableData';
|
|
import calculateRowHeightIndex from './calculateRowHeightIndex';
|
|
|
|
/**
|
|
* @param {Array} data
|
|
* @param {Object} config
|
|
* @returns {Array}
|
|
*/
|
|
const prepareData = (data, config) => {
|
|
let rows;
|
|
|
|
rows = stringifyTableData(data);
|
|
|
|
rows = truncateTableData(data, config);
|
|
|
|
const rowHeightIndex = calculateRowHeightIndex(rows, config);
|
|
|
|
rows = mapDataUsingRowHeightIndex(rows, rowHeightIndex, config);
|
|
rows = alignTableData(rows, config);
|
|
rows = padTableData(rows, config);
|
|
|
|
return rows;
|
|
};
|
|
|
|
/**
|
|
* @param {string[]} row
|
|
* @param {number[]} columnWidthIndex
|
|
* @param {Object} config
|
|
* @returns {undefined}
|
|
*/
|
|
const create = (row, columnWidthIndex, config) => {
|
|
const rows = prepareData([row], config);
|
|
|
|
const body = rows.map((literalRow) => {
|
|
return drawRow(literalRow, config.border);
|
|
}).join('');
|
|
|
|
let output;
|
|
|
|
output = '';
|
|
|
|
output += drawBorderTop(columnWidthIndex, config.border);
|
|
output += body;
|
|
output += drawBorderBottom(columnWidthIndex, config.border);
|
|
|
|
output = _.trimEnd(output);
|
|
|
|
process.stdout.write(output);
|
|
};
|
|
|
|
/**
|
|
* @param {string[]} row
|
|
* @param {number[]} columnWidthIndex
|
|
* @param {Object} config
|
|
* @returns {undefined}
|
|
*/
|
|
const append = (row, columnWidthIndex, config) => {
|
|
const rows = prepareData([row], config);
|
|
|
|
const body = rows.map((literalRow) => {
|
|
return drawRow(literalRow, config.border);
|
|
}).join('');
|
|
|
|
let output;
|
|
|
|
output = '\r\u001B[K';
|
|
|
|
output += drawBorderJoin(columnWidthIndex, config.border);
|
|
output += body;
|
|
output += drawBorderBottom(columnWidthIndex, config.border);
|
|
|
|
output = _.trimEnd(output);
|
|
|
|
process.stdout.write(output);
|
|
};
|
|
|
|
/**
|
|
* @param {Object} userConfig
|
|
* @returns {Object}
|
|
*/
|
|
export default (userConfig = {}) => {
|
|
const config = makeStreamConfig(userConfig);
|
|
|
|
// @todo Use 'Object.values' when Node.js v6 support is dropped.
|
|
const columnWidthIndex = _.values(_.mapValues(config.columns, (column) => {
|
|
return column.width + column.paddingLeft + column.paddingRight;
|
|
}));
|
|
|
|
let empty;
|
|
|
|
empty = true;
|
|
|
|
return {
|
|
/**
|
|
* @param {string[]} row
|
|
* @returns {undefined}
|
|
*/
|
|
write: (row) => {
|
|
if (row.length !== config.columnCount) {
|
|
throw new Error('Row cell count does not match the config.columnCount.');
|
|
}
|
|
|
|
if (empty) {
|
|
empty = false;
|
|
|
|
return create(row, columnWidthIndex, config);
|
|
} else {
|
|
return append(row, columnWidthIndex, config);
|
|
}
|
|
}
|
|
};
|
|
};
|